Skip to content

Commit 1d0b46f

Browse files
committed
add infer_name
1 parent 9896901 commit 1d0b46f

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

pydantic_ai_slim/pydantic_ai/agent/abstract.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,9 @@ def main():
684684
Returns:
685685
The result of the run.
686686
"""
687+
if infer_name and self.name is None:
688+
if frame := inspect.currentframe(): # pragma: no branch
689+
self._infer_name(frame)
687690

688691
async def _consume_stream():
689692
async with self.run_stream(

tests/test_streaming.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,7 @@ async def ret_a(x: str) -> str:
135135
)
136136

137137

138-
@pytest.fixture
139-
def close_cached_httpx_client():
140-
"""Override the global fixture to avoid async context issues in sync tests."""
141-
yield
142-
143-
144-
def test_streamed_text_sync_response(close_cached_httpx_client): # type: ignore[reportUnknownParameterType]
138+
def test_streamed_text_sync_response():
145139
m = TestModel()
146140

147141
test_agent = Agent(m)
@@ -152,7 +146,7 @@ async def ret_a(x: str) -> str:
152146
return f'{x}-apple'
153147

154148
result = test_agent.run_stream_sync('Hello')
155-
# assert test_agent.name == 'test_agent'
149+
assert test_agent.name == 'test_agent'
156150
assert not result.is_complete
157151
assert result.all_messages() == snapshot(
158152
[

0 commit comments

Comments
 (0)