Skip to content

Streaming agents do not call the agent_end lifecycle hook #371

@desmondpp

Description

@desmondpp

Describe the bug

I need to collect usage information at the end of each of my agent runs. For non-streaming agents I can hook into the agent_end event and fetch the usage information from the run context. However for steaming agents, my handler is never called.

Debug information

  • Agents SDK version: v0.0.17
  • Runtime environment: Node.js 20.19.3

Repro steps

const myAgent = new Agent({
    name: 'My Agent',
    instructions: 'Some instructions'
  });
const runner = new Runner();
const streamResult = await runner.run(myAgent, [], {
   context: {},
   stream: true
});
myAgent.on('agent_tool_start', () => {
  console.log('agent_tool_start called');  // This works!
);
myAgent.on('agent_tool_end', () => {
  console.log('agent_tool_end called');  // This function is never hit
);

Expected behavior

I expect completed streaming agents to call the agent_tool_end handlers.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions