-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Add token usage tracking to multi-agent workflow #86
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
- Add CostTracker class with generic model/SKU tracking approach - Track input/output/total tokens and request counts from RunResult.raw_responses - Integrate tracking into run_manager_developer_build and run_interactive_build - Add CostEvaluator with business logic for usage assessment - Correlate usage data with existing trace_id for attribution - Save detailed usage summaries to JSON files - Focus on token tracking foundation rather than hardcoded cost calculations Co-Authored-By: AJ Steers <[email protected]>
Original prompt from AJ Steers
|
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
👋 Greetings, Airbyte Team Member!Here are some helpful tips and reminders for your convenience. Testing This Branch via MCPTo test the changes in this specific branch with an MCP client like Claude Desktop, use the following configuration: {
"mcpServers": {
"connector-builder-mcp-dev": {
"command": "uvx",
"args": ["--from", "git+https://github.com/airbytehq/connector-builder-mcp.git@devin/1758422080-add-token-usage-tracking", "connector-builder-mcp"]
}
}
} Testing This Branch via CLIYou can test this version of the MCP Server using the following CLI snippet: # Run the CLI from this branch:
uvx 'git+https://github.com/airbytehq/connector-builder-mcp.git@devin/1758422080-add-token-usage-tracking#egg=airbyte-connector-builder-mcp' --help PR Slash CommandsAirbyte Maintainers can execute the following slash commands on your PR:
|
- Apply ruff formatting to cost_tracking.py and run.py - Convert single quotes to double quotes for consistency - Wrap long lines to meet formatting standards Co-Authored-By: AJ Steers <[email protected]>
- Add cost_summary_report string property to CostTracker class - Consolidate all summary text generation into single property - Simplify run_manager_developer_build to use new summary property - Remove unused CostEvaluator import from run.py - Maintain equivalent summary output with cleaner code structure Co-Authored-By: AJ Steers <[email protected]>
…cking Co-Authored-By: AJ Steers <[email protected]>
- Add comprehensive pricing table for OpenAI, Anthropic, and other models - Implement cost calculation in _calculate_cost method using per-token pricing - Enhance model name extraction with additional fallback strategies - Fix bug in CostEvaluator (thresholds -> _THRESHOLDS) - Add cost display to summary reports with 4-decimal precision - Support for unknown models with conservative pricing estimates Co-Authored-By: AJ Steers <[email protected]>
- Clarifies that tuples represent (input_price_per_1M_tokens, output_price_per_1M_tokens) in USD - Includes example for better understanding - Addresses code documentation feedback Co-Authored-By: AJ Steers <[email protected]>
- Updated _MODEL_PRICING with official pricing from OpenAI and other providers - Organized models by series (GPT-5, GPT-4.1, GPT-4o, O-series, etc.) - Added support for specialized models (realtime, audio, search, computer-use) - Set gpt-image-1 output pricing to 0.00 as it has no output tokens - Updated fallback pricing for unknown-model to be more conservative Co-Authored-By: AJ Steers <[email protected]>
- Added https://platform.openai.com/docs/pricing URL to _MODEL_PRICING docstring - Noted that the pricing page may require login for access - Provides authoritative source for pricing data verification and updates Co-Authored-By: AJ Steers <[email protected]>
- Verified that https://platform.openai.com/docs/pricing requires authentication - Updated docstring from 'may require login' to 'requires login' for accuracy - Browser test showed authentication error when accessing the URL Co-Authored-By: AJ Steers <[email protected]>
- Add fallback logic for OpenAI vs expected attribute naming (completion_tokens vs output_tokens) - Handle missing requests attribute from OpenAI responses (default to 1) - Improve debug logging in _extract_model_name for better troubleshooting - Add comprehensive test scripts to verify both response structure types - Fix token calculation in add_run_result to handle both attribute naming conventions Co-Authored-By: AJ Steers <[email protected]>
…rt pattern - Update usage file save logic to look for manifest.yaml in workspace directory - Save usage files alongside manifest when found, fall back to workspace directory - Follow same pattern as readiness report for consistent file organization - Add logging to show where usage files are being saved Co-Authored-By: AJ Steers <[email protected]>
Co-Authored-By: AJ Steers <[email protected]>
try: | ||
from .constants import WORKSPACE_WRITE_DIR | ||
|
||
usage_dir = WORKSPACE_WRITE_DIR | ||
manifest_files = list(WORKSPACE_WRITE_DIR.glob("**/manifest.yaml")) | ||
if manifest_files: | ||
usage_dir = manifest_files[0].parent | ||
update_progress_log( | ||
f"📁 Found manifest at {manifest_files[0]}, saving usage data in same directory" | ||
) | ||
else: | ||
update_progress_log( | ||
"📁 No manifest.yaml found, saving usage data in workspace directory" | ||
) | ||
|
||
usage_file = usage_dir / f"{trace_id}_usage_summary.json" | ||
cost_tracker.save_to_file(usage_file) | ||
update_progress_log(f"📊 Detailed usage data saved to: {usage_file}") |
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.
I didn't remember we already have this constant: WORKSPACE_WRITE_DIR
Skip checking for manifest.yaml - it doesn't matter.
feat: Add token usage tracking with cost estimation to multi-agent workflow
Summary
Implements comprehensive token usage tracking and cost estimation for the multi-agent connector building workflow. This adds:
manifest.yaml
when availableThe system tracks input/output tokens, request counts, and provides cost estimates in USD during both interactive and manager-developer build modes.
Review & Testing Checklist for Human
3 critical items to verify:
manifest.yaml
files to ensure usage files save to the correct directory. Test edge cases like multiple manifest files or nested directories_MODEL_PRICING
against current OpenAI pricing documentation. Pricing data was provided by user but should be double-checkedAdditional testing:
prompt_tokens
/completion_tokens
) and expected format (input_tokens
/output_tokens
) correctlyNotes
debug_model_extraction.py
,debug_workflow_responses.py
) are included in the diff but may not be needed in productionLink to Devin run: https://app.devin.ai/sessions/49242329340c4c67908d1ff5c10103d7
Requested by: @aaronsteers (AJ Steers)