Documentation / Integrations

Run bounded Google ADK agents

04 - Build · 02 - Get started

A lending agent may see both source facts and session state. Reusing its result after either changes risks a stale assessment; rerunning independent credit work adds unnecessary calls. Use versioned accessible session snapshots and Co2 artifacts alongside fresh ADK executions, then let the host route affected agents.

Install and run

Use CPython 3.11–3.14 and the Rust/Maturin prerequisites in the Python SDK guide. From the repository root:

python -m venv .venv
source .venv/bin/activate
python -m pip install -e '.[google-adk]'
python examples/google_adk_lending.py
python -m unittest discover -s agent_frameworks_tests/google_adk -v

The mock uses the actual ADK Runner.run_async, LlmAgent and InMemorySessionService, with a public BaseLlm test double and synthetic data. It makes no provider calls or financial operations. The integration was exercised on CPython 3.14 on the documented hosts; see the configuration matrix rather than inferring every combination from package metadata.

The optional Gemini experiment uses up to six model-boundary calls, at most one ADK LLM call per run, 256 output tokens, a 30-second client timeout and one HTTP attempt. It is opt-in and requires a Google API key:

# Set GOOGLE_API_KEY or GEMINI_API_KEY in the environment or local .env.
python examples/google_adk_lending.py --live --model gemini-2.5-flash --env-file .env
# Optional, separate live test; consumes up to six more calls:
CO2_LIVE_GOOGLE_ADK_TEST=1 python -m unittest discover -s agent_frameworks_tests/google_adk -v

The environment wins over .env; do not print or commit credentials. The live Gemini run and opt-in smoke test are unverified in this implementation because no Google/Gemini credentials were available. Provider defaults, quotas, retries, model availability, pricing and elapsed-time behavior must be checked in the intended environment. A client timeout is per request; it is not an end-to-end deadline or a billing guarantee. The mock's model call counts are real calls to the fake model, not live-provider measurements. Run the executable mock example to inspect its counters.

Dependency Compatibility

The extra pins google-adk==2.15.1; it does not add Google dependencies to the base SDK. A fresh combined local install of google-adk, openai-agents, langgraph, and llm-example resolved and pip check passed, with google-genai==2.34.0, openai-agents==0.20.0, openai==2.54.0, and langgraph==1.2.24.

There is a shared transitive version constraint, even though the extras can be resolved together. The tested combined resolver selected websockets==15.0.1 because ADK requires <16, and tenacity==9.1.4 because google-genai requires <9.2. An existing environment with either newer version will have those packages downgraded on a combined install, or the resolver will fail if they are strictly pinned.

Use a separate environment if that change is undesirable. The combined Python regression suite was tested with these selected versions; compatibility of unrelated applications and other platform builds is not established.

Map executions and session inputs

Each GoogleADKAdapter has a unique in-process Co2 namespace and its own ADK InMemorySessionService. A host-supplied logical agent name maps to a Co2 computation. Each explicitly requested run receives a unique Co2 attempt, a fresh ADK (app_name, user_id, session_id) and invocation ID, and, on successful atomic registration, a new immutable Co2 artifact. ADKResult exposes these IDs and the Co2 record. Historical human and effect records have no ADK execution/session and never execute anything.

Before a run, call register_session_state(agent, version, state) with the complete session state accessible to that agent. The adapter stores an immutable JSON snapshot and registers its version as a Co2 resource. A version cannot be reused for different state content within the adapter's lifetime, including after intervening versions. State accepts JSON values with unprefixed string keys; ADK's app:, user: and temp: scopes are rejected to avoid implicit shared state. Session bytes can contain sensitive information: the host owns their classification, retention and access. Avoid secrets in session state and source identifiers.

run_agent requires the expected session_state_version, all other accessible resource versions, upstream artifact IDs, an input builder and output encoder. The adapter automatically records a scoped observation of the session-state resource, constructs a fresh ADK session from the captured state, runs a single ADK invocation, validates the ADK session state, and submits the output through Co2's atomic API. INVOCATION_LEVEL is the default.

For trusted structured declarations, include session_ref(agent); omitting the observed session resource triggers OBSERVED_OMISSION_FALLBACK. LLM_FALLBACK and RUNTIME_OBSERVED_FALLBACK still retain the full captured set. No assurance of isolation is inferred from state inspection.

plan and reuse query the existing Co2 authority; the adapter does not compute invalidation or schedule work. Stale probabilistic computations block by default and need PlanPolicy(allow_probabilistic_recomputation=True). The lending host calls validate_snapshot at quiescent boundaries, inspects the plan, reuses credit and explicitly invokes eligibility and recommendation. Its mock counts are eligibility 2, credit 1, recommendation 2, plus 1 late-result probe; no human approval or funding operation is executed.

Handle state and failures

ADK sessions contain event history as well as state. This adapter intentionally creates a new ADK session per attempt; it does not restore or reuse an earlier ADK conversation, provider context, ADK memory service, checkpoint, persisted session or event history. Hosts needing any of those capabilities must supply/version the complete accessible context through an independently designed boundary. A new adapter cannot attach to an earlier adapter's namespace. There is no cross-process or durable recovery.

validate_snapshot(session_id, artifacts) compares a complete host artifact mapping with the current Co2 plan and checks that the corresponding ADK sessions still exist with the state snapshots recorded at their completed runs. It deliberately accepts current but stale artifacts for planning. It rejects foreign, missing, superseded or inconsistent mappings and detected session-state mutations; it does not restore state or validate a session's entire event history.

Call it at a quiescent boundary before relying on an ADK/Co2 snapshot. reuse itself checks Co2 validity, not the separate ADK service. ADK state checks and Co2 commit are not one atomic operation, so hosts must prevent out-of-band ADK mutations and cannot rely on a check to fence later changes.

A commit followed by host failure before its artifact binding is retained requires explicit reconciliation; it is not safe automatic recovery.

register_resource and register_session_state are separate updates; the host must provide ordered, accurate source versions and bind actual values to versions. Neither ADK nor Co2 can detect an unreported source change, a mislabeled version, hidden model/provider state, omitted input or external mutation. A user can mutate the exposed session service, agent, callback or model outside this cooperative boundary; state validation is not a sandbox.

Do not mutate an agent configuration during a run. Failed/cancelled runs abandon their captured Co2 attempt and delete their fresh ADK session. Completed sessions and the version/content ledger require the explicit lifecycle/capacity controls below.

ADK state and Co2 publication are not one durable transaction.

The supported boundary is one non-streaming, tool-free, callback-free LlmAgent invocation, with no subagents, planner, code executor, SDK retries, state-delta output, long-running tools, or configured tools. Unexpected errors, state changes, tool calls, multiple final events or missing final output are rejected before artifact publication. The host must still classify and control arbitrary custom model, input-builder and output-encoder code; this adapter cannot stop effects executed outside it.

Co2 never automatically repeats side effects: human decisions require revalidation and irreversible work escalates, but a host can ignore a plan. Sync Co2 API calls briefly occupy the calling event-loop thread; shared authority operations serialize on the Rust mutex.

Google documents session/state scopes and the ADK runtime; those APIs can evolve. Current documentation may describe versions newer than the pinned integration.

Lifecycle

Failed/cancelled calls abandon their captured Co2 invocation and delete their fresh ADK session. await adapter.collect_sessions(session_id) deletes superseded completed sessions at an explicit quiescent boundary; current sessions remain available for validation. Optional max_sessions, max_session_versions and max_session_state_bytes reject growth beyond their limits. The version/content ledger remains to reject version relabelling after cleanup; it cannot be discarded safely. See lifecycle guide. Core collection does not operate external session managers or framework checkpoints.

Example outcome

The default synthetic workflow records eligibility 2, credit 1, recommendation 2, plus a separate deliberately late attempt. These are executed mock-boundary counts, not billing or live-provider performance measurements. Credit retains its artifact; replacements get new attempt/artifact identities. Stale approval requires REVALIDATE; irreversible funding requires ESCALATE and funding execution stays zero. The host explicitly enables probabilistic recomputation for the reasoning demonstration. Without that policy, stale reasoning blocks.

Check versions, complete accessible context, output schema and current artifact bindings before using results. Session IDs correlate process-local state; they are not authorization credentials. Rejected late results need fresh current context and new identities when eligible. A source update after a successful check can still occur; no adapter locks external source systems. See execution semantics, failure handling and lifecycle cleanup.