Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f09874c

Browse files
authored
Fix agent lifecycle example output to reflect correct hook execution order (openai#1015)
**Problem:** The expected output in the agent lifecycle example incorrectly shows agent start hooks (`on_start`) running after tool execution and multiple times for the same agent. This misleads developers about when these lifecycle events actually occur. **Solution:** Updated the expected output to accurately reflect the OpenAI Agents framework behavior: - Agent start hooks run immediately when an agent begins execution - Start hooks only run once per agent activation, controlled by the `should_run_agent_start_hooks` flag - After handoffs, the new agent's start hook runs as the first event
1 parent 586d4b2 commit f09874c

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

examples/basic/agent_lifecycle_example.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,10 @@ async def main() -> None:
101101
### (Start Agent) 1: Agent Start Agent started
102102
### (Start Agent) 2: Agent Start Agent started tool random_number
103103
### (Start Agent) 3: Agent Start Agent ended tool random_number with result 37
104-
### (Start Agent) 4: Agent Start Agent started
105-
### (Start Agent) 5: Agent Start Agent handed off to Multiply Agent
104+
### (Start Agent) 4: Agent Start Agent handed off to Multiply Agent
106105
### (Multiply Agent) 1: Agent Multiply Agent started
107106
### (Multiply Agent) 2: Agent Multiply Agent started tool multiply_by_two
108107
### (Multiply Agent) 3: Agent Multiply Agent ended tool multiply_by_two with result 74
109-
### (Multiply Agent) 4: Agent Multiply Agent started
110-
### (Multiply Agent) 5: Agent Multiply Agent ended with output number=74
108+
### (Multiply Agent) 4: Agent Multiply Agent ended with output number=74
111109
Done!
112110
"""

examples/basic/lifecycle_example.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,12 @@ async def main() -> None:
105105
Enter a max number: 250
106106
### 1: Agent Start Agent started. Usage: 0 requests, 0 input tokens, 0 output tokens, 0 total tokens
107107
### 2: Tool random_number started. Usage: 1 requests, 148 input tokens, 15 output tokens, 163 total tokens
108-
### 3: Tool random_number ended with result 101. Usage: 1 requests, 148 input tokens, 15 output tokens, 163 total tokens
109-
### 4: Agent Start Agent started. Usage: 1 requests, 148 input tokens, 15 output tokens, 163 total tokens
110-
### 5: Handoff from Start Agent to Multiply Agent. Usage: 2 requests, 323 input tokens, 30 output tokens, 353 total tokens
111-
### 6: Agent Multiply Agent started. Usage: 2 requests, 323 input tokens, 30 output tokens, 353 total tokens
112-
### 7: Tool multiply_by_two started. Usage: 3 requests, 504 input tokens, 46 output tokens, 550 total tokens
113-
### 8: Tool multiply_by_two ended with result 202. Usage: 3 requests, 504 input tokens, 46 output tokens, 550 total tokens
114-
### 9: Agent Multiply Agent started. Usage: 3 requests, 504 input tokens, 46 output tokens, 550 total tokens
115-
### 10: Agent Multiply Agent ended with output number=202. Usage: 4 requests, 714 input tokens, 63 output tokens, 777 total tokens
108+
### 3: Tool random_number ended with result 101. Usage: 1 requests, 148 input tokens, 15 output tokens, 163 total token
109+
### 4: Handoff from Start Agent to Multiply Agent. Usage: 2 requests, 323 input tokens, 30 output tokens, 353 total tokens
110+
### 5: Agent Multiply Agent started. Usage: 2 requests, 323 input tokens, 30 output tokens, 353 total tokens
111+
### 6: Tool multiply_by_two started. Usage: 3 requests, 504 input tokens, 46 output tokens, 550 total tokens
112+
### 7: Tool multiply_by_two ended with result 202. Usage: 3 requests, 504 input tokens, 46 output tokens, 550 total tokens
113+
### 8: Agent Multiply Agent ended with output number=202. Usage: 4 requests, 714 input tokens, 63 output tokens, 777 total tokens
116114
Done!
117115
118116
"""

0 commit comments

Comments
 (0)