Skip to content

Commit b4d5e5a

Browse files
authored
Merge branch 'main' into fallback-output-mode
2 parents dad9f08 + cf7ce9f commit b4d5e5a

File tree

7 files changed

+1000
-174
lines changed

7 files changed

+1000
-174
lines changed

examples/pydantic_ai_examples/rag.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ async def build_search_db():
115115
async with httpx.AsyncClient() as client:
116116
response = await client.get(DOCS_JSON)
117117
response.raise_for_status()
118-
sections = sessions_ta.validate_json(response.content)
118+
sections = sections_ta.validate_json(response.content)
119119

120120
openai = AsyncOpenAI()
121121
logfire.instrument_openai(openai)
@@ -183,7 +183,7 @@ def embedding_content(self) -> str:
183183
return '\n\n'.join((f'path: {self.path}', f'title: {self.title}', self.content))
184184

185185

186-
sessions_ta = TypeAdapter(list[DocsSection])
186+
sections_ta = TypeAdapter(list[DocsSection])
187187

188188

189189
# pyright: reportUnknownMemberType=false

pydantic_ai_slim/pydantic_ai/common_tools/duckduckgo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
try:
1212
try:
13-
from ddgs import DDGS
13+
from ddgs.ddgs import DDGS
1414
except ImportError: # Fallback for older versions of ddgs
1515
from duckduckgo_search import DDGS
1616
except ImportError as _import_error:

pydantic_ai_slim/pydantic_ai/mcp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -726,9 +726,9 @@ async def client_streams(
726726
MemoryObjectReceiveStream[SessionMessage | Exception],
727727
MemoryObjectSendStream[SessionMessage],
728728
]
729-
]: # pragma: no cover
729+
]:
730730
if self.http_client and self.headers:
731-
raise ValueError('`http_client` is mutually exclusive with `headers`.')
731+
raise ValueError('`http_client` is mutually exclusive with `headers`.') # pragma: no cover
732732

733733
transport_client_partial = functools.partial(
734734
self._transport_client,
@@ -737,7 +737,7 @@ async def client_streams(
737737
sse_read_timeout=self.read_timeout,
738738
)
739739

740-
if self.http_client is not None:
740+
if self.http_client is not None: # pragma: no cover
741741

742742
def httpx_client_factory(
743743
headers: dict[str, str] | None = None,
@@ -866,7 +866,7 @@ def __get_pydantic_core_schema__(cls, _: Any, __: Any) -> CoreSchema:
866866

867867
@property
868868
def _transport_client(self):
869-
return streamablehttp_client # pragma: no cover
869+
return streamablehttp_client
870870

871871
def __eq__(self, value: object, /) -> bool:
872872
return super().__eq__(value) and isinstance(value, MCPServerStreamableHTTP) and self.url == value.url

pydantic_graph/pydantic_graph/beta/graph.py

Lines changed: 178 additions & 166 deletions
Large diffs are not rendered by default.

tests/cassettes/test_mcp/test_agent_run_stream_with_mcp_server_http.yaml

Lines changed: 801 additions & 0 deletions
Large diffs are not rendered by default.

tests/json_body_serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def serialize(cassette_dict: Any): # pragma: lax no cover
6868
if isinstance(body, dict):
6969
# Responses will have the body under a field called 'string'
7070
body = body.get('string')
71-
if body is not None:
71+
if body:
7272
# NOTE(Marcelo): This doesn't handle gzip compression.
7373
data['parsed_body'] = json.loads(body) # pyright: ignore[reportUnknownArgumentType]
7474
if 'access_token' in data['parsed_body']:

tests/test_mcp.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,3 +1489,16 @@ async def test_server_info(mcp_server: MCPServerStdio) -> None:
14891489
async with mcp_server:
14901490
assert mcp_server.server_info is not None
14911491
assert mcp_server.server_info.name == 'Pydantic AI MCP Server'
1492+
1493+
1494+
async def test_agent_run_stream_with_mcp_server_http(allow_model_requests: None, model: Model):
1495+
server = MCPServerStreamableHTTP(url='https://mcp.deepwiki.com/mcp', timeout=30)
1496+
agent = Agent(model, toolsets=[server], instructions='Be concise.')
1497+
1498+
# This should not raise an error.
1499+
# See https://github.com/pydantic/pydantic-ai/issues/2818#issuecomment-3476480829
1500+
async with agent.run_stream('Summarize the pydantic/pydantic-ai repo in one sentence') as result:
1501+
output = await result.get_output()
1502+
assert output == snapshot(
1503+
'The `pydantic/pydantic-ai` repository is a Python agent framework designed to facilitate the development of production-grade Generative AI applications and workflows with a focus on type-safety and an ergonomic developer experience.'
1504+
)

0 commit comments

Comments
 (0)