You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: produce structured progress reports when agent hits iteration/time limits (#548)
When the agent reaches its max iteration or time budget limit, instead of
a generic "unable to complete" message, it now produces a structured
progress report (Task, Completed Work, Key Findings, Attempted but
Inconclusive, Not Started/Remaining, Suggested Next Steps) so that a
follow-up agent can continue without starting from scratch.
Also enriches _toolCallLog with result briefs and step numbers, and
improves tool arg capture for the programmatic fallback report.
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: npm/src/agent/ProbeAgent.js
+86-26Lines changed: 86 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -4084,7 +4084,7 @@ or
4084
4084
}
4085
4085
return{
4086
4086
toolChoice: 'none',
4087
-
userMessage: `⚠️ TIME BUDGET EXHAUSTED. Your allocated time for this task has run out. You have ${remaining} step(s) remaining to provide your answer.\n\nIMPORTANT: This is a time budget constraint, NOT a system shutdown or error. The system is working perfectly — you simply used all your allocated time.\n\nDo NOT say things like "the system is shutting down" or "try again later" — the user submitted a request and is waiting for YOUR answer right now.\n\nProvide your BEST answer NOW using the information you have already gathered. Do NOT call any more tools. Summarize your findings and respond completely. If something was not completed, honestly state what was not done and provide any partial results or recommendations you can offer.`
4087
+
userMessage: `⚠️ TIME BUDGET EXHAUSTED. Your allocated time for this task has run out. You have ${remaining} step(s) remaining to provide your answer.\n\nIMPORTANT: This is a time budget constraint, NOT a system shutdown or error. The system is working perfectly — you simply used all your allocated time.\n\nDo NOT say things like "the system is shutting down" or "try again later" — the user submitted a request and is waiting for YOUR answer right now.\n\nYou MUST now produce a detailed PROGRESS REPORT so that a follow-up agent can continue your work without starting over. Structure your response as follows:\n\n## Task\nWhat was the original request / goal.\n\n## Completed Work\nWhat you successfully accomplished — include ALL findings, code snippets, file paths, data, and conclusions gathered. Be specific and include actual content, not just descriptions.\n\n## Key Findings\nConcrete facts, answers, or data points you discovered. Include file paths with line numbers, code snippets, configuration values, etc.\n\n## Attempted but Inconclusive\nWhat you tried that did not yield clear results — include the approach and why it was inconclusive, so the next agent does not repeat it.\n\n## Not Started / Remaining\nWhat parts of the task you did not get to, and any recommendations for how to approach them.\n\n## Suggested Next Steps\nSpecific, actionable steps for a follow-up agent to continue this work efficiently.\n\nIMPORTANT: Include ALL useful data you gathered inline — do not just say "I found X", actually include X. The next agent will only see this report, not your tool call history.`
4088
4088
};
4089
4089
}
4090
4090
@@ -4094,22 +4094,48 @@ or
4094
4094
return{toolChoice: 'none'};
4095
4095
}
4096
4096
4097
-
// Last-iteration warning — force text-only and tell the AI to summarize
4097
+
// Last-iteration warning — force text-only and request a structured progress report
4098
4098
if(stepNumber===maxIterations-1){
4099
-
// Build a brief summary of tools used so the model can reference them in its answer
? `⚠️ LAST ITERATION — you are out of tool calls. Output your JSON response NOW with whatever files you have verified so far. Set confidence to "low" if your search was incomplete. Include the "searches" array listing all search queries you made with their paths and outcomes.${searchSummary}`
4112
-
: `⚠️ LAST ITERATION — you are out of tool calls. Provide your BEST answer NOW with the information gathered so far. If you could not find what was requested, explain exactly what you searched for and why it did not work, so the caller can try a different approach.${searchSummary}`;
4115
+
? `⚠️ LAST ITERATION — you are out of tool calls. Output your JSON response NOW with whatever files you have verified so far. Set confidence to "low" if your search was incomplete. Include the "searches" array listing all search queries you made with their paths and outcomes.${activityLog}`
4116
+
: `⚠️ ITERATION LIMIT REACHED — you have no more tool calls. You MUST now produce a detailed PROGRESS REPORT so that a follow-up agent can continue your work without starting over.
4117
+
4118
+
Structure your response as follows:
4119
+
4120
+
## Task
4121
+
What was the original request / goal.
4122
+
4123
+
## Completed Work
4124
+
What you successfully accomplished — include ALL findings, code snippets, file paths, data, and conclusions gathered. Be specific and include actual content, not just descriptions.
4125
+
4126
+
## Key Findings
4127
+
Concrete facts, answers, or data points you discovered. Include file paths with line numbers, code snippets, configuration values, etc.
4128
+
4129
+
## Attempted but Inconclusive
4130
+
What you tried that did not yield clear results — include the approach and why it was inconclusive, so the next agent does not repeat it.
4131
+
4132
+
## Not Started / Remaining
4133
+
What parts of the task you did not get to, and any recommendations for how to approach them.
4134
+
4135
+
## Suggested Next Steps
4136
+
Specific, actionable steps for a follow-up agent to continue this work efficiently.
4137
+
4138
+
IMPORTANT: Include ALL useful data you gathered inline — do not just say "I found X", actually include X. The next agent will only see this report, not your tool call history.${activityLog}`;
4113
4139
4114
4140
return{
4115
4141
toolChoice: 'none',
@@ -4208,13 +4234,26 @@ Double-check your response based on the criteria above. If everything looks good
4208
4234
currentIteration++;
4209
4235
toolContext.currentIteration=currentIteration;
4210
4236
4211
-
// Track tool calls for failure diagnostics
4237
+
// Track tool calls for failure diagnostics and progress reports
// Record telemetry — include model's reasoning and tool call details
4219
4258
if(this.tracer){
4220
4259
conststepEvent={
@@ -4633,13 +4672,16 @@ Double-check your response based on the criteria above. If everything looks good
4633
4672
`Some of your tool calls were cancelled mid-execution because the timeout observer determined the time limit was reached.\n\n`+
4634
4673
`IMPORTANT: This is a time budget constraint, NOT a system shutdown or error. The system is working perfectly — you simply used all your allocated time. `+
4635
4674
`Do NOT say things like "the system is shutting down" or "try again later." The user is waiting for your answer RIGHT NOW.\n\n`+
4636
-
`Please provide a DETAILED summary of:\n`+
4637
-
`1. What you were asked to do (the original task)\n`+
4638
-
`2. What you accomplished — include ALL findings, code snippets, data, and conclusions you gathered\n`+
4639
-
`3. What was still in progress or not yet started\n`+
4640
-
`4. Any partial results or recommendations you can offer based on what you found so far`+
4675
+
`You MUST produce a detailed PROGRESS REPORT so that a follow-up agent can continue your work without starting over. `+
4676
+
`Structure your response with these sections:\n\n`+
4677
+
`## Task\nWhat was the original request / goal.\n\n`+
4678
+
`## Completed Work\nWhat you successfully accomplished — include ALL findings, code snippets, file paths, data, and conclusions gathered. Be specific and include actual content, not just descriptions.\n\n`+
4679
+
`## Key Findings\nConcrete facts, answers, or data points you discovered. Include file paths with line numbers, code snippets, configuration values, etc.\n\n`+
4680
+
`## Attempted but Inconclusive\nWhat you tried that did not yield clear results — include the approach and why it was inconclusive, so the next agent does not repeat it.\n\n`+
4681
+
`## Not Started / Remaining\nWhat parts of the task you did not get to, and any recommendations for how to approach them.\n\n`+
4682
+
`## Suggested Next Steps\nSpecific, actionable steps for a follow-up agent to continue this work efficiently.`+
4641
4683
`${taskContext}${schemaContext}\n\n`+
4642
-
`Be thorough — this is the user's only response. Include all useful information you collected.`;
4684
+
`IMPORTANT: Include ALL useful data you gathered inline — do not just say "I found X", actually include X. The next agent will only see this report, not your tool call history.`;
4643
4685
4644
4686
constsummaryMessages=[
4645
4687
...currentMessages,
@@ -4791,21 +4833,33 @@ Double-check your response based on the criteria above. If everything looks good
summary+=`\nThe search approach may be fundamentally wrong for this query. Consider: using exact=true for literal string matching, using bash/grep for pattern-based file searches, or trying a completely different strategy instead of repeating similar searches.`;
4884
+
summary+=`### Recommendation for Follow-Up\nThe iteration limit was reached before the task could be completed. A follow-up agent should review the activity log above to avoid repeating the same searches, and consider alternative approaches such as: using exact=true for literal string matching, using bash/grep for pattern-based file searches, or trying a different strategy.`;
0 commit comments