diff --git a/cptr/utils/agents/claude_code.py b/cptr/utils/agents/claude_code.py index 5806d01..fc16951 100644 --- a/cptr/utils/agents/claude_code.py +++ b/cptr/utils/agents/claude_code.py @@ -13,7 +13,6 @@ from cptr.utils.agents.events import ( AgentDone, AgentError, AgentEvent, - AgentReasoningDone, AgentReasoningDelta, AgentTextDelta, AgentToolUpdate, @@ -161,7 +160,6 @@ async def run_claude_code_agent( usage: dict[str, Any] | None = None observed_session_id = session_id tool_calls: dict[int, AgentToolUpdate] = {} - thinking_blocks: set[int] = set() received_text_delta = False received_thinking_delta = False @@ -182,9 +180,6 @@ async def run_claude_code_agent( elif delta.get("type") == "thinking_delta" and isinstance( delta.get("thinking"), str ): - index = event.get("index") - if isinstance(index, int): - thinking_blocks.add(index) thinking = delta["thinking"] yield AgentReasoningDelta(thinking) if thinking: @@ -195,15 +190,8 @@ async def run_claude_code_agent( if index is not None: tool_calls[index] = tool yield tool - elif isinstance(index, int): - block = event.get("content_block") - if isinstance(block, dict) and block.get("type") == "thinking": - thinking_blocks.add(index) elif event_type == "content_block_stop": index = event.get("index") - if isinstance(index, int) and index in thinking_blocks: - thinking_blocks.discard(index) - yield AgentReasoningDone() tool = tool_calls.get(index) if isinstance(index, int) else None if tool: yield AgentToolUpdate( diff --git a/cptr/utils/agents/events.py b/cptr/utils/agents/events.py index f1adb88..d0dcd6d 100644 --- a/cptr/utils/agents/events.py +++ b/cptr/utils/agents/events.py @@ -16,11 +16,6 @@ class AgentReasoningDelta: text: str -@dataclass -class AgentReasoningDone: - pass - - @dataclass class AgentToolUpdate: call_id: str @@ -51,7 +46,6 @@ class AgentError: AgentEvent = ( AgentTextDelta | AgentReasoningDelta - | AgentReasoningDone | AgentToolUpdate | AgentToolOutputDelta | AgentDone diff --git a/cptr/utils/chat_task.py b/cptr/utils/chat_task.py index 47924db..671b393 100644 --- a/cptr/utils/chat_task.py +++ b/cptr/utils/chat_task.py @@ -49,7 +49,6 @@ from cptr.utils.agents.events import ( AgentDone, AgentError, AgentReasoningDelta, - AgentReasoningDone, AgentTextDelta, AgentToolOutputDelta, AgentToolUpdate, @@ -1552,6 +1551,7 @@ async def run_chat_task( attachments=agent_attachments, ): if isinstance(event, AgentTextDelta): + await _finish_reasoning_item() content += event.text text_buffer += event.text await emit(delta=event.text) @@ -1567,9 +1567,8 @@ async def run_chat_task( _upsert_output_item(output_items, item) await emit(output=item) _sync_state() - elif isinstance(event, AgentReasoningDone): - await _finish_reasoning_item() elif isinstance(event, AgentToolUpdate): + await _finish_reasoning_item() flushed_item = _flush_text() if flushed_item: await emit(output=flushed_item) @@ -1630,6 +1629,7 @@ async def run_chat_task( await emit(output=output_item) _sync_state() elif isinstance(event, AgentToolOutputDelta): + await _finish_reasoning_item() flushed_item = _flush_text() if flushed_item: await emit(output=flushed_item)