|
| 1 | +--- |
| 2 | +id: google-adk |
| 3 | +title: Google ADK |
| 4 | +sidebar_label: Google ADK |
| 5 | +--- |
| 6 | +[Google's Agent Development Kit (ADK)](https://adk.dev/) is an open-source framework for building, orchestrating, and tracing generative-AI agents. |
| 7 | + |
| 8 | +:::tip |
| 9 | +We recommend logging in to [Confident AI](https://app.confident-ai.com) to view your Google ADK evaluations. |
| 10 | + |
| 11 | +```bash |
| 12 | +deepeval login |
| 13 | +``` |
| 14 | + |
| 15 | +For users in the EU region, please set your OTEL endpoint in the env as following: |
| 16 | + |
| 17 | +```bash |
| 18 | +export CONFIDENT_OTEL_URL="https://eu.otel.confident-ai.com" |
| 19 | + |
| 20 | +``` |
| 21 | + |
| 22 | +Or if you're in the AU region, please set your OTEL endpoint in the env as following: |
| 23 | + |
| 24 | +```bash |
| 25 | +export CONFIDENT_OTEL_URL="https://au.otel.confident-ai.com" |
| 26 | + |
| 27 | +``` |
| 28 | + |
| 29 | +::: |
| 30 | + |
| 31 | +`deepeval` instruments Google ADK through the community-maintained [`openinference-instrumentation-google-adk`](https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-google-adk) package. Every ADK agent, model call, and tool invocation emits an OTel span tagged with OpenInference semantic conventions, which `deepeval` then translates into Confident AI traces. |
| 32 | + |
| 33 | +```bash |
| 34 | +pip install google-adk openinference-instrumentation-google-adk |
| 35 | +``` |
| 36 | + |
| 37 | +## End-to-End Evals |
| 38 | + |
| 39 | +`deepeval` allows you to evaluate Google ADK agents in **under a minute**. |
| 40 | + |
| 41 | +<Steps> |
| 42 | + |
| 43 | +<Step> |
| 44 | +### Configure Google ADK |
| 45 | + |
| 46 | + |
| 47 | +Pass `agent_metrics` to the `instrument_google_adk` method. |
| 48 | + |
| 49 | +```python title="main.py" showLineNumbers |
| 50 | +from google.adk.agents import Agent |
| 51 | +from google.adk.runners import Runner |
| 52 | +from google.adk.sessions import InMemorySessionService |
| 53 | +from google.genai import types |
| 54 | + |
| 55 | +from deepeval.integrations.google_adk import instrument_google_adk |
| 56 | +from deepeval.metrics import AnswerRelevancyMetric |
| 57 | + |
| 58 | +instrument_google_adk( |
| 59 | + name="Google ADK Tracing", |
| 60 | + environment="development", |
| 61 | + agent_metrics=[AnswerRelevancyMetric()], |
| 62 | +) |
| 63 | + |
| 64 | +def get_weather(city: str) -> dict: |
| 65 | + return {"city": city, "forecast": "sunny, 24C"} |
| 66 | + |
| 67 | +weather_agent = Agent( |
| 68 | + name="weather_agent", |
| 69 | + model="gemini-2.0-flash", |
| 70 | + instruction="Use the get_weather tool to answer questions about the weather.", |
| 71 | + tools=[get_weather], |
| 72 | +) |
| 73 | + |
| 74 | +APP_NAME = "weather_app" |
| 75 | +USER_ID = "demo-user" |
| 76 | +SESSION_ID = "demo-session" |
| 77 | + |
| 78 | +session_service = InMemorySessionService() |
| 79 | +session_service.create_session( |
| 80 | + app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID |
| 81 | +) |
| 82 | +runner = Runner( |
| 83 | + agent=weather_agent, app_name=APP_NAME, session_service=session_service |
| 84 | +) |
| 85 | + |
| 86 | +def invoke(prompt: str) -> str: |
| 87 | + user_msg = types.Content(role="user", parts=[types.Part(text=prompt)]) |
| 88 | + final = "" |
| 89 | + for event in runner.run( |
| 90 | + user_id=USER_ID, session_id=SESSION_ID, new_message=user_msg |
| 91 | + ): |
| 92 | + if event.is_final_response(): |
| 93 | + final = event.content.parts[0].text |
| 94 | + return final |
| 95 | + |
| 96 | +invoke("What's the weather in Paris?") |
| 97 | +``` |
| 98 | + |
| 99 | +:::info |
| 100 | +Evaluations are supported for Google ADK `Agent`. Only metrics with parameters `input`, `output` and `tools_called` are eligible for evaluation. |
| 101 | +::: |
| 102 | + |
| 103 | +</Step> |
| 104 | +<Step> |
| 105 | +### Run evaluations |
| 106 | + |
| 107 | + |
| 108 | +Create an `EvaluationDataset` and invoke your Google ADK agent for each golden within the `evals_iterator()` loop to run end-to-end evaluations. |
| 109 | + |
| 110 | +<Tabs items={["Synchronous"]}> |
| 111 | +<Tab value="Synchronous"> |
| 112 | + |
| 113 | +```python title="main.py" showLineNumbers |
| 114 | +from deepeval.dataset import EvaluationDataset, Golden |
| 115 | +from deepeval.evaluate.configs import AsyncConfig |
| 116 | + |
| 117 | +dataset = EvaluationDataset( |
| 118 | + goldens=[ |
| 119 | + Golden(input="What's the weather in Paris?"), |
| 120 | + Golden(input="What's the weather in London?"), |
| 121 | + ] |
| 122 | +) |
| 123 | + |
| 124 | +for golden in dataset.evals_iterator(async_config=AsyncConfig(run_async=False)): |
| 125 | + invoke(golden.input) |
| 126 | +``` |
| 127 | + |
| 128 | +</Tab> |
| 129 | +</Tabs> |
| 130 | + |
| 131 | +✅ Done. The `evals_iterator` will automatically generate a test run with individual evaluation traces for each golden. |
| 132 | + |
| 133 | +</Step> |
| 134 | + |
| 135 | +</Steps> |
| 136 | + |
| 137 | +## Evals in Production |
| 138 | + |
| 139 | +To run online evaluations in production, replace `agent_metrics` with a [metric collection](https://www.confident-ai.com/docs/metrics/metric-collections) string from Confident AI, and run your Google ADK agent as usual: |
| 140 | + |
| 141 | +```python filename="main.py" showLineNumbers |
| 142 | +from google.adk.agents import Agent |
| 143 | +from deepeval.integrations.google_adk import instrument_google_adk |
| 144 | + |
| 145 | +instrument_google_adk( |
| 146 | + name="Google ADK Tracing", |
| 147 | + environment="production", |
| 148 | + trace_metric_collection="my-trace-collection", |
| 149 | + agent_metric_collection="my-agent-collection", |
| 150 | + llm_metric_collection="my-llm-collection", |
| 151 | + tool_metric_collection_map={ |
| 152 | + "get_weather": "my-tool-collection", |
| 153 | + }, |
| 154 | +) |
| 155 | + |
| 156 | +weather_agent = Agent( |
| 157 | + name="weather_agent", |
| 158 | + model="gemini-2.0-flash", |
| 159 | + instruction="Use the get_weather tool to answer questions about the weather.", |
| 160 | + tools=[get_weather], |
| 161 | +) |
| 162 | +``` |
| 163 | + |
| 164 | +`deepeval` allows you to run component evals at different levels like Trace, Agent, LLM and Tool spans. You can pass your metric collection for any spans using the `instrument_google_adk` method. |
| 165 | + |
| 166 | +## Combining with `@observe` |
| 167 | + |
| 168 | +`instrument_google_adk` is OTel-based, but it composes cleanly with deepeval's native `@observe` decorator. When an ADK call runs inside an `@observe`'d function, both the deepeval-native span (your Python function) and the OTel spans (ADK's agent, LLM, and tool invocations) land on the same trace. |
| 169 | + |
| 170 | +```python title="main.py" showLineNumbers |
| 171 | +from deepeval.tracing import observe |
| 172 | +from deepeval.metrics import AnswerRelevancyMetric |
| 173 | +from deepeval.integrations.google_adk import instrument_google_adk |
| 174 | + |
| 175 | +instrument_google_adk(name="Google ADK Tracing", environment="development") |
| 176 | + |
| 177 | +@observe(type="agent", metrics=[AnswerRelevancyMetric()]) |
| 178 | +def my_pipeline(query: str) -> str: |
| 179 | + # ADK runs here -> OTel spans, attached to the SAME trace |
| 180 | + return invoke(query) |
| 181 | +``` |
| 182 | + |
| 183 | +## Using `deepeval.instrument(...)` directly |
| 184 | + |
| 185 | +If you'd rather wire up `GoogleADKInstrumentor` yourself (for example, alongside other OpenInference instrumentors), use `deepeval.instrument(...)` to set up the OTel backend once and call any OpenInference instrumentor on top of it: |
| 186 | + |
| 187 | +```python title="main.py" showLineNumbers |
| 188 | +import deepeval |
| 189 | +from openinference.instrumentation.google_adk import GoogleADKInstrumentor |
| 190 | + |
| 191 | +deepeval.instrument(name="my-adk-app", environment="development") |
| 192 | +GoogleADKInstrumentor().instrument() |
| 193 | +``` |
| 194 | + |
| 195 | +This is the same pattern you'd use for any other OpenInference-instrumented framework. |
0 commit comments