Skip to content

Commit c872735

Browse files
logging cleanup
1 parent 3c2a6b1 commit c872735

File tree

3 files changed

+20
-36
lines changed

3 files changed

+20
-36
lines changed

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ 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-
153151
result = await workflow.execute_activity(
154152
run_claude_agent_activity,
155153
args=[
@@ -170,15 +168,6 @@ async def on_task_event_send(self, params: SendEventParams):
170168
),
171169
)
172170

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')}")
181-
182171
# Update session_id for next turn (maintains conversation context)
183172
new_session_id = result.get("session_id")
184173
if new_session_id:
@@ -189,7 +178,7 @@ async def on_task_event_send(self, params: SendEventParams):
189178
f"({new_session_id[:16]}...)"
190179
)
191180
else:
192-
logger.error(f"DEBUG: NO session_id in result! Current state session_id={self._state.claude_session_id}")
181+
logger.warning(f"No session_id returned - context may not persist")
193182

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

232221
except Exception as e:
233-
logger.error(f"[WORKFLOW] Error running Claude agent: {e}", exc_info=True)
222+
logger.error(f"Error running Claude agent: {e}", exc_info=True)
234223
# Send error message to user
235224
await adk.messages.create(
236225
task_id=params.task.id,
@@ -239,7 +228,7 @@ async def on_task_event_send(self, params: SendEventParams):
239228
content=f"❌ Error: {str(e)}",
240229
)
241230
)
242-
raise # Re-raise to see in Temporal UI
231+
raise
243232

244233
@workflow.run
245234
async def on_task_create(self, params: CreateTaskParams):

src/agentex/lib/core/temporal/plugins/claude_agents/activities.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ async def run_claude_agent_activity(
133133
async for message in client.receive_response():
134134
await handler.handle_message(message)
135135

136-
logger.info(f"[run_claude_agent_activity] ✅ Message loop completed, cleaning up...")
136+
logger.debug(f"Message loop completed, cleaning up...")
137137
await handler.cleanup()
138138

139139
results = handler.get_results()
140-
logger.info(f"[run_claude_agent_activity] ✅ About to return results: {results.keys()}")
140+
logger.debug(f"Returning results with keys: {results.keys()}")
141141
return results
142142

143143
except Exception as e:

src/agentex/lib/core/temporal/plugins/claude_agents/message_handler.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(
6767
async def initialize(self):
6868
"""Initialize streaming context if task_id is available."""
6969
if self.task_id:
70-
logger.info(f"[ClaudeMessageHandler] Creating streaming context for task: {self.task_id}")
70+
logger.debug(f"Creating streaming context for task: {self.task_id}")
7171
self.streaming_ctx = await adk.streaming.streaming_task_message_context(
7272
task_id=self.task_id,
7373
initial_content=TextContent(
@@ -82,11 +82,11 @@ async def handle_message(self, message: Any):
8282
self.messages.append(message)
8383
msg_num = len(self.messages)
8484

85-
# Debug logging
86-
logger.info(f"[ClaudeMessageHandler] 📨 [{msg_num}] Message type: {type(message).__name__}")
85+
# Debug logging (verbose - only for troubleshooting)
86+
logger.debug(f"📨 [{msg_num}] Message type: {type(message).__name__}")
8787
if isinstance(message, AssistantMessage):
8888
block_types = [type(b).__name__ for b in message.content]
89-
logger.info(f"[ClaudeMessageHandler] [{msg_num}] Content blocks: {block_types}")
89+
logger.debug(f" [{msg_num}] Content blocks: {block_types}")
9090

9191
# Route to specific handlers
9292
if isinstance(message, UserMessage):
@@ -104,7 +104,7 @@ async def _handle_user_message(self, message: UserMessage, msg_num: int):
104104
return
105105

106106
tool_name = self.tool_call_map.get(self.last_tool_call_id, "unknown")
107-
logger.info(f"[ClaudeMessageHandler] ✅ [{msg_num}] STREAMING Tool result: {tool_name}")
107+
logger.info(f" Tool result: {tool_name}")
108108

109109
# If this was a subagent (Task tool), close the subagent span
110110
if tool_name == "Task" and self.current_subagent_span and self.current_subagent_ctx:
@@ -114,7 +114,7 @@ async def _handle_user_message(self, message: UserMessage, msg_num: int):
114114

115115
self.current_subagent_span.output = {"result": user_content}
116116
await self.current_subagent_ctx.__aexit__(None, None, None)
117-
logger.info(f"[ClaudeMessageHandler] 🤖 Completed subagent execution")
117+
logger.info(f"🤖 Subagent completed: {tool_name}")
118118
self.current_subagent_span = None
119119
self.current_subagent_ctx = None
120120

@@ -178,7 +178,7 @@ async def _handle_tool_use(self, block: ToolUseBlock, msg_num: int):
178178
if not self.task_id:
179179
return
180180

181-
logger.info(f"[ClaudeMessageHandler] 🔧 [{msg_num}] STREAMING Tool request: {block.name}")
181+
logger.info(f"🔧 Tool request: {block.name}")
182182

183183
# Track tool_call_id → tool_name mapping
184184
self.tool_call_map[block.id] = block.name
@@ -187,7 +187,7 @@ async def _handle_tool_use(self, block: ToolUseBlock, msg_num: int):
187187
# Special handling for Task tool (subagents) - create nested span
188188
if block.name == "Task" and self.trace_id and self.parent_span_id:
189189
subagent_type = block.input.get("subagent_type", "unknown")
190-
logger.info(f"[ClaudeMessageHandler] 🤖 Starting subagent: {subagent_type}")
190+
logger.info(f"🤖 Subagent started: {subagent_type}")
191191

192192
# Create nested trace span
193193
self.current_subagent_ctx = adk.tracing.span(
@@ -230,7 +230,7 @@ async def _handle_tool_result(self, block: ToolResultBlock):
230230
return
231231

232232
tool_name = self.tool_call_map.get(block.tool_use_id, "unknown")
233-
logger.info(f"[ClaudeMessageHandler] ✅ Tool result: {tool_name}")
233+
logger.info(f"✅ Tool result: {tool_name}")
234234

235235
tool_content = block.content if block.content is not None else ""
236236

@@ -264,7 +264,7 @@ async def _handle_text_block(self, block: TextBlock, msg_num: int):
264264
if not block.text or not self.streaming_ctx:
265265
return
266266

267-
logger.info(f"[ClaudeMessageHandler] 💬 [{msg_num}] STREAMING Text: {block.text[:50]}...")
267+
logger.debug(f"💬 Text block: {block.text[:50]}...")
268268

269269
delta = TextDelta(type="text", text_delta=block.text)
270270

@@ -283,11 +283,9 @@ async def _handle_system_message(self, message: SystemMessage):
283283
"""Handle system message - extract session_id."""
284284
if message.subtype == "init":
285285
self.session_id = message.data.get("session_id")
286-
logger.info(
287-
f"[ClaudeMessageHandler] Session: "
288-
f"{'STARTED' if self.session_id else 'unknown'} ({self.session_id[:16] if self.session_id else 'N/A'}...)"
289-
)
290-
logger.debug(f"[ClaudeMessageHandler] SystemMessage: {message.subtype}")
286+
logger.debug(f"Session initialized: {self.session_id[:16] if self.session_id else 'unknown'}...")
287+
else:
288+
logger.debug(f"SystemMessage: {message.subtype}")
291289

292290
async def _handle_result_message(self, message: ResultMessage):
293291
"""Handle result message - extract usage and cost."""
@@ -298,17 +296,14 @@ async def _handle_result_message(self, message: ResultMessage):
298296
if message.session_id:
299297
self.session_id = message.session_id
300298

301-
logger.info(
302-
f"[ClaudeMessageHandler] Result - "
303-
f"cost=${self.cost_info:.4f}, duration={message.duration_ms}ms, turns={message.num_turns}"
304-
)
299+
logger.info(f"💰 Cost: ${self.cost_info:.4f}, Duration: {message.duration_ms}ms, Turns: {message.num_turns}")
305300

306301
async def cleanup(self):
307302
"""Clean up open streaming contexts."""
308303
if self.streaming_ctx:
309304
try:
310305
await self.streaming_ctx.close()
311-
logger.info(f"[ClaudeMessageHandler] Closed streaming context")
306+
logger.debug(f"Closed streaming context")
312307
except Exception as e:
313308
logger.warning(f"Failed to close streaming context: {e}")
314309

0 commit comments

Comments
 (0)