You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following example, the tool call event and the tool call output event are triggered simultaneously,and I believe it's more reasonable to separate them.
test code
importlogginglogging.basicConfig(
format="%(asctime)s.%(msecs)03d - %(levelname)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
logging.getLogger(__name__).setLevel(logging.DEBUG)
logger=logging.getLogger(__name__)
fromagentsimportRunner, Agent, ItemHelpers, function_toolimportasyncioimportrandom@function_tooldefhow_many_jokes() ->int:
awaitasyncio.sleep(3)
returnrandom.randint(1, 2)
asyncdefmain():
agent=Agent(
name="Joker",
instructions="First call the `how_many_jokes` tool, then tell that many jokes.",
tools=[how_many_jokes],
)
result=Runner.run_streamed(
agent,
input="Hello",
)
logger.debug("=== Run starting ===")
asyncforeventinresult.stream_events():
# We'll ignore the raw responses event deltasifevent.type=="raw_response_event":
continueelifevent.type=="agent_updated_stream_event":
logger.debug(f"Agent updated: {event.new_agent.name}")
elifevent.type=="run_item_stream_event":
ifevent.item.type=="tool_call_item":
logger.debug("-- Tool was called")
elifevent.item.type=="tool_call_output_item":
logger.debug(f"-- Tool output: {event.item.output}")
elifevent.item.type=="message_output_item":
logger.debug(
f"-- Message output:\n{ItemHelpers.text_message_output(event.item)}"
)
logger.debug("=== Run complete ===")
if__name__=="__main__":
asyncio.run(main())
current output
2025-06-09 17:02:38.588 - DEBUG - === Run starting ===
2025-06-09 17:02:38.588 - DEBUG - Agent updated: Joker
2025-06-09 17:02:39.770 - DEBUG - -- Tool was called
2025-06-09 17:02:39.770 - DEBUG - -- Tool output: 1
2025-06-09 17:02:40.788 - DEBUG - -- Message output:
Here's a joke for you:
Why don't skeletons fight each other?
They don't have the guts!
2025-06-09 17:02:40.788 - DEBUG - === Run complete ===
For event.item.type in "tool_call_item" and "tool_call_output_item", they are triggered simultaneously, and I believe it's more reasonable to separate them.
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
In the following example, the tool call event and the tool call output event are triggered simultaneously,and I believe it's more reasonable to separate them.
test code
current output
For event.item.type in "tool_call_item" and "tool_call_output_item", they are triggered simultaneously, and I believe it's more reasonable to separate them.
The text was updated successfully, but these errors were encountered: