- Per message: Each message (assistant, tool, etc.) has its own metrics.
- Per run: Each
RunOutputhas its own metrics. - Per session: The
AgentSessioncontains aggregatedsession_metricsthat are the sum of allRunOutput.metricsfor the session.
Example Usage
Suppose you have an agent that performs some tasks and you want to analyze the metrics after running it. Here’s how you can access and print the metrics: You run the following code to create an agent and run it with the following configuration:input_tokens: The number of tokens sent to the model.output_tokens: The number of tokens received from the model.total_tokens: The sum ofinput_tokensandoutput_tokens.audio_input_tokens: The number of tokens sent to the model for audio input.audio_output_tokens: The number of tokens received from the model for audio output.audio_total_tokens: The sum ofaudio_input_tokensandaudio_output_tokens.cache_read_tokens: The number of tokens read from the cache.cache_write_tokens: The number of tokens written to the cache.reasoning_tokens: The number of tokens used for reasoning.duration: The duration of the run in seconds.time_to_first_token: The time taken until the first token was generated.provider_metrics: Any provider-specific metrics.
Developer Resources
- View the RunOutput schema
- View the Metrics schema
- View Cookbook