fix: reviews failing to call next tool
This commit is contained in:
+33
-2
@@ -95,8 +95,17 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
|
||||
},
|
||||
];
|
||||
|
||||
// Tools that signal the agent has produced its final output.
|
||||
const OUTPUT_TOOLS = new Set([
|
||||
"create_pull_request_review",
|
||||
"report_progress",
|
||||
"set_output",
|
||||
]);
|
||||
|
||||
let iterations = 0;
|
||||
let pendingModeNudge = false;
|
||||
let calledOutputTool = false;
|
||||
let addedContinueNudge = false;
|
||||
|
||||
while (iterations < MAX_ITERATIONS) {
|
||||
iterations++;
|
||||
@@ -124,8 +133,26 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
|
||||
const toolCalls: ToolCall[] | undefined = assistantMessage.tool_calls;
|
||||
|
||||
if (!toolCalls || toolCalls.length === 0) {
|
||||
// If we just gave the model a nudge after select_mode and it still won't
|
||||
// call tools, it's genuinely done (or stuck) — exit cleanly.
|
||||
log.debug(` model text: ${assistantMessage.content?.slice(0, 500)}`);
|
||||
|
||||
// If the model stopped before ever calling an output tool and we haven't
|
||||
// nudged yet, give it one more push to continue the workflow — regardless
|
||||
// of whether the mode nudge is still pending (the model may have stopped
|
||||
// right after select_mode before acting on the guidance).
|
||||
if (!calledOutputTool && !addedContinueNudge) {
|
||||
log.info("» model stopped before completing task — nudging to continue");
|
||||
addedContinueNudge = true;
|
||||
messages.push({
|
||||
role: "user",
|
||||
content:
|
||||
"Your task is not complete yet. Continue executing the workflow — " +
|
||||
"call the next required tool to finish. " +
|
||||
"Do not stop until you have submitted a review (create_pull_request_review) " +
|
||||
"or called report_progress with a final summary.",
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pendingModeNudge) {
|
||||
log.info("» agent finished after mode nudge (no tool calls)");
|
||||
} else {
|
||||
@@ -150,6 +177,10 @@ async function runOllamaLoop(ctx: AgentRunContext): Promise<AgentResult> {
|
||||
log.info(`» calling tool: ${toolName}`);
|
||||
log.debug(` args: ${JSON.stringify(toolArgs)}`);
|
||||
|
||||
if (OUTPUT_TOOLS.has(toolName)) {
|
||||
calledOutputTool = true;
|
||||
}
|
||||
|
||||
if (ctx.onToolUse) {
|
||||
ctx.onToolUse({ toolName, input: toolArgs });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user