Skip to content

Commit b2614ab

Browse files
Fix content type extraction in temporal state machine tutorials
- Add safe content extraction patterns for TaskMessageContent unions - Replace direct .content access with hasattr/getattr patterns - Addresses str | List[str] | Unknown | object | None type errors
1 parent 0981979 commit b2614ab

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

examples/tutorials/10_agentic/10_temporal/020_state_machine/project/workflow.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ async def on_task_event_send(self, params: SendEventParams) -> None:
7272
# Check if we're in the middle of follow-up questions
7373
if deep_research_data.n_follow_up_questions_to_ask > 0:
7474
# User is responding to a follow-up question
75-
deep_research_data.follow_up_responses.append(message.content)
75+
# Safely extract content from message
76+
content_text = ""
77+
if hasattr(message, 'content'):
78+
content_val = getattr(message, 'content', '')
79+
if isinstance(content_val, str):
80+
content_text = content_val
81+
deep_research_data.follow_up_responses.append(content_text)
7682

7783
# Add the Q&A to the agent input list as context
7884
if deep_research_data.follow_up_questions:
@@ -115,11 +121,18 @@ async def on_task_event_send(self, params: SendEventParams) -> None:
115121
await self.state_machine.transition(DeepResearchState.CLARIFYING_USER_QUERY)
116122

117123
# Echo back the user's message
124+
# Safely extract content from message for display
125+
message_content = ""
126+
if hasattr(message, 'content'):
127+
content_val = getattr(message, 'content', '')
128+
if isinstance(content_val, str):
129+
message_content = content_val
130+
118131
await adk.messages.create(
119132
task_id=task.id,
120133
content=TextContent(
121134
author="user",
122-
content=message.content,
135+
content=message_content,
123136
),
124137
trace_id=task.id,
125138
parent_span_id=deep_research_data.current_span.id if deep_research_data.current_span else None,

examples/tutorials/10_agentic/10_temporal/020_state_machine/project/workflows/deep_research/clarify_user_query.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ async def execute(self, state_machine: StateMachine, state_machine_data: Optiona
6868
trace_id=state_machine_data.task_id,
6969
parent_span_id=state_machine_data.current_span.id,
7070
)
71-
follow_up_question = task_message.content.content
71+
# Safely extract content from task message
72+
follow_up_question = ""
73+
if task_message.content and hasattr(task_message.content, 'content'):
74+
content_val = getattr(task_message.content, 'content', '')
75+
if isinstance(content_val, str):
76+
follow_up_question = content_val
7277

7378
# Update with follow-up question
7479
state_machine_data.follow_up_questions.append(follow_up_question)

0 commit comments

Comments
 (0)