Skip to content

feat: add google adk plugins#1282

Draft
marcusmotill wants to merge 20 commits intotemporalio:mainfrom
marcusmotill:motill/adk_plugin
Draft

feat: add google adk plugins#1282
marcusmotill wants to merge 20 commits intotemporalio:mainfrom
marcusmotill:motill/adk_plugin

Conversation

@marcusmotill
Copy link

@marcusmotill marcusmotill commented Jan 19, 2026

Google ADK Agents SDK Integration for Temporal

This package provides the integration layer between the Google ADK and Temporal. It allows ADK Agents to run reliably within Temporal Workflows by ensuring determinism and correctly routing external calls (network I/O) through Temporal Activities.

What's Included

Core ADK Integration

  • AdkAgentPlugin: Intercepts model calls and executes them as Temporal activities
  • TemporalAdkPlugin: Worker plugin that configures runtime determinism and Pydantic serialization
  • invoke_model: Activity for executing LLM model calls with proper error handling

MCP (Model Context Protocol) Integration

  • TemporalMcpToolSet: Executes MCP tools as Temporal activities
  • TemporalMcpToolSetProvider: Manages toolset creation and activity registration
  • Full support for tool confirmation and event actions within workflows

OpenTelemetry Integration

  • Automatic instrumentation for ADK components when exporters are provided
  • Tracing integration that works within Temporal's execution context
  • Support for custom span exporters

Key Features

1. Deterministic Runtime

  • Replaces time.time() with workflow.now() when in workflow context
  • Replaces uuid.uuid4() with workflow.uuid4() for deterministic IDs
  • Automatic setup when using TemporalAdkPlugin

2. Activity-Based Model Execution

Model calls are intercepted and executed as Temporal activities with configurable:

  • Timeouts (schedule-to-close, start-to-close, heartbeat)
  • Retry policies
  • Task queues
  • Cancellation behavior
  • Priority levels

3. Sandbox Compatibility

  • Automatic passthrough for google.adk, google.genai, and mcp modules
  • Works with both sandboxed and unsandboxed workflow runners

4. Advanced Serialization

  • Pydantic payload converter for ADK objects
  • Proper handling of complex ADK data types
  • Maintains type safety across workflow boundaries

Usage

Basic Setup

Agent (Workflow) Side:

from temporalio.contrib.google_adk_agents import AdkAgentPlugin, ModelActivityParameters
from datetime import timedelta

# Configure activity parameters
activity_params = ModelActivityParameters(
    start_to_close_timeout=timedelta(minutes=1),
    retry_policy=RetryPolicy(maximum_attempts=3)
)

# Add to agent
agent = Agent(
    model="gemini-2.5-pro", 
    plugins=[AdkAgentPlugin(activity_params)]
)

Worker Side:

from temporalio.contrib.google_adk_agents import TemporalAdkPlugin

worker = Worker(
    client,
    task_queue="my-queue",
    plugins=[TemporalAdkPlugin()]
)

Advanced Features

With MCP Tools:

from temporalio.contrib.google_adk_agents import (
    TemporalAdkPlugin, 
    TemporalMcpToolSetProvider,
    TemporalMcpToolSet
)

# Create toolset provider
provider = TemporalMcpToolSetProvider("my-tools", my_toolset_factory)

# Use in agent workflow
agent = Agent(
    model="gemini-2.5-pro",
    toolsets=[TemporalMcpToolSet("my-tools")]
)

# Configure worker
worker = Worker(
    client,
    plugins=[TemporalAdkPlugin(toolset_providers=[provider])]
)

With OpenTelemetry:

from opentelemetry.exporter.jaeger.thrift import JaegerExporter

exporter = JaegerExporter(endpoint="http://localhost:14268/api/traces")
plugin = TemporalAdkPlugin(otel_exporters=[exporter])

Integration Points

This integration provides comprehensive support for running Google ADK Agents within Temporal workflows while maintaining:

  • Determinism: All non-deterministic operations are routed through Temporal
  • Observability: Full tracing and activity visibility
  • Reliability: Proper retry handling and error propagation
  • Extensibility: Support for custom tools via MCP protocol

@CLAassistant
Copy link

CLAassistant commented Jan 19, 2026

CLA assistant check
All committers have signed the CLA.

copybara-service bot pushed a commit to google/adk-python that referenced this pull request Mar 6, 2026
Merge #4200

**Problem:**
The current implementation of `SessionService`, `Event`, and other core components relies directly on `time.time()` and `uuid.uuid4()`. These standard library functions are non-deterministic, which prevents the ADK from being used in deterministic execution environments (like Temporal workflows). In such environments, logic that depends on time or random IDs must be replayable and consistent across executions.

**Solution:**
Introduced `google.adk.platform.time` and `google.adk.platform.uuid` modules to abstract time and UUID generation.
- Created `google.adk.platform.time` with `get_time()` and `set_time_provider()`.
- Created `google.adk.platform.uuid` with `new_uuid()` and `set_id_provider()`.
- Updated `Event`, `SessionService`, `InvocationContext`, and `SqliteSessionService` to use these new platform abstractions instead of `time` and `uuid` directly.

This allows runtimes to inject deterministic providers (e.g., Temporal's `workflow.now()` and side-effect-safe UUIDs) when running in a deterministic context, while defaulting to standard `time` and `uuid` for standard execution.

### Testing Plan

**Unit Tests:**

- [x] I have added or updated unit tests for my change.
- [x] All unit tests pass locally.

Added new unit tests for the platform modules:
- [tests/unittests/platform/test_time.py](cci:7://file:///usr/local/google/home/marcusmotill/Documents/code/temporal/adk-python-temporal/tests/unittests/platform/test_time.py:0:0-0:0): Verifies `get_time`, provider overriding, and resetting.
- [tests/unittests/platform/test_uuid.py](cci:7://file:///usr/local/google/home/marcusmotill/Documents/code/temporal/adk-python-temporal/tests/unittests/platform/test_uuid.py:0:0-0:0): Verifies `new_uuid`, provider overriding, and resetting.
- Updated [tests/unittests/artifacts/test_artifact_service.py](cci:7://file:///usr/local/google/home/marcusmotill/Documents/code/temporal/adk-python-temporal/tests/unittests/artifacts/test_artifact_service.py:0:0-0:0) to match the new patterns.

**Manual End-to-End (E2E) Tests:**

Verified that the ADK continues to function correctly in standard (non-deterministic) environments, ensuring the default providers for time and UUIDs work as expected.
- Ran existing agent workflows to confirm session creation and event logging still produce valid timestamps and IDs.

### Checklist

- [x] I have read the [CONTRIBUTING.md](https://github.com/google/adk-python/blob/main/CONTRIBUTING.md) document.
- [x] I have performed a self-review of my own code.
- [x] I have commented my code, particularly in hard-to-understand areas.
- [x] I have added tests that prove my fix is effective or that my feature works.
- [x] New and existing unit tests pass locally with my changes.
- [x] I have manually tested my changes end-to-end.
- [x] Any dependent changes have been merged and published in downstream modules.

### Additional context

These changes are a prerequisite for the [Temporal integration](temporalio/sdk-python#1282), allowing the ADK to run safely inside Temporal workflows without breaking determinism guarantees.

COPYBARA_INTEGRATE_REVIEW=#4200 from marcusmotill:motill/durable-support 61d0e31
PiperOrigin-RevId: 879662233
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.

3 participants