Skip to content

Multi-objectives: Implement helper to add token usage tracking and validation in objectives/guide#78

Open
doxav wants to merge 2 commits into
AgentOpt:experimentalfrom
doxav:multiobjective_token_objective_addition
Open

Multi-objectives: Implement helper to add token usage tracking and validation in objectives/guide#78
doxav wants to merge 2 commits into
AgentOpt:experimentalfrom
doxav:multiobjective_token_objective_addition

Conversation

@doxav

@doxav doxav commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator
  • Added UsageTrackingLLM class to wrap LLMs and record token usage.
  • Introduced TokenUsageAugmentingGuide to integrate token metrics into existing guides.
  • Enhanced ObjectiveConfig to include required metrics validation.
  • Implemented tests for required metrics in objectives and token usage in guides.
  • Created JSON output for multi-objective token usage results.

…ives and guides

- Added `UsageTrackingLLM` class to wrap LLMs and record token usage.
- Introduced `TokenUsageAugmentingGuide` to integrate token metrics into existing guides.
- Enhanced `ObjectiveConfig` to include required metrics validation.
- Implemented tests for required metrics in objectives and token usage in guides.
- Created JSON output for multi-objective token usage results.
Comment thread opto/trainer/objectives.py Outdated
return ranks


def _prepare_score_dicts(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name and docstring of this method is ambiguous.
Can we rename to capture the optimization or best selection aspect?

Comment thread opto/trainer/guide.py
return "" if content is None else str(content)


class TokenUsageAugmentingGuide(Guide):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we later make this as a mixin so we can create subclass with this feature dynamically?

Comment thread opto/trainer/guide.py
class UsageTrackingLLM:
"""Wrap an LLM and record token usage for the current execution context.

The wrapper reads OpenAI-compatible usage metadata when available:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check and throw warning when non compatible backends are used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants