MCPcopy
hub / github.com/openai/openai-agents-python / test_run_demo_loop_streaming

Function test_run_demo_loop_streaming

tests/test_repl.py:38–67  ·  view source on GitHub ↗
(monkeypatch, capsys)

Source from the content-addressed store, hash-verified

36
37@pytest.mark.asyncio
38async def test_run_demo_loop_streaming(monkeypatch, capsys):
39 model = FakeModel()
40 target_agent = Agent(name="target", model=model)
41 agent = Agent(
42 name="test",
43 model=model,
44 tools=[get_function_tool("foo", "tool_result")],
45 handoffs=[target_agent],
46 )
47
48 # A single user turn that exercises every streamed event branch:
49 # a tool call, the tool output, a handoff (agent update), then a text answer.
50 model.add_multiple_turn_outputs(
51 [
52 [get_function_tool_call("foo", "{}")],
53 [get_handoff_tool_call(target_agent)],
54 [get_text_message("all done")],
55 ]
56 )
57
58 inputs = iter(["Hello", "exit"])
59 monkeypatch.setattr("builtins.input", lambda _=" > ": next(inputs))
60
61 await run_demo_loop(agent, stream=True)
62
63 output = capsys.readouterr().out
64 assert "all done" in output
65 assert "[tool called]" in output
66 assert "[tool output: tool_result]" in output
67 assert "[Agent updated: target]" in output
68
69
70@pytest.mark.asyncio

Callers

nothing calls this directly

Calls 8

AgentClass · 0.90
run_demo_loopFunction · 0.90
FakeModelClass · 0.85
get_function_toolFunction · 0.85
get_function_tool_callFunction · 0.85
get_handoff_tool_callFunction · 0.85
get_text_messageFunction · 0.85

Tested by

no test coverage detected