MCPcopy Index your code
hub / github.com/openai/openai-agents-python / test_handoff_on_input

Function test_handoff_on_input

tests/test_agent_runner.py:1710–1750  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1708
1709@pytest.mark.asyncio
1710async def test_handoff_on_input():
1711 call_output: str | None = None
1712
1713 def on_input(_ctx: RunContextWrapper[Any], data: Foo) -> None:
1714 nonlocal call_output
1715 call_output = data["bar"]
1716
1717 model = FakeModel()
1718 agent_1 = Agent(
1719 name="test",
1720 model=model,
1721 )
1722
1723 agent_2 = Agent(
1724 name="test",
1725 model=model,
1726 handoffs=[
1727 handoff(
1728 agent=agent_1,
1729 on_handoff=on_input,
1730 input_type=Foo,
1731 )
1732 ],
1733 )
1734
1735 model.add_multiple_turn_outputs(
1736 [
1737 [
1738 get_text_message("1"),
1739 get_text_message("2"),
1740 get_handoff_tool_call(agent_1, args=json.dumps(Foo(bar="test_input"))),
1741 ],
1742 [get_text_message("last")],
1743 ]
1744 )
1745
1746 result = await Runner.run(agent_2, input="user_message")
1747
1748 assert result.final_output == "last"
1749
1750 assert call_output == "test_input", "should have called the handoff with the correct input"
1751
1752
1753@pytest.mark.asyncio

Callers

nothing calls this directly

Calls 8

AgentClass · 0.90
handoffFunction · 0.90
FakeModelClass · 0.85
get_text_messageFunction · 0.85
get_handoff_tool_callFunction · 0.85
FooClass · 0.70
runMethod · 0.45

Tested by

no test coverage detected