AgentOps provides seamless integration with Google Agent Development Kit (ADK), allowing you to track and analyze all your ADK agent interactions automatically.

Installation

Make sure to call agentops.init before calling any openai, cohere, crew, etc models.

pip install agentops google-adk

Basic Usage

Initialize AgentOps at the beginning of your application to automatically track all Google ADK agent interactions:

import asyncio
import uuid
import os
from google.genai import types

import agentops
from google.adk.agents import Agent
from google.adk.runners import InMemoryRunner
from google.adk.agents.run_config import RunConfig, StreamingMode

# Initialize AgentOps
agentops.init(api_key="<INSERT YOUR API KEY HERE>")

# Create a simple agent with no tools
agent = Agent(
    name="simple_agent",
    model="gemini-1.5-flash",
    instruction="You are a helpful assistant that provides clear and concise answers.",
)

# Create a runner
runner = InMemoryRunner(
    agent=agent,
    app_name="simple-example",
)

# Setup session
user_id = f"user-{uuid.uuid4().hex[:8]}"
session_id = f"session-{uuid.uuid4().hex[:8]}"
runner.session_service.create_session(
    app_name="simple-example",
    user_id=user_id,
    session_id=session_id,
)

# Run the agent with a user message
async def run_agent():
    message = "What are three benefits of artificial intelligence?"
    
    content = types.Content(
        role="user",
        parts=[types.Part(text=message)],
    )
    
    run_config = RunConfig(
        streaming_mode=StreamingMode.NONE,
    )
    
    async for event in runner.run_async(
        user_id=user_id,
        session_id=session_id,
        new_message=content,
        run_config=run_config,
    ):
        if hasattr(event, 'content') and event.content and event.content.parts:
            for part in event.content.parts:
                if hasattr(part, 'text') and part.text:
                    print(part.text)

# Run the agent
asyncio.run(run_agent())

Environment Variables

Set your API key as an .env variable for easy access.

AGENTOPS_API_KEY=<YOUR API KEY>
GOOGLE_API_KEY=<YOUR GOOGLE API KEY>

Read more about environment variables in Advanced Configuration

Additional Resources