Repository navigation
feat(AIC-3412): add the Google ADK agents handler #106
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
Open
andrewklatzke
wants to merge
8
commits into
main
Choose a base branch
from
aklatzke/AIC-3412/add-google-adk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4716801
feat(AIC-3412): add the Google ADK agents handler
andrewklatzke c93e38e
Merge remote-tracking branch 'origin/main' into aklatzke/AIC-3412/add…
apucacao 7a0a889
refactor(google-adk-agents): rename the graph span to launchdarkly.graph
apucacao 4391440
Merge remote-tracking branch 'origin/main' into aklatzke/AIC-3412/add…
andrewklatzke 58b0b35
fix(AIC-3412): report SDK usage, honour the global capture setting, a…
andrewklatzke 0f347aa
fix(AIC-3412): set LaunchDarkly identity attributes on the ADK graph …
andrewklatzke acaec8a
Merge remote-tracking branch 'origin/main' into aklatzke/AIC-3412/add…
andrewklatzke e58baa5
docs(AIC-3412): list the Google ADK package next to the other handlers
andrewklatzke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| """ | ||
| Example: google_adk_agents() — Google ADK agents handler (wildcard provider). | ||
|
|
||
| Gemini Developer API is the default (`GOOGLE_API_KEY`, `GEMINI_API_KEY`, or | ||
| `GOOGLE_GENAI_API_KEY`). Vertex is opt-in: pass `use_vertexai=True` plus project | ||
| and location, or set `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION`. | ||
|
|
||
| Usage (via main.py): | ||
| python main.py google-adk-agents <flag-key> "<user input>" | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
|
|
||
| from examples.tools import ( | ||
| fetch_launchdarkly_documentation, | ||
| get_preferences, | ||
| search_ld_documentation, | ||
| web_search, | ||
| ) | ||
| from examples.utils import new_context, write_output | ||
| from launchdarkly_ai_google_adk_agents import google_adk_agents | ||
|
|
||
|
|
||
| async def run(key: str, user_input: str) -> None: | ||
| response = await google_adk_agents( | ||
| key, | ||
| user_input, | ||
| new_context(), | ||
| tool_handlers={ | ||
| "get-user-preferences": get_preferences, | ||
| "search-ld-documentation": search_ld_documentation, | ||
| "fetch-ld-documentation": fetch_launchdarkly_documentation, | ||
| "fetch-launchdarkly-documentation": fetch_launchdarkly_documentation, | ||
| "web-search": web_search, | ||
| }, | ||
| ) | ||
|
|
||
| print(json.dumps(response, indent=2, default=str)) | ||
| write_output(response) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Google ADK agents | ||
|
|
||
| `launchdarkly-ai-google-adk-agents` is a wildcard agent handler for [Google ADK](https://google.github.io/adk-docs/). It serves any `agent` variation that does not have a more specific provider handler registered. | ||
|
|
||
| ```python | ||
| from launchdarkly_ai_google_adk_agents import google_adk_agents | ||
|
|
||
| response = await google_adk_agents(key, user_input, context, tool_handlers=tools) | ||
| ``` | ||
|
|
||
| Gemini Developer API is the default. Set `GOOGLE_API_KEY`, `GEMINI_API_KEY`, or `GOOGLE_GENAI_API_KEY`. Vertex is explicit: `create_google_adk_agents_handler(use_vertexai=True, project=..., location=...)`. A Gemini credential is never sent on the Vertex path, and a failed call is not retried on the other transport. | ||
|
|
||
| Non-Gemini models use ADK's `LiteLlm` adapter (`pip install 'google-adk[extensions]'`). The model id is `{provider}/{model}` unless the configured name already contains a slash. Pass `model=` to supply your own ADK model and skip both constructors. | ||
|
|
||
| `google-adk` is not declared on this package. Release 2.9.2 caps `opentelemetry-sdk<=1.42.1`, which conflicts with this workspace's exporter. Install ADK in the application environment. | ||
|
|
||
| `to_adk_agents(graph)` compiles a LaunchDarkly agent graph into an ADK `Workflow`. `google_adk_graph(key)` pre-wires this handler for `graph()`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Agent Guide — `launchdarkly-ai-google-adk-agents` | ||
|
|
||
| Wildcard agent handler (`provides_for = ("*", "agent")`) for Google ADK. An exact provider handler still wins when both are registered. | ||
|
|
||
| Gemini Developer API is the default. Vertex is opt-in (`use_vertexai=True`) and requires project and location at factory time. Do not send an API key in Vertex mode, and do not fall back from one transport to the other. | ||
|
|
||
| Python non-Gemini models go through ADK's `google.adk.models.lite_llm.LiteLlm` as `provider/model`. That is ADK's adapter, not `launchdarkly-ai-litellm`. TypeScript `@google/adk` 2.1 has no equivalent; inject `model` or the handler throws. | ||
|
|
||
| `google-adk` is imported lazily and is not a workspace dependency, because 2.9.2 caps `opentelemetry-sdk`. Install it in the app environment (`google-adk[extensions]` when you need LiteLLM). | ||
|
|
||
| ## File map | ||
|
|
||
| | File | Responsibility | | ||
| |---|---| | ||
| | `handler.py` | Factory, session seeding, `LaunchDarklyTelemetryPlugin`, run and stream | | ||
| | `spans.py` | `invoke_agent` / `chat {model}` / `execute_tool {name}` | | ||
| | `graph.py` | `google_adk_graph()` | | ||
| | `native_graph.py` | `to_adk_agents()` | | ||
|
|
||
| Span calls go through the `spans` module attribute so tests can patch them. Tool spans are abandoned from a `finally` (`abandon_open_spans` does not call `fail_span`). `gen_ai.system` is `google_adk`. `gen_ai.provider.name` is the serving provider; Google, Gemini, and Vertex normalize to `gcp.gemini`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| [project] | ||
| name = "launchdarkly-ai-google-adk-agents" | ||
| version = "0.1.0" | ||
| requires-python = ">=3.12" | ||
| dependencies = [ | ||
| "launchdarkly-ai-server", | ||
| "opentelemetry-api>=1.25", | ||
| ] | ||
| # google-adk[extensions]>=2.9.2 is the runtime dependency. It is intentionally | ||
| # not declared yet: 2.9.2 caps opentelemetry-sdk<=1.42.1, which the workspace | ||
| # cannot solve next to opentelemetry-exporter-otlp-proto-http>=1.43. | ||
| description = "Google ADK agent handler for LaunchDarkly AI SDK" | ||
| readme = "README.md" | ||
| license = "Apache-2.0" | ||
| authors = [{name = "LaunchDarkly", email = "team@launchdarkly.com"}] | ||
| keywords = ["launchdarkly", "ai", "google-adk", "agents"] | ||
| classifiers = [ | ||
| "Development Status :: 3 - Alpha", | ||
| "Intended Audience :: Developers", | ||
| "License :: OSI Approved :: Apache Software License", | ||
| "Programming Language :: Python :: 3", | ||
| "Programming Language :: Python :: 3.12", | ||
| "Topic :: Software Development :: Libraries", | ||
| ] | ||
|
|
||
| [project.urls] | ||
| Homepage = "https://github.com/launchdarkly/python-ai-sdk" | ||
| Repository = "https://github.com/launchdarkly/python-ai-sdk" | ||
| "Bug Tracker" = "https://github.com/launchdarkly/python-ai-sdk/issues" | ||
|
|
||
| [build-system] | ||
| requires = ["hatchling>=1.32,<2"] | ||
| build-backend = "hatchling.build" | ||
|
|
||
| [tool.hatch.build.targets.wheel] | ||
| packages = ["src/launchdarkly_ai_google_adk_agents"] |
25 changes: 25 additions & 0 deletions
25
packages/google-adk-agents/src/launchdarkly_ai_google_adk_agents/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """LaunchDarkly AI SDK integration for Google ADK agents. | ||
|
|
||
| See https://launchdarkly.com/docs for usage. | ||
| """ | ||
|
|
||
| from launchdarkly_ai_server import register_ai_sdk_package | ||
|
|
||
| from ._version import PACKAGE_NAME, __version__ | ||
| from .graph import google_adk_graph | ||
| from .handler import ( | ||
| create_google_adk_agents_handler, | ||
| google_adk_agents, | ||
| history_contents, | ||
| ) | ||
| from .native_graph import to_adk_agents | ||
|
|
||
| __all__ = [ | ||
| "create_google_adk_agents_handler", | ||
| "google_adk_agents", | ||
| "google_adk_graph", | ||
| "history_contents", | ||
| "to_adk_agents", | ||
| ] | ||
|
|
||
| register_ai_sdk_package(PACKAGE_NAME, __version__) |
4 changes: 4 additions & 0 deletions
4
packages/google-adk-agents/src/launchdarkly_ai_google_adk_agents/_version.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| """This package's identity, as sent with ``$ld:ai:sdk:info`` and ``$ld:ai:sdk:usage``.""" | ||
|
|
||
| PACKAGE_NAME = "launchdarkly-ai-google-adk-agents" | ||
| __version__ = "0.1.0" # x-release-please-version |
42 changes: 42 additions & 0 deletions
42
packages/google-adk-agents/src/launchdarkly_ai_google_adk_agents/graph.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| """Graph convenience wrapper for the Google ADK agents handler.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from launchdarkly_ai_server import _graph, report_usage | ||
|
|
||
| from ._version import PACKAGE_NAME, __version__ | ||
| from .handler import _create_google_adk_agents_handler | ||
|
|
||
|
|
||
| def google_adk_graph( | ||
| key: str, | ||
| *, | ||
| use_vertexai: bool = False, | ||
| project: str | None = None, | ||
| location: str | None = None, | ||
| model: Any = None, | ||
| capture_content: bool | None = None, | ||
| **options: Any, | ||
| ) -> Any: | ||
| """Runs an agent graph with one wildcard ADK handler pre-bound. | ||
|
|
||
| ``handlers`` passed by the caller is ignored. Auth and model options go to the | ||
| handler factory, not to ``graph()``. | ||
| """ | ||
| report_usage("google-adk-agents.googleAdkGraph", PACKAGE_NAME, __version__) | ||
| options.pop("handlers", None) | ||
| return _graph( | ||
| key, | ||
| handlers=[ | ||
| _create_google_adk_agents_handler( | ||
| use_vertexai=use_vertexai, | ||
| project=project, | ||
| location=location, | ||
| model=model, | ||
| capture_content=capture_content, | ||
| ) | ||
| ], | ||
| **options, | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Graph wrapper drops API key
Medium Severity
google_adk_graphforwards Vertex and model options to the handler factory but never takesapi_key. A caller who passesapi_keysends it to_graph, which only acceptshandlers,tool_handlers,registry, andgraph_judge, so the call raisesTypeErrorinstead of authenticating Gemini.Reviewed by Cursor Bugbot for commit 0f347aa. Configure here.