Skip to content

Commit d99be83

Browse files
authored
Merge branch 'main' into patch-3323
2 parents fd806f7 + cf7ce9f commit d99be83

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
@@ -789,9 +789,9 @@ async def client_streams(
789789
MemoryObjectReceiveStream[SessionMessage | Exception],
790790
MemoryObjectSendStream[SessionMessage],
791791
]
792-
]: # pragma: no cover
792+
]:
793793
if self.http_client and self.headers:
794-
raise ValueError('`http_client` is mutually exclusive with `headers`.')
794+
raise ValueError('`http_client` is mutually exclusive with `headers`.') # pragma: no cover
795795

796796
transport_client_partial = functools.partial(
797797
self._transport_client,
@@ -800,7 +800,7 @@ async def client_streams(
800800
sse_read_timeout=self.read_timeout,
801801
)
802802

803-
if self.http_client is not None:
803+
if self.http_client is not None: # pragma: no cover
804804

805805
def httpx_client_factory(
806806
headers: dict[str, str] | None = None,
@@ -929,7 +929,7 @@ def __get_pydantic_core_schema__(cls, _: Any, __: Any) -> CoreSchema:
929929

930930
@property
931931
def _transport_client(self):
932-
return streamablehttp_client # pragma: no cover
932+
return streamablehttp_client
933933

934934
def __eq__(self, value: object, /) -> bool:
935935
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
@@ -1520,3 +1520,16 @@ async def test_server_info(mcp_server: MCPServerStdio) -> None:
15201520
async with mcp_server:
15211521
assert mcp_server.server_info is not None
15221522
assert mcp_server.server_info.name == 'Pydantic AI MCP Server'
1523+
1524+
1525+
async def test_agent_run_stream_with_mcp_server_http(allow_model_requests: None, model: Model):
1526+
server = MCPServerStreamableHTTP(url='https://mcp.deepwiki.com/mcp', timeout=30)
1527+
agent = Agent(model, toolsets=[server], instructions='Be concise.')
1528+
1529+
# This should not raise an error.
1530+
# See https://github.com/pydantic/pydantic-ai/issues/2818#issuecomment-3476480829
1531+
async with agent.run_stream('Summarize the pydantic/pydantic-ai repo in one sentence') as result:
1532+
output = await result.get_output()
1533+
assert output == snapshot(
1534+
'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.'
1535+
)

0 commit comments

Comments
 (0)