-
-
Notifications
You must be signed in to change notification settings - Fork 62
Improved Usage Tracking #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…er normalization and cleanup processes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request introduces normalized usage statistics across all providers (OpenAI, Anthropic, Ollama, and OpenRouter) by adding a unified Usage model. The changes enable consistent access to token usage statistics regardless of which provider is being used.
Key changes:
- Added comprehensive unit tests for provider transform modules to verify gem-to-hash conversions and parameter normalization
- Implemented
Usagemodel tests covering all provider formats with auto-detection capabilities - Added integration tests with VCR cassettes for all providers to validate response handling
- Updated documentation and added inline documentation for model classes
Reviewed Changes
Copilot reviewed 214 out of 216 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/providers/open_router/transforms_test.rb | Unit tests for OpenRouter-specific transforms including parameter extraction, serialization, and response format handling |
| test/providers/open_ai/responses/transforms_test.rb | Unit tests for OpenAI Responses API transforms covering input normalization, response format handling, and message simplification |
| test/providers/open_ai/embedding/transforms_test.rb | Unit tests for OpenAI Embedding transforms including input normalization, parameter handling, and serialization cleanup |
| test/providers/open_ai/chat/transforms_test.rb | Comprehensive unit tests for OpenAI Chat transforms covering message normalization, content handling, and instruction processing |
| test/providers/ollama/embedding/transforms_test.rb | Unit tests for Ollama Embedding transforms including Ollama-specific parameter extraction and input validation |
| test/providers/ollama/chat/transforms_test.rb | Unit tests for Ollama Chat transforms covering message grouping and Ollama-specific parameter handling |
| test/providers/common/usage_test.rb | Core unit tests for Usage model covering all provider formats, auto-detection, and field normalization |
| test/providers/anthropic/transforms_test.rb | Unit tests for Anthropic transforms covering message normalization, content handling, and response cleanup |
| test/integration/* | Integration tests with VCR cassettes validating real API response handling across all providers |
| test/fixtures/vcr_cassettes/* | VCR cassettes capturing real API responses for reliable integration testing |
| test/docs/providers/anthropic_examples_test.rb | Fixed assertion argument order to follow Minitest conventions |
| lib/active_agent/providers/open_router/requests/prediction.rb | Added comprehensive inline documentation for Prediction model |
| lib/active_agent/providers/open_router/requests/message.rb | Removed unused require statement |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
73106c7 to
f0ace9a
Compare
603d0ec to
3dfd9fd
Compare
3dfd9fd to
2825f2c
Compare
This is to improved usage tracking and instrumentation for cost monitoring and APM integration. The original instrumentation was a slop coded prototype, that didn't actually work in a way that is useful. This cuts it down and restructures it for APM integration while adding usage normalization.
Multi-Turn Usage Tracking
Cumulative token tracking across tool calling cycles:
Usage Statistics
Consistent token tracking across all providers:
Provider-specific fields:
reasoning_tokens,audio_tokens,cache_creation_tokens,service_tier,duration_msCombine usage objects:
APM Integration
Unified instrumentation events with comprehensive payloads:
Top-level events (overall request lifecycle):
Provider-level events (per API call):
Event payloads include:
model,temperature,max_tokens,top_p,stream,message_count,has_toolsinput_tokens,output_tokens,total_tokens,cached_tokens,reasoning_tokens,audio_tokens,cache_creation_tokensfinish_reason,response_model,response_id,embedding_countEmbedding events:
New response methods:
Breaking Change