Skip to content

Conversation

vincentkoc
Copy link
Contributor

Opik is one of the leading open-source telemetry, evaluation and optimization platform. A large % of our open-source users are Google ADK users and our integration has been stable for sometime (we shipped day zero support early on). This PR introduces new documentation and examples following our reference guide (https://www.comet.com/docs/opik/python-sdk-reference/integrations/adk/overview/). Please reach out if you need any changes.

Copy link
Collaborator

@koverholt koverholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for your contribution to ADK and for this integration! ❤️ I left a comment about an error running the sample code, and another comment about a 404 error in a link. So let's work through those.

Copy link
Collaborator

@koverholt koverholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates!

The code sample is not working as-is, so I left another comment along with a proposed version to get it working and make it simpler.

Comment on lines +50 to +74
```python
from google.adk.agents import LlmAgent
from google.adk import runners
from opik.integrations.adk import OpikTracer

weather_agent = LlmAgent(
name="weather_agent",
instruction="You provide friendly weather updates.",
model="gemini-2.0-flash",
)

tracer = OpikTracer(project_name="adk-weather-demo")

runner = runners.Runner(
agent=weather_agent,
app_name="weather_app",
before_agent_callback=tracer.before_agent_callback,
after_agent_callback=tracer.after_agent_callback,
before_model_callback=tracer.before_model_callback,
after_model_callback=tracer.after_model_callback,
)

response = runner.run(user_request="What's the weather in New York?")
tracer.flush() # ensure spans are delivered before the script exits
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The *_callback kwargs should go into the LlmAgent instance rather than the Runner class, which is causing an error.

  2. The runner.run syntax here is not working for me since user_request is not a valid kwarg. Instead, one would need to add a new_message kwarg with a content object, plus a session and user ID, which would require setting up a session service, and other config that would make this code sample much longer.

  3. ADK is complaining about this agent because there is no root_agent defined.

Proposed solution to address all of these:

I suggest updating this code example to the following, then instruct users to run adk web or adk run (which I tested and it's working as expected) to interact with the agent and see the traces in Opik. That way those interfaces will handle setting up the session for the user and the code sample is simpler and focuses on the basic tracing implementation w/ callbacks.


The OpikTracer automatically captures agent execution, tool calls, and model interactions. Attach it to your ADK agents as shown below:

from google.adk.agents import Agent
from opik.integrations.adk import OpikTracer

tracer = OpikTracer(project_name="adk-weather-demo")

root_agent = Agent(
    name="weather_agent",
    instruction="You provide friendly weather updates.",
    model="gemini-2.0-flash",
    before_agent_callback=tracer.before_agent_callback,
    after_agent_callback=tracer.after_agent_callback,
    before_model_callback=tracer.before_model_callback,
    after_model_callback=tracer.after_model_callback,
)

tracer.flush()  # Ensure spans are delivered before the script exits

Then run the agent with ADK using adk web or adk run and send a sample message such as:

What's the weather in New York?

Now you can open the Opik dashboard and navigate to your project to inspect the trace. You will see the agent span, the downstream LLM call, tool invocations (if any), token usage, and cost estimates.


Thoughts on this version of the code sample?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@koverholt super appreciate the response and a suggested example. Let me review and circle back asap 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants