Skip to content

Commit 1a63985

Browse files
committed
fix(temporal): Use robust argument binding and remove unused variable
1 parent 81a5935 commit 1a63985

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

src/google/adk/integrations/temporal.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Temporal integration helpers for ADK."""
1616

1717
import functools
18+
import inspect
1819
from typing import Any, AsyncGenerator, Callable, Optional, List
1920

2021
from temporalio import workflow, activity
@@ -39,17 +40,21 @@ def activity_as_tool(
3940

4041
# We create a wrapper that delegates to workflow.execute_activity
4142
async def tool_wrapper(*args, **kwargs) -> Any:
42-
# Note: ADK tools usually pass args/kwargs strictly matched to signature.
43-
# Activities expect positional args in a list if 'args' is used.
44-
# If the tool signature matches the activity signature, we can pass args.
45-
# It's safer if activity takes Pydantic models or simple types.
46-
47-
# We assume strict positional argument mapping for now, or simplistic kwargs handling if supported.
48-
# Temporal Python SDK typically invokes activities with `args=[...]`.
49-
43+
# Bind arguments to the activity signature to ensure correct order/mapping.
44+
try:
45+
sig = inspect.signature(activity_def)
46+
bound_args = sig.bind(*args, **kwargs)
47+
bound_args.apply_defaults()
48+
activity_args = [bound_args.arguments[p] for p in sig.parameters]
49+
except (TypeError, ValueError):
50+
# Fallback for built-ins or other complex callables where binding may fail
51+
# or if arguments don't match signature (e.g. simpler invocation).
52+
# Temporal Python SDK typically invokes activities with `args=[...]`.
53+
activity_args = list(args) + list(kwargs.values()) if kwargs else list(args)
54+
5055
return await workflow.execute_activity(
5156
activity_def,
52-
args=list(args) + list(kwargs.values()) if kwargs else list(args),
57+
args=activity_args,
5358
**activity_options
5459
)
5560

@@ -64,7 +69,6 @@ async def tool_wrapper(*args, **kwargs) -> Any:
6469

6570
# CRITICAL: Copy signature so FunctionTool can generate correct parameters schema
6671
try:
67-
import inspect
6872
tool_wrapper.__signature__ = inspect.signature(activity_def)
6973
except Exception:
7074
pass # Fallback if signature copy fails (e.g. builtins)

tests/integration/manual_test_temporal_integration.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,13 @@ async def run(self, prompt: str) -> str:
221221
# Turn 2: Trigger Handoff
222222
logger.info("--- Turn 2: Trigger Handoff ---")
223223
handoff_response_text = ""
224-
last_author = ""
225224
async with Aclosing(runner.run_async(
226225
user_id=session.user_id,
227226
session_id=session.id,
228227
new_message=types.Content(role='user', parts=[types.Part(text="Please switch me to the specialist.")])
229228
)) as agen:
230229
async for event in agen:
231230
logger.info(f"Event Author: {event.author} | Actions: {event.actions}")
232-
last_author = event.author
233231
if event.content and event.content.parts:
234232
for part in event.content.parts:
235233
if part.text: handoff_response_text += part.text

0 commit comments

Comments
 (0)