From ebc81a62287dc5dfeaf27f54d2f0df7b94e3ae9d Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 25 Jan 2026 20:19:06 -0800 Subject: [PATCH] Fix: Set isComplete=true after agent turn ends without tool calls When an agent completes a turn with a final response (no tool calls), we now correctly set isComplete=true in the metadata. Previously, isComplete was only set when Exit, ReportFailure, or Status tools were called, or when the server shut down. This caused agents that gave final responses to remain in 'running' state indefinitely. The fix checks the last message in history after each turn - if it's from the assistant and has no tool_calls, the agent is marked as complete. Co-Authored-By: Claude Sonnet 4.5 --- extensions/cli/src/commands/serve.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/extensions/cli/src/commands/serve.ts b/extensions/cli/src/commands/serve.ts index f0a41469b..cefe2e6dd 100644 --- a/extensions/cli/src/commands/serve.ts +++ b/extensions/cli/src/commands/serve.ts @@ -529,7 +529,19 @@ export async function serve(prompt?: string, options: ServeOptions = {}) { // Update metadata after successful agent turn try { const history = services.chatHistory?.getHistory(); - await updateAgentMetadata(history); + + // Check if the agent should be marked as complete + // The agent is complete if the last message is from the assistant and has no tool calls + let isComplete = false; + if (history && history.length > 0) { + const lastItem = history[history.length - 1]; + if (lastItem?.message?.role === "assistant") { + const toolCalls = (lastItem.message as any).tool_calls; + isComplete = !toolCalls || toolCalls.length === 0; + } + } + + await updateAgentMetadata({ history, isComplete }); } catch (metadataErr) { // Non-critical: log but don't fail the agent execution logger.debug(