Skip to content

Commit a43600e

Browse files
ADK: Allow overriding summary for Agents without overriding the start to close timeout (#1370)
* Allow overriding summary for agents without overriding the start to close timeout * Add test and change activity_options name --------- Co-authored-by: Tim Conley <timothy.conley@temporal.io> Co-authored-by: tconley1428 <tconley1428@gmail.com>
1 parent bb44cb8 commit a43600e

3 files changed

Lines changed: 27 additions & 8 deletions

File tree

temporalio/contrib/google_adk_agents/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,14 @@ Model calls are intercepted and executed as Temporal activities with configurabl
7171
**Agent (Workflow) Side:**
7272
```python
7373
from temporalio.contrib.google_adk_agents import TemporalModel
74+
from temporalio.workflow import ActivityConfig
7475
from google.adk import Agent
7576

7677

7778
# Add to agent
7879
agent = Agent(
7980
name="test_agent",
80-
model=TemporalModel("gemini-2.5-pro"),
81+
model=TemporalModel("gemini-2.5-pro", activity_config=ActivityConfig(summary="Researcher Agent")),
8182
)
8283
```
8384

temporalio/contrib/google_adk_agents/_model.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,21 @@ class TemporalModel(BaseLlm):
3939
"""A Temporal-based LLM model that executes model invocations as activities."""
4040

4141
def __init__(
42-
self, model_name: str, activity_options: ActivityConfig | None = None
42+
self, model_name: str, activity_config: ActivityConfig | None = None
4343
) -> None:
4444
"""Initialize the TemporalModel.
4545
4646
Args:
4747
model_name: The name of the model to use.
48-
activity_options: Configuration options for the activity execution.
48+
activity_config: Configuration options for the activity execution.
4949
"""
5050
super().__init__(model=model_name)
5151
self._model_name = model_name
52-
self._activity_options = activity_options or ActivityConfig(
52+
self._activity_config = ActivityConfig(
5353
start_to_close_timeout=timedelta(seconds=60)
5454
)
55+
if activity_config:
56+
self._activity_config.update(activity_config)
5557

5658
async def generate_content_async(
5759
self, llm_request: LlmRequest, stream: bool = False
@@ -68,7 +70,7 @@ async def generate_content_async(
6870
responses = await workflow.execute_activity(
6971
invoke_model,
7072
args=[llm_request],
71-
**self._activity_options,
73+
**self._activity_config,
7274
)
7375
for response in responses:
7476
yield response

tests/contrib/google_adk_agents/test_google_adk_agents.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
)
5353
from temporalio.contrib.opentelemetry import OpenTelemetryPlugin, create_tracer_provider
5454
from temporalio.worker import Worker
55+
from temporalio.workflow import ActivityConfig
5556
from tests.contrib.opentelemetry.test_opentelemetry import dump_spans
5657

5758
logger = logging.getLogger(__name__)
@@ -128,21 +129,31 @@ async def run(self, topic: str, model_name: str) -> str | None:
128129
# Sub-agent: Researcher
129130
researcher = LlmAgent(
130131
name="researcher",
131-
model=TemporalModel(model_name),
132+
model=TemporalModel(
133+
model_name, activity_config=ActivityConfig(summary="Researcher Agent")
134+
),
132135
instruction="You are a researcher. Find information about the topic.",
133136
)
134137

135138
# Sub-agent: Writer
136139
writer = LlmAgent(
137140
name="writer",
138-
model=TemporalModel(model_name),
141+
model=TemporalModel(
142+
model_name, activity_config=ActivityConfig(summary="Writer Agent")
143+
),
139144
instruction="You are a poet. Write a haiku based on the research.",
140145
)
141146

142147
# Root Agent: Coordinator
143148
coordinator = LlmAgent(
144149
name="coordinator",
145-
model=TemporalModel(model_name),
150+
model=TemporalModel(
151+
model_name,
152+
activity_config=ActivityConfig(
153+
start_to_close_timeout=timedelta(seconds=30),
154+
summary="Coordinator Agent",
155+
),
156+
),
146157
instruction="You are a coordinator. Delegate to researcher then writer.",
147158
sub_agents=[researcher, writer],
148159
)
@@ -551,3 +562,8 @@ async def test_single_agent_telemetry(client: Client):
551562
" StartActivity:invoke_model",
552563
" RunActivity:invoke_model",
553564
]
565+
566+
567+
async def test_unsetting_timeout():
568+
model = TemporalModel("", ActivityConfig(start_to_close_timeout=None))
569+
assert model._activity_config.get("start_to_close_timeout", None) is None

0 commit comments

Comments
 (0)