-
Notifications
You must be signed in to change notification settings - Fork 164
Add Google ADK Agents integration for Temporal workflows #1353
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
Changes from all commits
b862834
2cf6808
dbf35b2
1f534ab
a04b109
6dd1b77
ad18ee8
8aa2647
18e4400
117ebdc
bd5cef5
493e7bb
d159549
d230423
8dce0bb
2df0244
9be0754
92fc584
dc72bc7
22badb8
59d5a98
2706809
6b0ee98
552cf5e
e1579b2
52aada5
9971195
17c0f15
14e0ac6
b4be00a
7de1cba
d76a2a5
9ff8938
193b893
60b3130
b33a005
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| # 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. | ||
tconley1428 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Benefits of Temporal to the ADK | ||
|
|
||
| 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: | ||
|
|
||
| - **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) | ||
| - Along with [Retries](https://docs.temporal.io/encyclopedia/retry-policies) and mechanisms for handling backpressure and rate limits. | ||
| - **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). | ||
| - **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). | ||
| - 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. | ||
| - [**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. | ||
| - [Manage and debug your agent workflow](https://temporal.io/resources/on-demand/demo-ai-agent) execution and pinpoint problems using Temporal UI. | ||
|
|
||
| ## Benefits of the ADK to Temporal | ||
|
|
||
| ADK provides: (from the [ADK overview](https://google.github.io/adk-docs/#learn-more)): | ||
|
|
||
| - Improved Agent development velocity with a first-class Agentic abstraction and integration with LLMs and an ecosystem of tools. | ||
| - Improved agent robustness using built-in evals | ||
| - Build complex agents using its Multi-agent architecture. | ||
| - [Safety and security](https://google.github.io/adk-docs/safety/), via guardrails and integrations with sandboxing solutions like Vertex Agent Runtime. | ||
|
|
||
| ## What's Included | ||
|
|
||
| ### Core ADK Integration | ||
| - **`TemporalModel`**: Intercepts model calls and executes them as Temporal activities | ||
| - **`GoogleAdkPlugin`**: 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 `GoogleAdkPlugin` | ||
|
|
||
| #### 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:** | ||
| ```python | ||
| from temporalio.contrib.google_adk_agents import TemporalModel | ||
| from google.adk import Agent | ||
|
|
||
|
|
||
| # Add to agent | ||
| agent = Agent( | ||
| name="test_agent", | ||
| model=TemporalModel("gemini-2.5-pro"), | ||
| ) | ||
| ``` | ||
|
|
||
| **Worker Side:** | ||
|
|
||
| ```python | ||
| from temporalio.client import Client | ||
| from temporalio.worker import Worker | ||
| from temporalio.contrib.google_adk_agents import GoogleAdkPlugin | ||
|
|
||
| client = await Client.connect( | ||
| "localhost:7233", | ||
| plugins=[ | ||
| GoogleAdkPlugin(), | ||
| ], | ||
| ) | ||
|
|
||
| worker = Worker( | ||
| client, | ||
| task_queue="my-queue", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to list a workflow and maybe activities.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's really just demonstrating the registration of the plugin, I don't think it's necessary to make up a workflow to put in. Activities certainly not required. |
||
| ) | ||
| ``` | ||
|
|
||
| ### Advanced Features | ||
|
|
||
| **With MCP Tools:** | ||
|
|
||
| ```python | ||
| import os | ||
| from google.adk import Agent | ||
| from google.adk.tools.mcp_tool import McpToolset | ||
| from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams | ||
| from mcp import StdioServerParameters | ||
| from temporalio.client import Client | ||
| from temporalio.worker import Worker | ||
|
|
||
| from temporalio.contrib.google_adk_agents import ( | ||
| GoogleAdkPlugin, | ||
| TemporalMcpToolSetProvider, | ||
| TemporalMcpToolSet | ||
| ) | ||
|
|
||
| # Create toolset provider | ||
| provider = TemporalMcpToolSetProvider("my-tools", | ||
| lambda _: McpToolset( | ||
| connection_params=StdioConnectionParams( | ||
| server_params=StdioServerParameters( | ||
| command="npx", | ||
| args=[ | ||
| "-y", | ||
| "@modelcontextprotocol/server-filesystem", | ||
| os.path.dirname(os.path.abspath(__file__)), | ||
| ], | ||
| ), | ||
| ), | ||
| )) | ||
|
|
||
| # Use in agent workflow | ||
| agent = Agent( | ||
| name="test_agent", | ||
| model="gemini-2.5-pro", | ||
| tools=[TemporalMcpToolSet("my-tools")] | ||
| ) | ||
|
|
||
| client = await Client.connect( | ||
| "localhost:7233", | ||
| plugins=[ | ||
| GoogleAdkPlugin(toolset_providers=[provider]), | ||
| ], | ||
| ) | ||
|
|
||
| # Configure worker | ||
| worker = Worker( | ||
| client, | ||
| task_queue="task-queue" | ||
| ) | ||
| ``` | ||
|
|
||
| ## 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| """Temporal Integration for ADK. | ||
|
|
||
| This module provides the necessary components to run ADK Agents within Temporal Workflows. | ||
| """ | ||
|
|
||
| from temporalio.contrib.google_adk_agents._mcp import ( | ||
| TemporalMcpToolSet, | ||
| TemporalMcpToolSetProvider, | ||
| ) | ||
| from temporalio.contrib.google_adk_agents._model import TemporalModel | ||
| from temporalio.contrib.google_adk_agents._plugin import ( | ||
| GoogleAdkPlugin, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "GoogleAdkPlugin", | ||
| "TemporalMcpToolSet", | ||
| "TemporalMcpToolSetProvider", | ||
| "TemporalModel", | ||
| ] |
Uh oh!
There was an error while loading. Please reload this page.