Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tasks): accept args in BaseTask.run() #1598

Merged
merged 1 commit into from
Feb 18, 2025
Merged

Conversation

collindutter
Copy link
Member

@collindutter collindutter commented Jan 21, 2025

Describe your changes

BaseTask.run() now accepts args just like Structure.run(). Decided against adding kwargs support in this PR since there is a future opportunity for special kwargs like context=. Having a blackhole kwargs that is dumped into context makes it challenging to add kwargs that shouldn't go in context.

Issue ticket number and link

Closes #1597


📚 Documentation preview 📚: https://griptape--1598.org.readthedocs.build//1598/

Copy link

codecov bot commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@collindutter collindutter modified the milestone: 1.3 Jan 22, 2025
@vachillo
Copy link
Member

@collindutter what else needs to be done here?

@collindutter collindutter added this to the 1.4 milestone Feb 13, 2025
@collindutter collindutter self-assigned this Feb 13, 2025
@collindutter
Copy link
Member Author

I had some last minute ideas I wanted to try out. Will implement soon to see how they feel.

@collindutter collindutter force-pushed the feature/task-args branch 2 times, most recently from cdf5272 to 1a5ef91 Compare February 17, 2025 19:26
@collindutter collindutter changed the title Support Structure kwargs, Task args/kwargs feat(tasks): accept args in BaseTask.run() Feb 17, 2025
@collindutter
Copy link
Member Author

@vachillo I updated/simplified the PR if you'd like to take one more look.

@vachillo
Copy link
Member

vachillo commented Feb 18, 2025

@vachillo I updated/simplified the PR if you'd like to take one more look.

no kwargs now? any reason for that? description was updated

@collindutter
Copy link
Member Author

@vachillo how does updated version look?

Copy link
Member

@vachillo vachillo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i find it kind of confusing that there is two entrypoints into the prompt via args and context. what would be the advantage of either way?

@@ -197,7 +196,8 @@ def after_run(self) -> None:
def add_task(self, task: BaseTask) -> BaseTask: ...

@observable
def run(self, *args) -> Structure:
def run(self, *args, **kwargs) -> Structure:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets remove **kwargs here

@@ -154,7 +154,6 @@ def resolve_relationships(self) -> None:
@observable
def before_run(self, args: Any) -> None:
super().before_run(args)
self._execution_args = args
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does the move to .run for this line going to affect behavior?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted it

Comment on lines +46 to +50
_execution_args: tuple = field(factory=tuple, init=False)

@property
def execution_args(self) -> tuple:
return self._execution_args
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these be serializable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, they are not intended to be static, serializable data.

@collindutter
Copy link
Member Author

i find it kind of confusing that there is two entrypoints into the prompt via args and context. what would be the advantage of either way?

BaseTask.input is for defining the input to the LLM. In the case of PromptTask.input, it's a place for defining a text template.
BaseTask.context is for static data that needs to be made available that template.
BaseTask.run() args is for runtime data that needs to be made available to that template.

For example:

task = PromptTask(
    input="You are talking to {{ user_name }} ({{ user_id }}).They just said: {{ args[0] }}",
    context={
        "user_name": "John Doe",
        "user_id": "123",
    },
)


task.run("Hello, how are you?")
task.run("How do I foo the bar?")

@vachillo
Copy link
Member

i find it kind of confusing that there is two entrypoints into the prompt via args and context. what would be the advantage of either way?

BaseTask.input is for defining the input to the LLM. In the case of PromptTask.input, it's a place for defining a text template. BaseTask.context is for static data that needs to be made available that template. BaseTask.run() args is for runtime data that needs to be made available to that template.

For example:

task = PromptTask(
    input="You are talking to {{ user_name }} ({{ user_id }}).They just said: {{ args[0] }}",
    context={
        "user_name": "John Doe",
        "user_id": "123",
    },
)


task.run("Hello, how are you?")
task.run("How do I foo the bar?")

i see. i think we just have very different ways of thinking about how this stuff gets run. to me, its unrealistic that you would invoke task.run twice like that. every instanstiation of objects is in completely seperate processes, and gets spun up with all the data that is needed dynamically. so i dont see context as any less "dyanmic" than args, just a different entrypoint. like an event driven case where you are spinning everything up every time. its just optimizing for very different scenarios.

@collindutter
Copy link
Member Author

to me, its unrealistic that you would invoke task.run twice like that. every instanstiation of objects is in completely seperate processes

It would be preferable if you didn't need to create a new Task every time though, as there is some overhead associated with creating it. With the upcoming async work I think that model becomes more feasible since you can run the async work on the main thread vs creating a new one.

@collindutter collindutter added this pull request to the merge queue Feb 18, 2025
Merged via the queue into main with commit 89c32d4 Feb 18, 2025
16 checks passed
@collindutter collindutter deleted the feature/task-args branch February 18, 2025 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Structure/Task Run Args/Kwargs
3 participants