run-llama/LlamaIndexTS

Usage Visibility for Anthropic and OpenAI when using agent-workflow

Open

#2,207 opened on Sep 18, 2025

 (2 comments) (0 reactions) (0 assignees)TypeScript (524 forks)auto 404
buggood first issuehelp wanted

Repository metrics

Stars
 (3,078 stars)
PR merge metrics
 (PR metrics pending)

Description

1. Anthropic (Streaming)

When using agent-workflow with Anthropic and stream = true, the usage info is filtered out from the chunk.
The usage info is of type "message-delta", and the chunk is not yielded in the code below:

🔗 LlamaIndexTS Anthropic LLM Code

Example payload:

{
  "type": "message_delta",
  "delta": {
    "stop_reason": "end_turn",
    "stop_sequence": null
  },
  "usage": {
    "input_tokens": 8,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "output_tokens": 12
  }
}

2. Anthropic and OpenAI (Non-Streaming)

When running with agent.run, it is returning the finalEvent. However, the finalEvent does not have usage info applicable. https://github.com/run-llama/LlamaIndexTS/blob/main/packages/workflow/src/agent/agent-workflow.ts#L470-L476


Contributor guide