-
Notifications
You must be signed in to change notification settings - Fork 209
Closed
Labels
Description
I’ve noticed that the agent_updated_stream_event payload returns the previous agent, not the new one (stream.currentAgent). For example, if the call starts with Agent A and then hands off to Agent B, the event payload looks like this:
{
type: 'agent_updated_stream_event',
agent: {
name: 'Agent A'
}
}
Debug information
- Agents SDK version: (e.g.
v0.0.11
) - Runtime environment (e.g.
Node.js 22.16.0
)
Repro steps
Run this minimal TypeScript snippet to reproduce the issue:
import { Agent, Runner } from '@openai/agents'
import chalk from 'chalk'
const agentB = new Agent({
name: 'Agent B',
})
const agentA = new Agent({
name: 'Agent A',
handoffs: [agentB],
instructions: `You are a helpful assistant. You will hand off to Agent B when asked math questions.`,
})
const runner = new Runner({
model: 'gpt-4.1-mini',
})
async function main() {
const stream = await runner.run(agentA, 'What is the answer to: 2 + 3', { stream: true })
for await (const event of stream) {
// these are the raw events from the model
if (event.type === 'raw_model_stream_event') {
console.log(`${chalk.bgWhite(event.type)} %o`, event.data)
}
// agent updated events
if (event.type == 'agent_updated_stream_event') {
console.log(`${chalk.bgGreen(event.type)} New agent: %s`, event.agent.name)
}
// Agent SDK specific events
if (event.type === 'run_item_stream_event') {
console.log(`${chalk.bgYellow(event.type)} %o`, event.item)
}
}
}
main().catch(console.error)
Observe the agent_updated_stream_event payload.
Actual vs. Expected
- Actual: The agent field contains the old agent’s name.
- Expected: The agent field should contain the new agent’s name (the target of the handoff).
Expected behaviour
This does't seem like intuitive behaviour and I'm not sure if it was intended. I would've expected to see the target agent in the payload, not the agent I already knew was active. In other words, I'd expect this event to tell me what agent we're handing off to, not which agent we've handed off from.
Also, please consider adding a Streaming Events section to the documentation that:
- Lists each event type (e.g. agent_updated_stream_event)
- Describes its payload schema
- Gives example payloads for common scenarios