Hello @agnoteam
Hi everyone,
I’m running into an issue where AgentOS is not capturing the token metrics from a workflow that runs inside a custom tool.
My Setup
I have a Team with a custom async tool that internally runs a Workflow:
@tool
async def process_documents(
run_input: RunInput,
run_context: RunContext,
) -> AsyncGenerator[Any, Any]:
workflow = my_workflow()
async for event in workflow.arun(
input=run_input.input_content,
session_state=run_context.session_state,
session_id=run_context.session_id,
stream=True,
stream_events=True,
):
yield event
my_team = Team(
name="Document Processing Team",
tools=[process_documents],
# ... other config
)
The Problem
When I print the metrics from the workflow events, I see the actual token usage:
{'input_tokens': 4201, 'output_tokens': 2288, 'total_tokens': 6489}
{'input_tokens': 4034, 'output_tokens': 2137, 'total_tokens': 6171}
{'input_tokens': 3720, 'output_tokens': 1142, 'total_tokens': 4862}
But in AgentOS, I only see:
Input Tokens: 4,960
Output Tokens: 145
Total Tokens: 5,105
AgentOS is only tracking the outer Team’s metrics and completely missing the ~17,500 tokens consumed by the inner workflow agents.
Questions
-
Is there a way to have nested workflow metrics automatically propagate to AgentOS?
-
Would using
WorkflowToolsinstead of a custom tool solve this? -
Is this a known limitation or am I missing something?
This is important for tracking actual token usage and costs. Any help appreciated!
Thanks!