Skip to content

Commit ca079f5

Browse files
alexmojakiDouweM
andauthored
Minor fixes: Agent.__aenter__ returns Self, use default instrumentation for MCP sampling model (#2765)
Co-authored-by: Douwe Maan <[email protected]>
1 parent 01b6e51 commit ca079f5

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

pydantic_ai_slim/pydantic_ai/agent/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import anyio
1313
from opentelemetry.trace import NoOpTracer, use_span
1414
from pydantic.json_schema import GenerateJsonSchema
15-
from typing_extensions import TypeVar, deprecated
15+
from typing_extensions import Self, TypeVar, deprecated
1616

1717
from pydantic_graph import Graph
1818

@@ -1355,7 +1355,7 @@ def _prepare_output_schema(
13551355

13561356
return schema # pyright: ignore[reportReturnType]
13571357

1358-
async def __aenter__(self) -> AbstractAgent[AgentDepsT, OutputDataT]:
1358+
async def __aenter__(self) -> Self:
13591359
"""Enter the agent context.
13601360
13611361
This will start all [`MCPServerStdio`s][pydantic_ai.mcp.MCPServerStdio] registered as `toolsets` so they are ready to be used.

pydantic_ai_slim/pydantic_ai/mcp.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from pydantic_ai.tools import RunContext, ToolDefinition
2222

23+
from .direct import model_request
2324
from .toolsets.abstract import AbstractToolset, ToolsetTool
2425

2526
try:
@@ -329,11 +330,7 @@ async def _sampling_callback(
329330
if stop_sequences := params.stopSequences: # pragma: no branch
330331
model_settings['stop_sequences'] = stop_sequences
331332

332-
model_response = await self.sampling_model.request(
333-
pai_messages,
334-
model_settings,
335-
models.ModelRequestParameters(),
336-
)
333+
model_response = await model_request(self.sampling_model, pai_messages, model_settings=model_settings)
337334
return mcp_types.CreateMessageResult(
338335
role='assistant',
339336
content=_mcp.map_from_model_response(model_response),

0 commit comments

Comments
 (0)