Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pydantic_ai_slim/pydantic_ai/agent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import anyio
from opentelemetry.trace import NoOpTracer, use_span
from pydantic.json_schema import GenerateJsonSchema
from typing_extensions import TypeVar, deprecated
from typing_extensions import Self, TypeVar, deprecated

from pydantic_graph import Graph

Expand Down Expand Up @@ -1355,7 +1355,7 @@ def _prepare_output_schema(

return schema # pyright: ignore[reportReturnType]

async def __aenter__(self) -> AbstractAgent[AgentDepsT, OutputDataT]:
async def __aenter__(self) -> Self:
"""Enter the agent context.

This will start all [`MCPServerStdio`s][pydantic_ai.mcp.MCPServerStdio] registered as `toolsets` so they are ready to be used.
Expand Down
7 changes: 2 additions & 5 deletions pydantic_ai_slim/pydantic_ai/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from pydantic_ai.tools import RunContext, ToolDefinition

from .direct import model_request
from .toolsets.abstract import AbstractToolset, ToolsetTool

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

model_response = await self.sampling_model.request(
pai_messages,
model_settings,
models.ModelRequestParameters(),
)
model_response = await model_request(self.sampling_model, pai_messages, model_settings=model_settings)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way logfire.instrument_pydantic_ai() will instrument the sampling model.

return mcp_types.CreateMessageResult(
role='assistant',
content=_mcp.map_from_model_response(model_response),
Expand Down