Skip to content

Commit 3c2a6b1

Browse files
fix context contuinuiation
1 parent 9e6f785 commit 3c2a6b1

File tree

5 files changed

+528
-383
lines changed

5 files changed

+528
-383
lines changed

examples/tutorials/10_async/10_temporal/090_claude_agents_sdk_mvp/project/workflow.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ async def on_task_event_send(self, params: SendEventParams):
148148

149149
# Run Claude via activity (manual wrapper for MVP)
150150
# ContextInterceptor reads _task_id, _trace_id, _parent_span_id and threads to activity!
151+
logger.info(f"[WORKFLOW] About to call activity with resume_session_id={self._state.claude_session_id}")
152+
151153
result = await workflow.execute_activity(
152154
run_claude_agent_activity,
153155
args=[
@@ -168,7 +170,14 @@ async def on_task_event_send(self, params: SendEventParams):
168170
),
169171
)
170172

171-
logger.info(f"Claude activity completed: {len(result.get('messages', []))} messages")
173+
logger.info(f"[WORKFLOW] ✅ Claude activity returned successfully!")
174+
logger.info(f"[WORKFLOW] Result type: {type(result)}")
175+
logger.info(f"[WORKFLOW] Result: {result}")
176+
logger.info(f"[WORKFLOW] Claude activity completed: {len(result.get('messages', []))} messages")
177+
178+
# DEBUG: Check what we got back
179+
logger.info(f"DEBUG: result keys = {result.keys()}")
180+
logger.info(f"DEBUG: session_id from result = {result.get('session_id')}")
172181

173182
# Update session_id for next turn (maintains conversation context)
174183
new_session_id = result.get("session_id")
@@ -179,6 +188,8 @@ async def on_task_event_send(self, params: SendEventParams):
179188
f"session_id={'STARTED' if self._state.turn_number == 1 else 'CONTINUED'} "
180189
f"({new_session_id[:16]}...)"
181190
)
191+
else:
192+
logger.error(f"DEBUG: NO session_id in result! Current state session_id={self._state.claude_session_id}")
182193

183194
# Send Claude's response back to user
184195
# Note: Activity should have streamed the response in real-time
@@ -219,7 +230,7 @@ async def on_task_event_send(self, params: SendEventParams):
219230
)
220231

221232
except Exception as e:
222-
logger.error(f"Error running Claude agent: {e}", exc_info=True)
233+
logger.error(f"[WORKFLOW] Error running Claude agent: {e}", exc_info=True)
223234
# Send error message to user
224235
await adk.messages.create(
225236
task_id=params.task.id,
@@ -228,6 +239,7 @@ async def on_task_event_send(self, params: SendEventParams):
228239
content=f"❌ Error: {str(e)}",
229240
)
230241
)
242+
raise # Re-raise to see in Temporal UI
231243

232244
@workflow.run
233245
async def on_task_create(self, params: CreateTaskParams):

0 commit comments

Comments
 (0)