pydantic-ai-slim 1.0.15__tar.gz → 1.0.17__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pydantic-ai-slim might be problematic. Click here for more details.
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/PKG-INFO +4 -4
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/_agent_graph.py +13 -12
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/_cli.py +3 -3
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/agent/__init__.py +33 -9
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/agent/abstract.py +54 -26
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/agent/wrapper.py +13 -4
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/builtin_tools.py +4 -1
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/direct.py +9 -9
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/durable_exec/dbos/_agent.py +52 -20
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/durable_exec/temporal/_agent.py +45 -16
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/format_prompt.py +6 -4
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/messages.py +71 -43
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/models/anthropic.py +20 -19
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/models/openai.py +9 -1
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/result.py +5 -5
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/usage.py +35 -1
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pyproject.toml +1 -1
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/.gitignore +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/LICENSE +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/README.md +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/__init__.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/__main__.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/_a2a.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/_function_schema.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/_griffe.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/_instrumentation.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/_json_schema.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/_mcp.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/_otel_messages.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/_output.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/_parts_manager.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/_run_context.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/_system_prompt.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/_thinking_part.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/_tool_manager.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/_utils.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/ag_ui.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/common_tools/__init__.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/common_tools/duckduckgo.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/common_tools/tavily.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/durable_exec/__init__.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/durable_exec/dbos/__init__.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/durable_exec/dbos/_mcp_server.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/durable_exec/dbos/_model.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/durable_exec/dbos/_utils.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/durable_exec/temporal/__init__.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/durable_exec/temporal/_function_toolset.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/durable_exec/temporal/_logfire.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/durable_exec/temporal/_mcp_server.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/durable_exec/temporal/_model.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/durable_exec/temporal/_run_context.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/durable_exec/temporal/_toolset.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/exceptions.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/ext/__init__.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/ext/aci.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/ext/langchain.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/mcp.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/models/__init__.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/models/bedrock.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/models/cohere.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/models/fallback.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/models/function.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/models/gemini.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/models/google.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/models/groq.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/models/huggingface.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/models/instrumented.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/models/mcp_sampling.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/models/mistral.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/models/test.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/models/wrapper.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/output.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/profiles/__init__.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/profiles/amazon.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/profiles/anthropic.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/profiles/cohere.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/profiles/deepseek.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/profiles/google.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/profiles/grok.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/profiles/groq.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/profiles/harmony.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/profiles/meta.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/profiles/mistral.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/profiles/moonshotai.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/profiles/openai.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/profiles/qwen.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/__init__.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/anthropic.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/azure.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/bedrock.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/cerebras.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/cohere.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/deepseek.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/fireworks.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/gateway.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/github.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/google.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/google_gla.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/google_vertex.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/grok.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/groq.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/heroku.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/huggingface.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/litellm.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/mistral.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/moonshotai.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/ollama.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/openai.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/openrouter.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/together.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/providers/vercel.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/py.typed +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/retries.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/run.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/settings.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/tools.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/toolsets/__init__.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/toolsets/_dynamic.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/toolsets/abstract.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/toolsets/approval_required.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/toolsets/combined.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/toolsets/external.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/toolsets/filtered.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/toolsets/function.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/toolsets/prefixed.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/toolsets/prepared.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/toolsets/renamed.py +0 -0
- {pydantic_ai_slim-1.0.15 → pydantic_ai_slim-1.0.17}/pydantic_ai/toolsets/wrapper.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pydantic-ai-slim
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.17
|
|
4
4
|
Summary: Agent Framework / shim to use Pydantic with LLMs, slim package
|
|
5
5
|
Project-URL: Homepage, https://github.com/pydantic/pydantic-ai/tree/main/pydantic_ai_slim
|
|
6
6
|
Project-URL: Source, https://github.com/pydantic/pydantic-ai/tree/main/pydantic_ai_slim
|
|
@@ -29,11 +29,11 @@ Classifier: Topic :: Internet
|
|
|
29
29
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
30
30
|
Requires-Python: >=3.10
|
|
31
31
|
Requires-Dist: exceptiongroup; python_version < '3.11'
|
|
32
|
-
Requires-Dist: genai-prices>=0.0.
|
|
32
|
+
Requires-Dist: genai-prices>=0.0.30
|
|
33
33
|
Requires-Dist: griffe>=1.3.2
|
|
34
34
|
Requires-Dist: httpx>=0.27
|
|
35
35
|
Requires-Dist: opentelemetry-api>=1.28.0
|
|
36
|
-
Requires-Dist: pydantic-graph==1.0.
|
|
36
|
+
Requires-Dist: pydantic-graph==1.0.17
|
|
37
37
|
Requires-Dist: pydantic>=2.10
|
|
38
38
|
Requires-Dist: typing-inspection>=0.4.0
|
|
39
39
|
Provides-Extra: a2a
|
|
@@ -57,7 +57,7 @@ Requires-Dist: dbos>=1.14.0; extra == 'dbos'
|
|
|
57
57
|
Provides-Extra: duckduckgo
|
|
58
58
|
Requires-Dist: ddgs>=9.0.0; extra == 'duckduckgo'
|
|
59
59
|
Provides-Extra: evals
|
|
60
|
-
Requires-Dist: pydantic-evals==1.0.
|
|
60
|
+
Requires-Dist: pydantic-evals==1.0.17; extra == 'evals'
|
|
61
61
|
Provides-Extra: google
|
|
62
62
|
Requires-Dist: google-genai>=1.31.0; extra == 'google'
|
|
63
63
|
Provides-Extra: groq
|
|
@@ -795,16 +795,14 @@ async def process_tool_calls( # noqa: C901
|
|
|
795
795
|
# Then, we handle function tool calls
|
|
796
796
|
calls_to_run: list[_messages.ToolCallPart] = []
|
|
797
797
|
if final_result and ctx.deps.end_strategy == 'early':
|
|
798
|
-
|
|
799
|
-
|
|
798
|
+
for call in tool_calls_by_kind['function']:
|
|
799
|
+
output_parts.append(
|
|
800
800
|
_messages.ToolReturnPart(
|
|
801
801
|
tool_name=call.tool_name,
|
|
802
802
|
content='Tool not executed - a final result was already processed.',
|
|
803
803
|
tool_call_id=call.tool_call_id,
|
|
804
804
|
)
|
|
805
|
-
|
|
806
|
-
]
|
|
807
|
-
)
|
|
805
|
+
)
|
|
808
806
|
else:
|
|
809
807
|
calls_to_run.extend(tool_calls_by_kind['function'])
|
|
810
808
|
|
|
@@ -850,14 +848,17 @@ async def process_tool_calls( # noqa: C901
|
|
|
850
848
|
if tool_call_results is None:
|
|
851
849
|
calls = [*tool_calls_by_kind['external'], *tool_calls_by_kind['unapproved']]
|
|
852
850
|
if final_result:
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
851
|
+
# If the run was already determined to end on deferred tool calls,
|
|
852
|
+
# we shouldn't insert return parts as the deferred tools will still get a real result.
|
|
853
|
+
if not isinstance(final_result.output, _output.DeferredToolRequests):
|
|
854
|
+
for call in calls:
|
|
855
|
+
output_parts.append(
|
|
856
|
+
_messages.ToolReturnPart(
|
|
857
|
+
tool_name=call.tool_name,
|
|
858
|
+
content='Tool not executed - a final result was already processed.',
|
|
859
|
+
tool_call_id=call.tool_call_id,
|
|
860
|
+
)
|
|
859
861
|
)
|
|
860
|
-
)
|
|
861
862
|
elif calls:
|
|
862
863
|
deferred_calls['external'].extend(tool_calls_by_kind['external'])
|
|
863
864
|
deferred_calls['unapproved'].extend(tool_calls_by_kind['unapproved'])
|
|
@@ -228,7 +228,7 @@ async def run_chat(
|
|
|
228
228
|
prog_name: str,
|
|
229
229
|
config_dir: Path | None = None,
|
|
230
230
|
deps: AgentDepsT = None,
|
|
231
|
-
message_history:
|
|
231
|
+
message_history: Sequence[ModelMessage] | None = None,
|
|
232
232
|
) -> int:
|
|
233
233
|
prompt_history_path = (config_dir or PYDANTIC_AI_HOME) / PROMPT_HISTORY_FILENAME
|
|
234
234
|
prompt_history_path.parent.mkdir(parents=True, exist_ok=True)
|
|
@@ -236,7 +236,7 @@ async def run_chat(
|
|
|
236
236
|
session: PromptSession[Any] = PromptSession(history=FileHistory(str(prompt_history_path)))
|
|
237
237
|
|
|
238
238
|
multiline = False
|
|
239
|
-
messages: list[ModelMessage] = message_history
|
|
239
|
+
messages: list[ModelMessage] = list(message_history) if message_history else []
|
|
240
240
|
|
|
241
241
|
while True:
|
|
242
242
|
try:
|
|
@@ -272,7 +272,7 @@ async def ask_agent(
|
|
|
272
272
|
console: Console,
|
|
273
273
|
code_theme: str,
|
|
274
274
|
deps: AgentDepsT = None,
|
|
275
|
-
messages:
|
|
275
|
+
messages: Sequence[ModelMessage] | None = None,
|
|
276
276
|
) -> list[ModelMessage]:
|
|
277
277
|
status = Status('[dim]Working on it…[/dim]', console=console)
|
|
278
278
|
|
|
@@ -344,6 +344,7 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
344
344
|
|
|
345
345
|
self._event_stream_handler = event_stream_handler
|
|
346
346
|
|
|
347
|
+
self._override_name: ContextVar[_utils.Option[str]] = ContextVar('_override_name', default=None)
|
|
347
348
|
self._override_deps: ContextVar[_utils.Option[AgentDepsT]] = ContextVar('_override_deps', default=None)
|
|
348
349
|
self._override_model: ContextVar[_utils.Option[models.Model]] = ContextVar('_override_model', default=None)
|
|
349
350
|
self._override_toolsets: ContextVar[_utils.Option[Sequence[AbstractToolset[AgentDepsT]]]] = ContextVar(
|
|
@@ -384,7 +385,8 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
384
385
|
|
|
385
386
|
If `None`, we try to infer the agent name from the call frame when the agent is first run.
|
|
386
387
|
"""
|
|
387
|
-
|
|
388
|
+
name_ = self._override_name.get()
|
|
389
|
+
return name_.value if name_ else self._name
|
|
388
390
|
|
|
389
391
|
@name.setter
|
|
390
392
|
def name(self, value: str | None) -> None:
|
|
@@ -415,7 +417,7 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
415
417
|
user_prompt: str | Sequence[_messages.UserContent] | None = None,
|
|
416
418
|
*,
|
|
417
419
|
output_type: None = None,
|
|
418
|
-
message_history:
|
|
420
|
+
message_history: Sequence[_messages.ModelMessage] | None = None,
|
|
419
421
|
deferred_tool_results: DeferredToolResults | None = None,
|
|
420
422
|
model: models.Model | models.KnownModelName | str | None = None,
|
|
421
423
|
deps: AgentDepsT = None,
|
|
@@ -424,6 +426,7 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
424
426
|
usage: _usage.RunUsage | None = None,
|
|
425
427
|
infer_name: bool = True,
|
|
426
428
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
429
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
427
430
|
) -> AbstractAsyncContextManager[AgentRun[AgentDepsT, OutputDataT]]: ...
|
|
428
431
|
|
|
429
432
|
@overload
|
|
@@ -432,7 +435,7 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
432
435
|
user_prompt: str | Sequence[_messages.UserContent] | None = None,
|
|
433
436
|
*,
|
|
434
437
|
output_type: OutputSpec[RunOutputDataT],
|
|
435
|
-
message_history:
|
|
438
|
+
message_history: Sequence[_messages.ModelMessage] | None = None,
|
|
436
439
|
deferred_tool_results: DeferredToolResults | None = None,
|
|
437
440
|
model: models.Model | models.KnownModelName | str | None = None,
|
|
438
441
|
deps: AgentDepsT = None,
|
|
@@ -441,6 +444,7 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
441
444
|
usage: _usage.RunUsage | None = None,
|
|
442
445
|
infer_name: bool = True,
|
|
443
446
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
447
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
444
448
|
) -> AbstractAsyncContextManager[AgentRun[AgentDepsT, RunOutputDataT]]: ...
|
|
445
449
|
|
|
446
450
|
@asynccontextmanager
|
|
@@ -449,7 +453,7 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
449
453
|
user_prompt: str | Sequence[_messages.UserContent] | None = None,
|
|
450
454
|
*,
|
|
451
455
|
output_type: OutputSpec[RunOutputDataT] | None = None,
|
|
452
|
-
message_history:
|
|
456
|
+
message_history: Sequence[_messages.ModelMessage] | None = None,
|
|
453
457
|
deferred_tool_results: DeferredToolResults | None = None,
|
|
454
458
|
model: models.Model | models.KnownModelName | str | None = None,
|
|
455
459
|
deps: AgentDepsT = None,
|
|
@@ -458,6 +462,7 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
458
462
|
usage: _usage.RunUsage | None = None,
|
|
459
463
|
infer_name: bool = True,
|
|
460
464
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | None = None,
|
|
465
|
+
builtin_tools: Sequence[AbstractBuiltinTool] | None = None,
|
|
461
466
|
) -> AsyncIterator[AgentRun[AgentDepsT, Any]]:
|
|
462
467
|
"""A contextmanager which can be used to iterate over the agent graph's nodes as they are executed.
|
|
463
468
|
|
|
@@ -530,6 +535,7 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
530
535
|
usage: Optional usage to start with, useful for resuming a conversation or agents used in tools.
|
|
531
536
|
infer_name: Whether to try to infer the agent name from the call frame if it's not set.
|
|
532
537
|
toolsets: Optional additional toolsets for this run.
|
|
538
|
+
builtin_tools: Optional additional builtin tools for this run.
|
|
533
539
|
|
|
534
540
|
Returns:
|
|
535
541
|
The result of the run.
|
|
@@ -566,7 +572,7 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
566
572
|
# Build the initial state
|
|
567
573
|
usage = usage or _usage.RunUsage()
|
|
568
574
|
state = _agent_graph.GraphAgentState(
|
|
569
|
-
message_history=message_history
|
|
575
|
+
message_history=list(message_history) if message_history else [],
|
|
570
576
|
usage=usage,
|
|
571
577
|
retries=0,
|
|
572
578
|
run_step=0,
|
|
@@ -601,7 +607,16 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
601
607
|
else:
|
|
602
608
|
instrumentation_settings = None
|
|
603
609
|
tracer = NoOpTracer()
|
|
604
|
-
|
|
610
|
+
if builtin_tools:
|
|
611
|
+
# Deduplicate builtin tools passed to the agent and the run based on type
|
|
612
|
+
builtin_tools = list(
|
|
613
|
+
{
|
|
614
|
+
**({type(tool): tool for tool in self._builtin_tools or []}),
|
|
615
|
+
**({type(tool): tool for tool in builtin_tools}),
|
|
616
|
+
}.values()
|
|
617
|
+
)
|
|
618
|
+
else:
|
|
619
|
+
builtin_tools = list(self._builtin_tools)
|
|
605
620
|
graph_deps = _agent_graph.GraphAgentDeps[AgentDepsT, RunOutputDataT](
|
|
606
621
|
user_deps=deps,
|
|
607
622
|
prompt=user_prompt,
|
|
@@ -614,7 +629,7 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
614
629
|
output_schema=output_schema,
|
|
615
630
|
output_validators=output_validators,
|
|
616
631
|
history_processors=self.history_processors,
|
|
617
|
-
builtin_tools=
|
|
632
|
+
builtin_tools=builtin_tools,
|
|
618
633
|
tool_manager=tool_manager,
|
|
619
634
|
tracer=tracer,
|
|
620
635
|
get_instructions=get_instructions,
|
|
@@ -690,7 +705,7 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
690
705
|
}
|
|
691
706
|
else:
|
|
692
707
|
attrs = {
|
|
693
|
-
'pydantic_ai.all_messages': json.dumps(settings.messages_to_otel_messages(state.message_history)),
|
|
708
|
+
'pydantic_ai.all_messages': json.dumps(settings.messages_to_otel_messages(list(state.message_history))),
|
|
694
709
|
**settings.system_instructions_attributes(literal_instructions),
|
|
695
710
|
}
|
|
696
711
|
|
|
@@ -712,24 +727,31 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
712
727
|
def override(
|
|
713
728
|
self,
|
|
714
729
|
*,
|
|
730
|
+
name: str | _utils.Unset = _utils.UNSET,
|
|
715
731
|
deps: AgentDepsT | _utils.Unset = _utils.UNSET,
|
|
716
732
|
model: models.Model | models.KnownModelName | str | _utils.Unset = _utils.UNSET,
|
|
717
733
|
toolsets: Sequence[AbstractToolset[AgentDepsT]] | _utils.Unset = _utils.UNSET,
|
|
718
734
|
tools: Sequence[Tool[AgentDepsT] | ToolFuncEither[AgentDepsT, ...]] | _utils.Unset = _utils.UNSET,
|
|
719
735
|
instructions: Instructions[AgentDepsT] | _utils.Unset = _utils.UNSET,
|
|
720
736
|
) -> Iterator[None]:
|
|
721
|
-
"""Context manager to temporarily override agent dependencies, model, toolsets, tools, or instructions.
|
|
737
|
+
"""Context manager to temporarily override agent name, dependencies, model, toolsets, tools, or instructions.
|
|
722
738
|
|
|
723
739
|
This is particularly useful when testing.
|
|
724
740
|
You can find an example of this [here](../testing.md#overriding-model-via-pytest-fixtures).
|
|
725
741
|
|
|
726
742
|
Args:
|
|
743
|
+
name: The name to use instead of the name passed to the agent constructor and agent run.
|
|
727
744
|
deps: The dependencies to use instead of the dependencies passed to the agent run.
|
|
728
745
|
model: The model to use instead of the model passed to the agent run.
|
|
729
746
|
toolsets: The toolsets to use instead of the toolsets passed to the agent constructor and agent run.
|
|
730
747
|
tools: The tools to use instead of the tools registered with the agent.
|
|
731
748
|
instructions: The instructions to use instead of the instructions registered with the agent.
|
|
732
749
|
"""
|
|
750
|
+
if _utils.is_set(name):
|
|
751
|
+
name_token = self._override_name.set(_utils.Some(name))
|
|
752
|
+
else:
|
|
753
|
+
name_token = None
|
|
754
|
+
|
|
733
755
|
if _utils.is_set(deps):
|
|
734
756
|
deps_token = self._override_deps.set(_utils.Some(deps))
|
|
735
757
|
else:
|
|
@@ -759,6 +781,8 @@ class Agent(AbstractAgent[AgentDepsT, OutputDataT]):
|
|
|
759
781
|
try:
|
|
760
782
|
yield
|
|
761
783
|
finally:
|
|
784
|
+
if name_token is not None:
|
|
785
|
+
self._override_name.reset(name_token)
|
|
762
786
|
if deps_token is not None:
|
|
763
787
|
self._override_deps.reset(deps_token)
|
|
764
788
|
if model_token is not None:
|