-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: Add Temporal integration and deterministic runtime support #3920
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @marcusmotill, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the ADK by integrating with Temporal workflows, thereby addressing critical challenges related to determinism and I/O traceability in AI agent execution. It achieves this by introducing a new runtime abstraction that provides deterministic time and UUID generation, alongside a suite of helper classes that seamlessly bridge ADK agents and tools with Temporal activities. This ensures that all agent actions, including LLM calls and tool executions, are durably recorded and replayable within the Temporal Event History, facilitating robust and observable AI applications. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Response from ADK Triaging Agent Hello @marcusmotill, thank you for creating this PR! Your PR is missing unit tests. Could you please add unit tests for your change? You can add or update tests under This information will help reviewers to review your PR more efficiently. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a significant and well-designed integration with Temporal to support deterministic execution of AI agents in workflows. The core of the change is the new runtime module, which correctly abstracts non-deterministic system calls like getting the time and generating UUIDs. The integration helpers in google.adk.integrations.temporal, such as TemporalModel and activity_as_tool, are powerful additions that make it much easier to run ADK agents within Temporal. The accompanying integration test is comprehensive and covers both single and multi-agent scenarios effectively.
My review includes a critical fix for argument handling when wrapping activities as tools to prevent potential bugs with keyword arguments, a suggestion to adhere to Python's import conventions, and a minor cleanup in the test code to remove an unused variable. Overall, this is an excellent contribution that greatly enhances the capabilities of the ADK.
c0fd751 to
1a63985
Compare
| # Wraps 'get_weather' activity as a Tool | ||
| weather_tool = TemporalPlugin.activity_tool( | ||
| get_weather, | ||
| start_to_close_timeout=timedelta(seconds=60) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the function ned to have @activity.defn like above? is the the best place for options?
ADK Temporal Integration Internals
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.
Core Concepts
1. Interception Flow (
AgentPlugin)The
AgentPluginacts as a middleware that intercepts model calls (e.g.,agent.generate_content) before they execute.Workflow Interception:
before_model_callbackwhen an agent attempts to call a model.workflow.execute_activity(), routing the request to Temporal for execution.This ensures that all model interactions are recorded in the Temporal Workflow history, enabling reliable replay and determinism.
2. Dynamic Activity Registration
To provide visibility in the Temporal UI, activities are dynamically named after the calling agent (e.g.,
MyAgent.generate_content). Since agent names are not known at startup, the integration uses Temporal's dynamic activity registration.When the workflow executes an activity with an unknown name (e.g.,
MyAgent.generate_content), the worker routes the call todynamic_activity. This handler inspects theactivity_typeand delegates execution to the appropriate internal logic (_handle_generate_content), enabling arbitrary activity names without explicit registration.3. Usage & Configuration
The integration requires setup on both the Agent (Workflow) side and the Worker side.
Agent Setup (Workflow Side)
Attach the
AgentPluginto your ADK agent. This safely routes model calls through Temporal activities. You must provide activity options (e.g., timeouts) as there are no defaults.Worker Setup
Install the
WorkerPluginon your Temporal Worker. This handles serialization and runtime determinism.What
WorkerPluginDoes:time.time,uuid.uuid4) before workflow execution.UnsandboxedWorkflowRunner, allowing standard imports in ADK agents.