Overview
The Google ADK integration allows you to:- Automatic Instrumentation: Automatically capture traces from ADK agents without code changes
- Multi-Agent Monitoring: Track complex agent interactions and workflows
- Performance Insights: Monitor agent execution times and resource usage
- Metrics Collection: Collect key metrics such as latency, token usage, and cost for each agent or workflow
- Error Tracking: Capture and analyze agent failures and exceptions
- Custom Logging: Add structured logging to your agent workflows
- Node-Level Evaluation: Apply evaluators to components within an agent trace using Maxim’s node-level evaluation capabilities, enabling granular assessment and scoring of each step or node in an agent workflow
Installation
Prerequisites
- Python 3.10+
- Google ADK installed and configured
- Maxim account and API key
Install Dependencies
Quick Start
1. Environment Setup
Create a.env file in your project directory:
2. Basic Integration
Add Maxim instrumentation to your ADK agent:3. Run Your Agent
Create arun_with_maxim.py file to run your agent:
Important: When using the Python script approach, always call
end_maxim_session() in a finally block to ensure all traces are properly flushed to Maxim before the program exits.Example: Financial Advisor Agent
Here’s a complete example of a financial advisor agent (Agent Example by Google) with Maxim instrumentation:Running the Example
Monitoring and Observability
Dashboard Views
Once your agent is running with Maxim instrumentation, you can monitor:- Agent Performance: Response times, success rates, and error rates
- Workflow Traces: Complete execution paths through your multi-agent system
- Custom Metrics: Business-specific metrics and KPIs
- Error Analysis: Detailed error tracking and debugging information

Key Metrics Tracked
- Agent execution time
- Token usage and costs
- Error rates and types
- Agent interaction patterns
Troubleshooting
Common Issues
Instrumentation not working:- Ensure
instrument_google_adk()is called before agent initialization - Check that your agent is properly imported after instrumentation
- Verify Maxim API key and repository ID are correct
Debug Mode
Enable debug mode for detailed logging:Advanced Integration with Callbacks
For more control over tracing and custom metrics, you can use callback functions to hook into different stages of agent execution.Available Callbacks
Theinstrument_google_adk() function supports the following callbacks:
before_generation_callback: Called before each LLM generationafter_generation_callback: Called after each LLM generation completesbefore_trace_callback: Called at the start of a traceafter_trace_callback: Called when a trace completesbefore_span_callback: Called when creating a span for an agentafter_span_callback: Called when a span completes
Example with Custom Callbacks
Callback Parameters
Each callback receives specific parameters that you can use:Generation Callbacks
callback_context: Context object with request/response detailsllm_request: The original LLM requestllm_response: The LLM response (after_generation only)generation: Maxim Generation object for adding metrics/tags (after_generation only)model_info: Dictionary with model name and configurationmessages: List of messages sent to the LLMusage_info: Token usage statistics (after_generation only)content: Generated content (after_generation only)tool_calls: List of tool calls made (after_generation only)
Trace Callbacks
invocation_context: Agent invocation contexttrace: Maxim Trace object for adding metrics/tags (after_trace only)user_input: The user’s input message (before_trace only)agent_output: The agent’s output (after_trace only)trace_usage: Overall token usage for the trace (after_trace only)
Span Callbacks
invocation_context: Agent invocation context with agent detailsagent_span: Maxim Span object for adding tags/metadata (after_span only)parent_context: Parent span context (before_span only)agent_output: The agent’s output (after_span only)
Adding Custom Metrics and Tags
You can enrich your traces with custom data:Use Cases for Callbacks
- Cost Tracking: Calculate and log estimated costs per trace
- Performance Monitoring: Track latency and throughput metrics
- Custom Analytics: Add business-specific tags for filtering and analysis
- Debugging: Log detailed information about agent execution
- A/B Testing: Tag traces with experiment variants
- User Segmentation: Add user metadata for cohort analysis