Skip to content

Commit fe07149

Browse files
committed
Document Agent.__aenter__
1 parent f7db040 commit fe07149

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

pydantic_ai_slim/pydantic_ai/agent.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,7 @@ def is_end_node(
17881788
return isinstance(node, End)
17891789

17901790
async def __aenter__(self) -> Self:
1791+
"""Enter the agent. This will start all [`MCPServerStdio`s][pydantic_ai.mcp.MCPServerStdio] registered with the agent so they can be used in a run."""
17911792
if self._running_count == 0:
17921793
self._exit_stack = AsyncExitStack()
17931794
await self._exit_stack.enter_async_context(self._toolset)
@@ -1828,6 +1829,9 @@ async def run_mcp_servers(
18281829
) -> AsyncIterator[None]:
18291830
"""Run [`MCPServerStdio`s][pydantic_ai.mcp.MCPServerStdio] so they can be used by the agent.
18301831
1832+
Deprecated: use [`async with agent`][pydantic_ai.agent.Agent.__aenter__] instead.
1833+
If you need to set a sampling model on all MCP servers, use [`agent.set_mcp_sampling_model(...)`][pydantic_ai.agent.Agent.set_mcp_sampling_model].
1834+
18311835
Returns: a context manager to start and shutdown the servers.
18321836
"""
18331837
try:

0 commit comments

Comments
 (0)