-
Notifications
You must be signed in to change notification settings - Fork 340
docs: add agent observability with opik #738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
There was a problem hiding this 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.
```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 | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
The
*_callback
kwargs should go into theLlmAgent
instance rather than theRunner
class, which is causing an error. -
The
runner.run
syntax here is not working for me sinceuser_request
is not a valid kwarg. Instead, one would need to add anew_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. -
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?
There was a problem hiding this comment.
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 👍
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.