-
Notifications
You must be signed in to change notification settings - Fork 1k
Python: Adds support for flowing kwargs to context and tool calls when using … #2945
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -141,7 +141,19 @@ async def run( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| checkpoint_storage: Runtime checkpoint storage. When provided with checkpoint_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| used to load and restore the checkpoint. When provided without checkpoint_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| enables checkpointing for this run. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| **kwargs: Additional keyword arguments. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| **kwargs: Additional keyword arguments to pass through to agent invocations. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| These are stored in SharedState and accessible in @ai_function tools | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| via the **kwargs parameter. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| With custom context for ai_functions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .. code-block:: python | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result = await workflow_agent.run( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "analyze data", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| custom_data={"endpoint": "https://api.example.com"}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| user_token={"user": "alice"}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| The final workflow response as an AgentRunResponse. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -153,7 +165,12 @@ async def run( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response_id = str(uuid.uuid4()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async for update in self._run_stream_impl( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| input_messages, response_id, thread, checkpoint_id, checkpoint_storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| input_messages, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| thread, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| checkpoint_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| checkpoint_storage, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run_kwargs=kwargs if kwargs else None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason we couldn't use idiomatic Python **kwargs forwarding?
Comment on lines
165
to
+173
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response_updates.append(update) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -187,7 +204,20 @@ async def run_stream( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| checkpoint_storage: Runtime checkpoint storage. When provided with checkpoint_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| used to load and restore the checkpoint. When provided without checkpoint_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| enables checkpointing for this run. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| **kwargs: Additional keyword arguments. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| **kwargs: Additional keyword arguments to pass through to agent invocations. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| These are stored in SharedState and accessible in @ai_function tools | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| via the **kwargs parameter. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| With custom context for ai_functions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .. code-block:: python | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async for event in workflow_agent.run_stream( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "analyze data", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| custom_data={"endpoint": "https://api.example.com"}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| user_token={"user": "alice"}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process(event) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Yields: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AgentRunResponseUpdate objects representing the workflow execution progress. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+211
to
223
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| With custom context for ai_functions: | |
| .. code-block:: python | |
| async for event in workflow_agent.run_stream( | |
| "analyze data", | |
| custom_data={"endpoint": "https://api.example.com"}, | |
| user_token={"user": "alice"}, | |
| ): | |
| process(event) | |
| Yields: | |
| AgentRunResponseUpdate objects representing the workflow execution progress. | |
| Yields: | |
| AgentRunResponseUpdate objects representing the workflow execution progress. | |
| Examples: | |
| With custom context for ai_functions: | |
| .. code-block:: python | |
| async for event in workflow_agent.run_stream( | |
| "analyze data", | |
| custom_data={"endpoint": "https://api.example.com"}, | |
| user_token={"user": "alice"}, | |
| ): | |
| process(event) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like this adds some unnecessary complexity - could we simply propagate **kwargs as-is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code example is incorrectly placed within the "Keyword Args:" section. Following the pattern established in Workflow.run_stream() (lines 480-520 in _workflow.py), examples should be in a separate "Examples:" section after the "Returns:" section. The example text "With custom context for ai_functions:" should be a subsection heading within an "Examples:" section, not nested under "Keyword Args:". Please restructure the docstring to match the Workflow.run_stream() documentation style.