Skip to content

.NET Agent Performance Metrics and Token Usage #2688

@lukemurraynz

Description

@lukemurraynz

Current Behavior: No built-in telemetry for:

Total tokens consumed (input + output)
Cost estimation
Latency breakdown (network, processing, tool calls)
Success/failure rates
Problem: Production applications need to track:

Cost per conversation
Performance bottlenecks
Token usage trends for budgeting
Recommended Changes:

Add Metrics property to AgentRunResponse
Include token counts, latency, and cost estimates
Support custom metric providers
Integrate with OpenTelemetry
Example Desired API:

var result = await agent.RunAsync(prompt);

Console.WriteLine($"Tokens used: {result.Metrics.TotalTokens}");
Console.WriteLine($"  Input: {result.Metrics.InputTokens}");
Console.WriteLine($"  Output: {result.Metrics.OutputTokens}");
Console.WriteLine($"Estimated cost: ${result.Metrics.EstimatedCost:F4}");
Console.WriteLine($"Latency: {result.Metrics.TotalLatency}ms");
Console.WriteLine($"  LLM: {result.Metrics.LlmLatency}ms");
Console.WriteLine($"  Tools: {result.Metrics.ToolLatency}ms");

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions