Skip to content

Conversation

@AjayKumbham
Copy link
Contributor

Summary

Fixes #371 - Streaming agents do not call the agent_end lifecycle hook

Changes

  • Fix streaming agents not calling agent_end lifecycle hook when completing execution
  • Add agent_end event emissions in streaming loop to match non-streaming behavior
  • Add tests to verify agent_end events are emitted for both streaming and non-streaming agents
  • Resolves issue where users could not collect usage information from streaming agent runs

Problem

Users reported that agent_end lifecycle hooks work for non-streaming agents but are never called for streaming agents, preventing them from collecting usage information at the end of agent runs.

Solution

Added missing agent_end event emissions in the streaming implementation (packages/agents-core/src/run.ts) to match the non-streaming behavior. Both the runner and agent instances now emit the agent_end event when streaming agents complete execution.

Testing

  • ✅ Added test for streaming agents emitting agent_end events
  • ✅ Added regression test for non-streaming agents
  • ✅ Verified both agent and runner instances emit events
  • ✅ Confirmed event signatures are consistent

Impact

  • Type: Bug fix (patch)
  • Breaking Changes: None
  • Backward Compatibility: Full
  • Performance: Minimal impact (two additional event emissions)

Fixes #371

- Fix streaming agents not calling agent_end lifecycle hook when completing execution
- Add agent_end event emissions in streaming loop to match non-streaming behavior
- Add tests to verify agent_end events are emitted for both streaming and non-streaming agents
- Resolves issue where users could not collect usage information from streaming agent runs

Fixes #371
@changeset-bot
Copy link

changeset-bot bot commented Aug 26, 2025

🦋 Changeset detected

Latest commit: 58cc241

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

- Added assertion to verify result.finalOutput in agent_end lifecycle test
- Resolves ESLint error: 'result' is assigned a value but never used
- Makes test more comprehensive by validating both events and return value
@AjayKumbham
Copy link
Contributor Author

Hi @seratch, I’ve pushed the changes to resolve the CI issues. Could you please review the updates when you have a chance? Thank you.

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't checked if the change is relevant yet, but can you simplify the changeset like I suggest?

@seratch
Copy link
Member

seratch commented Aug 26, 2025

The code change looks good to me

@seratch seratch enabled auto-merge (squash) August 26, 2025 09:26
@seratch seratch merged commit 94f606c into openai:main Aug 26, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streaming agents do not call the agent_end lifecycle hook

2 participants