mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
fix(metrics) Merge metrics of agent LLM and condenser LLM (#7890)
Co-authored-by: Carlos Freund <carlosfreund@gmail.com>
This commit is contained in:
@@ -67,7 +67,6 @@ from openhands.events.observation import (
|
||||
)
|
||||
from openhands.events.serialization.event import event_to_trajectory, truncate_content
|
||||
from openhands.llm.llm import LLM
|
||||
from openhands.llm.metrics import Metrics
|
||||
|
||||
# note: RESUME is only available on web GUI
|
||||
TRAFFIC_CONTROL_REMINDER = (
|
||||
@@ -1142,15 +1141,21 @@ class AgentController:
|
||||
- accumulated_cost: The current total cost
|
||||
- accumulated_token_usage: Accumulated token statistics across all API calls
|
||||
|
||||
This includes metrics from both the agent's LLM and the condenser's LLM if it exists.
|
||||
|
||||
Args:
|
||||
action: The action to attach metrics to
|
||||
"""
|
||||
metrics = self.agent.llm.metrics.copy()
|
||||
|
||||
# Include condenser metrics if they exist
|
||||
if hasattr(self.agent, 'condenser') and hasattr(self.agent.condenser, 'llm'):
|
||||
metrics.merge(self.agent.condenser.llm.metrics)
|
||||
|
||||
# Create a minimal metrics object with just what the frontend needs
|
||||
metrics = Metrics(model_name=self.agent.llm.metrics.model_name)
|
||||
metrics.accumulated_cost = self.agent.llm.metrics.accumulated_cost
|
||||
metrics._accumulated_token_usage = (
|
||||
self.agent.llm.metrics.accumulated_token_usage
|
||||
)
|
||||
metrics._token_usages = []
|
||||
metrics._response_latencies = []
|
||||
metrics._costs = []
|
||||
|
||||
action.llm_metrics = metrics
|
||||
|
||||
|
||||
Reference in New Issue
Block a user