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 <noreply@anthropic.com>
This commit is contained in:
parent
b65f44027a
commit
ebc81a6228
1 changed files with 13 additions and 1 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue