feat: structured progress reports on agent iteration/time limits#548
feat: structured progress reports on agent iteration/time limits#548
Conversation
…ime limits 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>
PR Overview: Structured Progress Reports on Agent Iteration/Time LimitsSummaryThis PR enhances the ProbeAgent's shutdown behavior when hitting iteration limits or time budgets. Instead of generic failure messages, the agent now produces structured progress reports that enable follow-up agents to continue work without starting from scratch. Key Changes1. Enhanced Tool Call Logging (
|
| Component | Change | Impact |
|---|---|---|
_toolCallLog structure |
Added resultBrief, step fields |
Enables detailed activity logs in shutdown messages |
_assistant_text tracking |
New entry type for AI text output | Captures reasoning and partial findings |
prepareStep last-iteration prompt |
Structured report format + activity log | Better handoff for iteration limit |
| Graceful timeout prompt | Structured report format | Better handoff for time budget exhaustion |
| Negotiated timeout summary | Structured report format | Better handoff when observer declines extension |
| Max iterations fallback | Enhanced with timeline and findings | Fallback still useful even when LLM doesn't respond |
Affected System Components
graph TD
A[ProbeAgent Main Loop] --> B{Check Limits}
B -->|Last Iteration| C[prepareStep - Structured Report Prompt]
B -->|Time Budget Exhausted| D[Graceful Wind-Down - Structured Report]
B -->|Negotiated Timeout Declined| E[Abort Summary - Structured Report]
B -->|Hard Limit Hit| F[Fallback Report with Timeline]
C --> G[Enhanced _toolCallLog]
D --> G
E --> G
F --> G
G --> H[resultBrief + step Numbers]
G --> I[_assistant_text Tracking]
H --> J[Structured Progress Report]
I --> J
J --> K[Follow-up Agent Can Continue]
Component Relationships
sequenceDiagram
participant Main as ProbeAgent Main Loop
participant prepareStep as prepareStep Callback
participant Logger as _toolCallLog
participant LLM as AI Model
Main->>Logger: Track tool calls with resultBrief
Main->>Logger: Track assistant text fragments
Note over Main: Check iteration/time limits
alt Last Iteration
prepareStep->>LLM: Inject structured report prompt + activity log
LLM->>Main: Generate progress report
else Graceful Timeout
prepareStep->>LLM: Inject structured report prompt
LLM->>Main: Generate progress report
else Negotiated Timeout Declined
Main->>LLM: Request structured summary
LLM->>Main: Generate progress report
else Hard Limit Hit
Main->>Main: Build fallback report from _toolCallLog
end
Main->>Main: Return structured progress report
Scope Discovery & Context Expansion
Direct Impact
- Core agent behavior: All three shutdown paths (iteration limit, graceful timeout, negotiated timeout) now produce structured reports
- Tool call tracking: Enhanced logging affects every tool execution in the main loop
- Memory overhead:
_toolCallLognow stores more data (result briefs up to 500 chars, assistant text up to 1000 chars)
Related Components (Inferred)
-
Subagent delegation (
src/delegate.js): Subagents inherit timeout behavior and may produce structured reports that parent agents receive -
Code-searcher subagents: Special handling for
promptType === 'code-searcher'- they output structured JSON even on partial results (confidence: "low") -
MCP servers: Two-phase graceful stop coordination (
_initiateGracefulStop) signals MCP servers to wind down -
Telemetry/tracing: The enhanced
_toolCallLogdata could be exposed via tracer events for debugging -
Configuration:
MAX_TOOL_ITERATIONS: Default 30 (range 1-200)gracefulTimeoutBonusSteps: Default 4 (range 1-20)negotiatedTimeoutBudget: Default 1800000ms (30 min)
Potential Follow-Up Areas
-
Progress report parsing: Follow-up agents could be enhanced to parse and understand the structured report format
-
Report schema: Could define a formal JSON schema for progress reports to enable programmatic consumption
-
Compression: For long-running agents,
_toolCallLogcould grow large - consider compression or summarization -
UI display: Frontend could render structured progress reports in a user-friendly format
Files Changed Analysis
| File | Additions | Deletions | Net Change | Purpose |
|---|---|---|---|---|
npm/src/agent/ProbeAgent.js |
+86 | -26 | +60 | Core implementation of structured reports and enhanced logging |
npm/tests/unit/code-searcher-iteration-limit.test.js |
+1 | -1 | 0 | Update assertion to expect "PROGRESS REPORT" |
npm/tests/unit/graceful-timeout.test.js |
+1 | -1 | 0 | Update assertion to expect "PROGRESS REPORT" |
npm/tests/unit/negotiated-timeout.test.js |
+2 | -2 | 0 | Update assertions to expect "PROGRESS REPORT" |
Total: 90 additions, 30 deletions across 4 files
Notable Patterns
-
Consistent structure: All three shutdown paths use the same 5-section format (Task, Completed Work, Key Findings, Attempted but Inconclusive, Not Started/Remaining, Suggested Next Steps)
-
Data inclusion emphasis: Prompts explicitly instruct the AI to "include ALL useful data you gathered inline — do not just say 'I found X', actually include X"
-
Activity log injection: The tool activity log is dynamically generated from
_toolCallLogand injected into prompts to provide context -
Backward compatibility: Code-searcher subagents still output structured JSON (unchanged), just with enhanced search details
References
Code Locations
- Enhanced tool call logging:
npm/src/agent/ProbeAgent.js:4208-4230 - Last iteration structured prompt:
npm/src/agent/ProbeAgent.js:4097-4145 - Graceful timeout structured prompt:
npm/src/agent/ProbeAgent.js:4073-4095 - Negotiated timeout structured summary:
npm/src/agent/ProbeAgent.js:4632-4650 - Enhanced fallback report:
npm/src/agent/ProbeAgent.js:4785-4828 - Test updates:
npm/tests/unit/code-searcher-iteration-limit.test.js:87npm/tests/unit/graceful-timeout.test.js:123npm/tests/unit/negotiated-timeout.test.js:448, 486
Related Documentation
- Timeout modes:
docs/probe-agent/sdk/timeout-modes.md:55-85 - Limits reference:
docs/reference/limits.md - Code-searcher prompt:
npm/src/agent/shared/prompts.js:36-80 - CODE_SEARCH_SCHEMA:
npm/src/tools/vercel.js:89-130
Metadata
- Review Effort: 2 / 5
- Primary Label: feature
Powered by Visor from Probelabs
Last updated: 2026-03-27T21:43:25.733Z | Triggered by: pr_opened | Commit: 3157d21
💡 TIP: You can chat with Visor using /visor ask <your question>
Security Issues (7)
Performance Issues (1)
Quality Issues (13)
Powered by Visor from Probelabs Last updated: 2026-03-27T21:42:30.338Z | Triggered by: pr_opened | Commit: 3157d21 💡 TIP: You can chat with Visor using |
Summary
_toolCallLogwith result briefs, step numbers, and assistant text fragments for richer programmatic fallback reportsTest plan
graceful-timeout.test.js,negotiated-timeout.test.js,code-searcher-iteration-limit.test.jsMAX_TOOL_ITERATIONS=3— confirmed structured progress report is produced on iteration limit🤖 Generated with Claude Code