Replies: 5 comments 2 replies
-
|
You're right to be concerned about potential double-counting. Here's what's happening: Token Inference for SpansLangfuse only infers usage and cost for observations of type However, if the Microsoft Agent Framework is creating observations that Langfuse interprets as Double-Counting IssuesThere are known issues with double-counting in certain scenarios:
RecommendationsTo resolve this:
Could you share a link to a specific trace in Langfuse Cloud so we can examine the observation types and token counting behavior? 📚 Sources:
Have another question? Just tag @inkeep. |
Beta Was this translation helpful? Give feedback.
-
|
Unfortunately, I cannot access the specific trace link you provided as I don't have direct access to your Langfuse Cloud project. However, based on the token counting behavior you're describing with the Microsoft Agent Framework, here's what's likely happening: Token Inference BehaviorLangfuse will attempt to infer token usage when:
The documentation explicitly states: "Only observations of type Potential Causes of Double-CountingIf you're seeing double-counted tokens, the most likely scenarios are:
How to Verify and FixTo diagnose this issue, check in the Langfuse UI:
If Agent Framework observations are incorrectly typed as Could you check the observation types in your trace and share what you find? 📚 Sources: Have another question? Just tag @inkeep. |
Beta Was this translation helpful? Give feedback.
-
|
I cannot directly access or analyze the JSON file you've attached. However, I can help you understand what to look for based on Langfuse's token counting behavior. Key Points About Token InferenceLangfuse only infers usage and cost for observations of type
What to Check in Your Trace JSONLook for these specific fields in your trace JSON:
Expected BehaviorAccording to the documentation, usage types are summarized as follows: "In the UI, Langfuse summarizes all usage types that include the string SolutionTo prevent double-counting, ensure that Agent Framework observations are created as type If you can share specific observation types and whether usage details are present in the JSON, I can provide more targeted guidance. 📚 Sources: Have another question? Just tag @inkeep. |
Beta Was this translation helpful? Give feedback.
-
|
Based on the metadata you've shared, I can now identify the issue. Your From the documentation: "Any span that includes an attribute mapped to Why Token Inference is HappeningEven though the Microsoft Agent Framework sets
The Double-Counting ProblemThe double-counting occurs because:
SolutionTo prevent this, you need to ensure the If you cannot modify the Agent Framework's OpenTelemetry instrumentation, you could alternatively:
The key issue is that the presence of 📚 Sources: Have another question? Just tag @inkeep. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @eddieahn, could you send an example how and why you are using |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe your question
When using the Microsoft Agent Framework, every ChatAgent, is decorated with capture_usage=False. This means:
the Agent Framework intentionally does not send token usage on invoke_agent spans.
But it seems like Langfuse estimates tokens for type spans anyway. As a result, it looks like the total count within Langfuse is double counted and an inaccurate representation on the number of tokens and cost.
If you could please take a look and confirm, that would be great!
Langfuse Cloud or Self-Hosted?
Langfuse Cloud
If Self-Hosted
No response
If Langfuse Cloud
No response
SDK and integration versions
No response
Pre-Submission Checklist
Beta Was this translation helpful? Give feedback.
All reactions