-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add DynamicToolset support in Temporal
#3682
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
base: main
Are you sure you want to change the base?
Add DynamicToolset support in Temporal
#3682
Conversation
pydantic_ai_slim/pydantic_ai/durable_exec/temporal/_dynamic_toolset.py
Outdated
Show resolved
Hide resolved
tests/test_temporal.py
Outdated
| assert output == 'Dynamic result received' | ||
|
|
||
|
|
||
| # Test with explicit id parameter |
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.
I'd rather test the new id arg where we test the @agent.toolset decorator, since this part is not Temporal-specific
tests/test_temporal.py
Outdated
| pytest.fail('TemporalDynamicToolset not found in toolsets') | ||
|
|
||
|
|
||
| async def test_dynamic_toolset_get_tools_outside_workflow(): |
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.
We should test this by running the same agent we created earlier outside of a workflow, and checking that we still get the correct result
tests/test_temporal.py
Outdated
| pytest.fail('TemporalDynamicToolset not found') | ||
|
|
||
|
|
||
| async def test_dynamic_toolset_call_tool_outside_workflow(): |
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.
Not needed
tests/test_temporal.py
Outdated
| pytest.fail('TemporalDynamicToolset not found') | ||
|
|
||
|
|
||
| async def test_dynamic_toolset_tool_not_found_in_activity(): |
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.
I'm fine with pragma: no cover for this UserError like we have here:
pydantic-ai/pydantic_ai_slim/pydantic_ai/durable_exec/temporal/_function_toolset.py
Lines 41 to 47 in f42e523
| try: | |
| tool = (await toolset.get_tools(ctx))[name] | |
| except KeyError as e: # pragma: no cover | |
| raise UserError( | |
| f'Tool {name!r} not found in toolset {self.id!r}. ' | |
| 'Removing or renaming tools during an agent run is not supported with Temporal.' | |
| ) from e |
Core changes: - DynamicToolset: convert to plain class with custom __init__, add copy() - TemporalDynamicToolset: use _call_tool_in_activity shared method - TemporalFunctionToolset: use _call_tool_in_activity shared method - temporalize_toolset: move DynamicToolset import to top Test changes: - Add test_fastmcp_dynamic_toolset_in_workflow for MCP lifecycle in DynamicToolset - Add test_dynamic_toolset_id and test_agent_toolset_decorator_id - Update test_visit_and_replace for DynamicToolset plain class 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Closes #3390
@agent.toolsetdecorator