Production-ready services, credentials, and FastAPI wiring for Google ADK
Project description
google-adk-extras
Production-ready extensions for Google ADK (Agent Development Kit). This library adds durable service backends (sessions, artifacts, memory), practical credential services (OAuth2/JWT/Basic), and clean FastAPI wiring so you can run ADK agents with real storage and auth.
What this is not: a fork of ADK. It builds on ADK’s core runtime, agents, tools and callbacks, and drops in where ADK expects services and a web server.
Why it exists
ADK provides the core primitives (Runner, Session/State, MemoryService, ArtifactService, CredentialService, Agents/Tools, callbacks, Dev UI, and deployment paths). See the official ADK docs for concepts and APIs.
This package focuses on three gaps common in real apps:
- Durable storage backends beyond in‑memory defaults
- Usable credential flows (Google/GitHub/Microsoft/X OAuth2, JWT, Basic)
- FastAPI integration that accepts your credential service without hacks
Features
- Session services: SQL (SQLite/Postgres/MySQL), MongoDB, Redis, YAML files
- Artifact services: Local folder (versioned), S3‑compatible, SQL, MongoDB
- Memory services: SQL, MongoDB, Redis, YAML files (term search over text parts)
- Credential services: Google/GitHub/Microsoft/X (OAuth2), JWT, HTTP Basic
- Enhanced FastAPI wiring that respects a provided credential service
- Fluent builder (
AdkBuilder) to assemble a FastAPI app or a Runner - A2A helpers for exposing/consuming agents (see below)
Note on Runner: EnhancedRunner is a thin subclass of ADK’s Runner for compatibility with the enhanced web server; it does not change behavior.
Install
Requirements: Python 3.12+, google-adk.
Using uv:
# create a venv (optional)
uv venv && source .venv/bin/activate
# install the package
uv pip install google-adk-extras
If you plan to use specific backends, also install their clients (examples):
- SQL:
uv pip install sqlalchemy - MongoDB:
uv pip install pymongo - Redis:
uv pip install redis - S3:
uv pip install boto3 - JWT:
uv pip install PyJWT
Quickstart (FastAPI)
Use the fluent builder to wire services and credentials. Then run with uvicorn.
# app.py
from google_adk_extras import AdkBuilder
from google_adk_extras.credentials import GoogleOAuth2CredentialService
app = (
AdkBuilder()
.with_agents_dir("./agents") # ADK agents on disk
.with_session_service("sqlite:///./sessions.db") # or: mongodb://, redis://, yaml://
.with_artifact_service("local://./artifacts") # or: s3://bucket, mongodb://, sql://
.with_memory_service("yaml://./memory") # or: redis://, mongodb://, sql://
.with_credential_service(GoogleOAuth2CredentialService(
client_id="…apps.googleusercontent.com",
client_secret="…",
scopes=["openid", "email", "profile"],
))
.with_web_ui(True) # serve ADK’s dev UI if assets available
.with_agent_reload(True)
.build_fastapi_app()
)
Run:
uvicorn app:app --reload
If you don’t keep agents on disk, register them programmatically and use a custom loader (see below).
Quickstart (Runner)
Create a Runner wired with your chosen backends. Use agent name (filesystem loader) or pass an agent instance.
from google_adk_extras import AdkBuilder
runner = (
AdkBuilder()
.with_agents_dir("./agents")
.with_session_service("sqlite:///./sessions.db")
.with_memory_service("redis://localhost:6379")
.with_artifact_service("local://./artifacts")
.build_runner("my_agent")
)
result = await runner.run("Hello there!")
How this extends ADK (in practice)
ADK defines abstract service interfaces and a runner/web stack. This package provides drop‑in implementations and a small web‑server shim:
- Sessions
SQLSessionService— SQLAlchemy; JSON‑serialized state/eventsMongoSessionService— PyMongo; per‑session doc, indexed by app/user/idRedisSessionService— hashes per session + user set; JSON state/events
YamlFileSessionService—base/app/user/{session_id}.yaml
A2A helpers (new)
Two light-weight helpers wrap ADK’s A2A capabilities:
-
AdkBuilder.enable_a2a_for_registered_agents(enabled=True, mount_base="/a2a", card_factory=None)- Expose programmatically registered agents (added via
with_agent_instance()/with_agents()) over A2A without anagents_dir. - Optionally supply
card_factory(name, agent) -> dictto build an Agent Card; otherwise a minimal card is used.
- Expose programmatically registered agents (added via
-
AdkBuilder.with_remote_a2a_agent(name, agent_card_url, description=None)- Register a
RemoteA2aAgentby agent card URL so your root agent can delegate to a remote agent. - Requires
google-adk[a2a]installed.
- Register a
Expose a programmatic agent via A2A:
from google_adk_extras import AdkBuilder
from google.adk.agents import Agent
hello = Agent(model="gemini-2.0-flash", name="hello", instruction="You are helpful.")
app = (
AdkBuilder()
.with_agent_instance("hello", hello)
.with_a2a_protocol(True)
.enable_a2a_for_registered_agents() # becomes available at /a2a/hello
.build_fastapi_app()
)
Consume a remote A2A agent:
from a2a.utils.constants import AGENT_CARD_WELL_KNOWN_PATH
from google_adk_extras import AdkBuilder
card_url = f"http://remote-host:8001/a2a/prime{AGENT_CARD_WELL_KNOWN_PATH}"
app = (
AdkBuilder()
.with_remote_a2a_agent("prime_agent", card_url, description="Prime checker")
# add your root agent via with_agent_instance(...)
.build_fastapi_app()
)
-
Artifacts
LocalFolderArtifactService— per‑artifact metadata JSON + versioned data filesS3ArtifactService— metadata JSON + versioned data objects in S3‑compatible storageSQLArtifactService— blobs per version in SQLMongoArtifactService— blobs per version in MongoDB
-
Memory
SQLMemoryService,MongoMemoryService,RedisMemoryService,YamlFileMemoryService- Extracts text from
google.genai.types.Content, tokenizes simple terms, and searches terms
-
Credentials
- OAuth2: Google, GitHub, Microsoft, X (Twitter)
- Tokens: JWT (generate/verify/refresh‑aware), HTTP Basic (+ multi‑user variant)
- Persist via ADK’s session/in‑memory credential stores
-
FastAPI integration
get_enhanced_fast_api_app(...)accepts a provided credential serviceEnhancedAdkWebServerreturnsEnhancedRunnerand keeps ADK’s caching/cleanup- Prefer the fluent
AdkBuilder()path for multi‑backend wiring in one place
Agent loading options
- Directory loading (ADK default):
with_agents_dir("./agents")and create./agents/<app_name>/agent.json(or your ADK agent files) per app. - Programmatic agents: register instances and avoid a folder layout.
from google_adk_extras import AdkBuilder
from google_adk_extras.custom_agent_loader import CustomAgentLoader
from google.adk.agents.base_agent import BaseAgent
loader = CustomAgentLoader()
loader.register_agent("my_app", BaseAgent(name="my_app")) # replace with a real agent
app = (
AdkBuilder()
.with_agent_loader(loader)
.with_session_service("sqlite:///./sessions.db")
.build_fastapi_app()
)
Credential URI cheatsheet (optional)
If you prefer URIs instead of constructing services:
- Google OAuth2:
oauth2-google://client_id:secret@scopes=openid,email,profile - GitHub OAuth2:
oauth2-github://client_id:secret@scopes=user,repo - Microsoft OAuth2:
oauth2-microsoft://<tenant>/<client_id>:<secret>@scopes=User.Read - X OAuth2:
oauth2-x://client_id:secret@scopes=tweet.read,users.read - JWT:
jwt://<secret>@algorithm=HS256&issuer=my-app&audience=api.example.com&expiration_minutes=60 - Basic:
basic-auth://username:password@realm=My%20API
cred = (
AdkBuilder()
.with_credential_service_uri("jwt://secret@issuer=my-app")
._create_credential_service()
)
Notes & limitations
- The runner in this package is intentionally thin. All agent logic, tools, callbacks, and evaluation remain ADK responsibilities.
- The repository currently ships only the pieces listed above; referenced registries or configuration subsystems are intentionally out of scope.
- Some direct FastAPI parameters (e.g., ADK’s special memory URIs) pass through for parity, but the fluent builder is the recommended path for the extended backends offered here.
Docs
This repo ships a full MkDocs site in docs/.
Build locally with uv:
uv pip install .[docs]
uv run mkdocs serve
Development
uv sync # or: pip install -e .
pytest -q # run tests
License
Apache 2.0 — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file google_adk_extras-0.2.3.tar.gz.
File metadata
- Download URL: google_adk_extras-0.2.3.tar.gz
- Upload date:
- Size: 66.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c90b361f84059bd89d8dc047faf727c8e0d26ef4feb20cf259110201aaedab9
|
|
| MD5 |
2104089861cdc9cd7fb5849556b85320
|
|
| BLAKE2b-256 |
5fde3bc83ec4ff4ff2f53dfe1e7bde2eb729aee56ce7a0167fd4eba29a8ea3bf
|
File details
Details for the file google_adk_extras-0.2.3-py3-none-any.whl.
File metadata
- Download URL: google_adk_extras-0.2.3-py3-none-any.whl
- Upload date:
- Size: 81.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23c51839b8f43702e7bea9296dd645a14252a0038aad8ee7dea13f3ededfd044
|
|
| MD5 |
0a58445f5703fb729c49bec54846aa78
|
|
| BLAKE2b-256 |
58ae52caed15ad9be5ad3bd3a7b556777ed550922a5f5a57240f38252309d6d3
|