Skip to content

Commit 16a0378

Browse files
committed
fix
1 parent d09bab1 commit 16a0378

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/agents/agent.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,16 @@ def as_tool(
418418
is_enabled=is_enabled,
419419
)
420420
async def run_agent(context: RunContextWrapper, input: str) -> str:
421-
from .run import Runner
421+
from .run import DEFAULT_MAX_TURNS, Runner
422+
423+
resolved_max_turns = max_turns if max_turns is not None else DEFAULT_MAX_TURNS
422424

423425
output = await Runner.run(
424426
starting_agent=self,
425427
input=input,
426428
context=context.context,
427429
run_config=run_config,
428-
max_turns=max_turns,
430+
max_turns=resolved_max_turns,
429431
hooks=hooks,
430432
previous_response_id=previous_response_id,
431433
conversation_id=conversation_id,

tests/test_agent_as_tool.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any
22

33
import pytest
4+
from openai.types.responses import ResponseOutputMessage, ResponseOutputText
45
from pydantic import BaseModel
56

67
from agents import (
@@ -13,9 +14,9 @@
1314
RunHooks,
1415
Runner,
1516
Session,
17+
TResponseInputItem,
1618
)
1719
from agents.tool_context import ToolContext
18-
from openai.types.responses import ResponseOutputMessage, ResponseOutputText
1920

2021

2122
class BoolCtx(BaseModel):
@@ -242,7 +243,11 @@ async def test_agent_as_tool_returns_concatenated_text(monkeypatch: pytest.Monke
242243
],
243244
)
244245

245-
result = type("DummyResult", (), {"new_items": [MessageOutputItem(agent=agent, raw_item=message)]})()
246+
result = type(
247+
"DummyResult",
248+
(),
249+
{"new_items": [MessageOutputItem(agent=agent, raw_item=message)]},
250+
)()
246251

247252
async def fake_run(
248253
cls,
@@ -269,6 +274,7 @@ async def fake_run(
269274
is_enabled=True,
270275
)
271276

277+
assert isinstance(tool, FunctionTool)
272278
tool_context = ToolContext(context=None, tool_name="story_tool", tool_call_id="call_1")
273279
output = await tool.on_invoke_tool(tool_context, '{"input": "hello"}')
274280

@@ -299,16 +305,16 @@ async def test_agent_as_tool_custom_output_extractor(monkeypatch: pytest.MonkeyP
299305
class DummySession(Session):
300306
session_id = "sess_123"
301307

302-
async def get_items(self, limit: int | None = None): # type: ignore[override]
308+
async def get_items(self, limit: int | None = None) -> list[TResponseInputItem]:
303309
return []
304310

305-
async def add_items(self, items): # type: ignore[override]
311+
async def add_items(self, items: list[TResponseInputItem]) -> None:
306312
return None
307313

308-
async def pop_item(self): # type: ignore[override]
314+
async def pop_item(self) -> TResponseInputItem | None:
309315
return None
310316

311-
async def clear_session(self): # type: ignore[override]
317+
async def clear_session(self) -> None:
312318
return None
313319

314320
dummy_session = DummySession()
@@ -365,6 +371,7 @@ async def extractor(result) -> str:
365371
session=dummy_session,
366372
)
367373

374+
assert isinstance(tool, FunctionTool)
368375
tool_context = ToolContext(context=None, tool_name="summary_tool", tool_call_id="call_2")
369376
output = await tool.on_invoke_tool(tool_context, '{"input": "summarize this"}')
370377

0 commit comments

Comments
 (0)