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(