Skip to content

Commit d50158d

Browse files
tconley1428marcusmotillchris-olszewski
authored
Add Google ADK Agents integration for Temporal workflows (#1353)
* add google adk plugins * Update with dev dependency and some cleanup * Fix copy paste error string * Add replay validation and local model validation * Work in progress mcp support * Fix linting errors * Added support and test for using otel exporter in adk integration * Linting * Update tests and explicit activity config types * Fixing tests to do test models differently * Update readme * Update to use a model wrapper instead of a plugin. Preserves llm call telemetry. * Remove unused file * Linting * Update with latest adk changes * Update readme * Use inmemoryrunner in a test to validate * Update dependency to ADK main * Fix telemetry assertion * Add execution timeout to improve CI debugging * Disable MCP for now * Formatting * Fix pydoctor errors, don't include extras in proto 3 validation * Extend latest deps timeout * Remove adk dependency for proto validation * Missed hypen * Skip google tests in proto validation * Update temporalio/contrib/google_adk_agents/_plugin.py Co-authored-by: Chris Olszewski <chrisdolszewski@gmail.com> * PR updates and released dependency * Fix task queue names --------- Co-authored-by: Marcus Motill <marcusmotill@google.com> Co-authored-by: Chris Olszewski <chrisdolszewski@gmail.com>
1 parent f4a43ca commit d50158d

13 files changed

Lines changed: 3587 additions & 9 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@ jobs:
104104
env:
105105
TEMPORAL_TEST_PROTO3: 1
106106
run: |
107+
uv remove google-adk --optional google-adk
107108
uv add --python 3.10 "protobuf<4"
108109
uv sync --all-extras
109110
poe build-develop
110111
poe gen-protos
111112
[[ -z $(git status --porcelain temporalio) ]] || (git diff temporalio; echo "Protos changed"; exit 1)
112-
poe test -s
113+
poe test -s --ignore=tests/contrib/google_adk_agents/
113114
timeout-minutes: 10
114115

115116
# Do docs stuff (only on one host)

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ grpc = ["grpcio>=1.48.2,<2"]
2929
opentelemetry = ["opentelemetry-api>=1.11.1,<2", "opentelemetry-sdk>=1.11.1,<2"]
3030
pydantic = ["pydantic>=2.0.0,<3"]
3131
openai-agents = ["openai-agents>=0.3,<0.7", "mcp>=1.9.4, <2"]
32+
google-adk = ["google-adk>=1.27.0,<2"]
3233

3334
[project.urls]
3435
Homepage = "https://github.com/temporalio/sdk-python"
@@ -60,6 +61,7 @@ dev = [
6061
"pytest-pretty>=1.3.0",
6162
"openai-agents>=0.3,<0.7; python_version >= '3.14'",
6263
"openai-agents[litellm]>=0.3,<0.7; python_version < '3.14'",
64+
"openinference-instrumentation-google-adk>=0.1.8",
6365
"googleapis-common-protos==1.70.0",
6466
"pytest-rerunfailures>=16.1",
6567
]
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Google ADK Agents SDK Integration for Temporal
2+
3+
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.
4+
5+
## Benefits of Temporal to the ADK
6+
7+
Temporal provides a holistic, unified solution that centralizes your orchestration needs in one Workflow abstraction. Rather than cobbling together separate servers, task queues, gateways, and databases, you get:
8+
9+
- **Recovering from crashes and stalls automatically**, rather than manually managing [sessions](https://google.github.io/adk-docs/sessions/session/#example-examining-session-properties) and [resuming](https://google.github.io/adk-docs/runtime/resume/#resume-a-stopped-workflow) them. (Google offers [Vertex Agent Engine](https://docs.cloud.google.com/agent-builder/agent-engine/sessions/manage-sessions-adk), which still leaves resumption to the user). No need to set up a separate [database](https://dev.to/greyisheepai/mastering-google-adk-databasesessionservice-and-events-complete-guide-to-event-injection-and-pdm#understanding-adk-databasesessionservice)
10+
- Along with [Retries](https://docs.temporal.io/encyclopedia/retry-policies) and mechanisms for handling backpressure and rate limits.
11+
- **Support for [ambient](https://temporal.io/blog/orchestrating-ambient-agents-with-temporal)/long-running agent patterns** via blocking awaits and [worker versioning](https://docs.temporal.io/production-deployment/worker-deployments/worker-versioning).
12+
- **Automatic execution state [persistence](https://docs.temporal.io/temporal-service/persistence)**, not just for agent interactions but for any custom automations in your workflows, without setting up a separate [database](https://dev.to/greyisheepai/mastering-google-adk-databasesessionservice-and-events-complete-guide-to-event-injection-and-pdm#understanding-adk-databasesessionservice).
13+
- For **Human-in-the-Loop patterns,** an api gateway to scalably [route](https://docs.temporal.io/task-routing) incoming messages (such as user chats) to awaken the correct workflow on your worker pool.
14+
- [**Long-running tools](https://google.github.io/adk-docs/tools-custom/function-tools/#long-run-tool) support** using [Activities](https://docs.temporal.io/activities) — no need to set up and maintain microservices.
15+
- [Manage and debug your agent workflow](https://temporal.io/resources/on-demand/demo-ai-agent) execution and pinpoint problems using Temporal UI.
16+
17+
## Benefits of the ADK to Temporal
18+
19+
ADK provides: (from the [ADK overview](https://google.github.io/adk-docs/#learn-more)):
20+
21+
- Improved Agent development velocity with a first-class Agentic abstraction and integration with LLMs and an ecosystem of tools.
22+
- Improved agent robustness using built-in evals
23+
- Build complex agents using its Multi-agent architecture.
24+
- [Safety and security](https://google.github.io/adk-docs/safety/), via guardrails and integrations with sandboxing solutions like Vertex Agent Runtime.
25+
26+
## What's Included
27+
28+
### Core ADK Integration
29+
- **`TemporalModel`**: Intercepts model calls and executes them as Temporal activities
30+
- **`GoogleAdkPlugin`**: Worker plugin that configures runtime determinism and Pydantic serialization
31+
- **`invoke_model`**: Activity for executing LLM model calls with proper error handling
32+
33+
### MCP (Model Context Protocol) Integration
34+
- **`TemporalMcpToolSet`**: Executes MCP tools as Temporal activities
35+
- **`TemporalMcpToolSetProvider`**: Manages toolset creation and activity registration
36+
- Full support for tool confirmation and event actions within workflows
37+
38+
### OpenTelemetry Integration
39+
- Automatic instrumentation for ADK components when exporters are provided
40+
- Tracing integration that works within Temporal's execution context
41+
- Support for custom span exporters
42+
43+
### Key Features
44+
45+
#### 1. Deterministic Runtime
46+
- Replaces `time.time()` with `workflow.now()` when in workflow context
47+
- Replaces `uuid.uuid4()` with `workflow.uuid4()` for deterministic IDs
48+
- Automatic setup when using `GoogleAdkPlugin`
49+
50+
#### 2. Activity-Based Model Execution
51+
Model calls are intercepted and executed as Temporal activities with configurable:
52+
- Timeouts (schedule-to-close, start-to-close, heartbeat)
53+
- Retry policies
54+
- Task queues
55+
- Cancellation behavior
56+
- Priority levels
57+
58+
#### 3. Sandbox Compatibility
59+
- Automatic passthrough for `google.adk`, `google.genai`, and `mcp` modules
60+
- Works with both sandboxed and unsandboxed workflow runners
61+
62+
#### 4. Advanced Serialization
63+
- Pydantic payload converter for ADK objects
64+
- Proper handling of complex ADK data types
65+
- Maintains type safety across workflow boundaries
66+
67+
## Usage
68+
69+
### Basic Setup
70+
71+
**Agent (Workflow) Side:**
72+
```python
73+
from temporalio.contrib.google_adk_agents import TemporalModel
74+
from google.adk import Agent
75+
76+
77+
# Add to agent
78+
agent = Agent(
79+
name="test_agent",
80+
model=TemporalModel("gemini-2.5-pro"),
81+
)
82+
```
83+
84+
**Worker Side:**
85+
86+
```python
87+
from temporalio.client import Client
88+
from temporalio.worker import Worker
89+
from temporalio.contrib.google_adk_agents import GoogleAdkPlugin
90+
91+
client = await Client.connect(
92+
"localhost:7233",
93+
plugins=[
94+
GoogleAdkPlugin(),
95+
],
96+
)
97+
98+
worker = Worker(
99+
client,
100+
task_queue="my-queue",
101+
)
102+
```
103+
104+
### Advanced Features
105+
106+
**With MCP Tools:**
107+
108+
```python
109+
import os
110+
from google.adk import Agent
111+
from google.adk.tools.mcp_tool import McpToolset
112+
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
113+
from mcp import StdioServerParameters
114+
from temporalio.client import Client
115+
from temporalio.worker import Worker
116+
117+
from temporalio.contrib.google_adk_agents import (
118+
GoogleAdkPlugin,
119+
TemporalMcpToolSetProvider,
120+
TemporalMcpToolSet
121+
)
122+
123+
# Create toolset provider
124+
provider = TemporalMcpToolSetProvider("my-tools",
125+
lambda _: McpToolset(
126+
connection_params=StdioConnectionParams(
127+
server_params=StdioServerParameters(
128+
command="npx",
129+
args=[
130+
"-y",
131+
"@modelcontextprotocol/server-filesystem",
132+
os.path.dirname(os.path.abspath(__file__)),
133+
],
134+
),
135+
),
136+
))
137+
138+
# Use in agent workflow
139+
agent = Agent(
140+
name="test_agent",
141+
model="gemini-2.5-pro",
142+
tools=[TemporalMcpToolSet("my-tools")]
143+
)
144+
145+
client = await Client.connect(
146+
"localhost:7233",
147+
plugins=[
148+
GoogleAdkPlugin(toolset_providers=[provider]),
149+
],
150+
)
151+
152+
# Configure worker
153+
worker = Worker(
154+
client,
155+
task_queue="task-queue"
156+
)
157+
```
158+
159+
## Integration Points
160+
161+
This integration provides comprehensive support for running Google ADK Agents within Temporal workflows while maintaining:
162+
- **Determinism**: All non-deterministic operations are routed through Temporal
163+
- **Observability**: Full tracing and activity visibility
164+
- **Reliability**: Proper retry handling and error propagation
165+
- **Extensibility**: Support for custom tools via MCP protocol
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""Temporal Integration for ADK.
2+
3+
This module provides the necessary components to run ADK Agents within Temporal Workflows.
4+
"""
5+
6+
from temporalio.contrib.google_adk_agents._mcp import (
7+
TemporalMcpToolSet,
8+
TemporalMcpToolSetProvider,
9+
)
10+
from temporalio.contrib.google_adk_agents._model import TemporalModel
11+
from temporalio.contrib.google_adk_agents._plugin import (
12+
GoogleAdkPlugin,
13+
)
14+
15+
__all__ = [
16+
"GoogleAdkPlugin",
17+
"TemporalMcpToolSet",
18+
"TemporalMcpToolSetProvider",
19+
"TemporalModel",
20+
]

0 commit comments

Comments
 (0)