RFC: Behavior-memory budget prediction for agent loops (Loop Pilot)
Summary
Agent loops currently have no awareness of how many tool calls a task should take. The model optimizes for thoroughness (RLHF default) without knowing its budget is finite. This leads to research spirals on open-ended tasks and premature cap-hits on complex ones.
Loop Pilot is a trajectory optimization engine that solves this by learning from past runs and injecting budget guidance before each loop starts.
The Problem
Codex currently has:
- No iteration cap (trusts the model to self-regulate)
- No spinning detection
- No progress awareness
- No task-type adaptation
This works well for bounded tasks (tests pass → stop). It breaks for open-ended tasks where "done" is subjective — the model keeps gathering context indefinitely because it has no signal to stop.
Proposed Solution: Inform, Then Trust
Instead of hard caps (too rigid) or blind trust (too optimistic), give the model information about what success looks like:
- Episode memory — store past tool-call episodes (task description, tools used, call count, outcome)
- KNN similarity — when a new task arrives, find the 5 most similar past episodes
- Budget prediction — predict tool budget from successful neighbors
- Prompt guidance — inject a guidance block into the system prompt before the loop starts
The model reads: "Tasks like this typically take 3-5 tool calls. You have 10 available. Here's what worked before." It self-regulates.
What It Looks Like
The injected guidance block:
## Loop Pilot Guidance
Similar past behavior suggests:
- Suggested tool-call budget: 4
- Confidence: high
- Risk: low
- Likely useful tools: bash, web_search, write_file
Reason: Based on 5 similar successful episode(s), average tool calls were 3.2.
Repeated-tool caution: similar tasks repeated bash. Avoid repeating
a tool once enough context is found.
Use this as operational guidance. Continue to reason normally.
Implementation
I've built this and it's running in production on my agent harness (Cal):
Repo: https://github.com/monbishnoi/loop-pilot
- TypeScript, MIT licensed
- SQLite-backed episode memory
- Pluggable embedding providers (HTTP endpoint, CLI command)
- MCP server (4 tools: plan_task, record_episode, import_episodes, get_stats)
- HTTP server alternative
- 404 real episodes imported, KNN predictions consistently accurate
Integration with Codex
Loop Pilot could integrate as:
- A Codex plugin — runs
plan_taskbefore each agent loop, injects guidance into the system prompt - A pre-loop hook — if Codex exposes a lifecycle hook before model invocation
- An MCP server — Codex already supports MCP; Loop Pilot exposes MCP tools
The key design principle: advisory only. Loop Pilot never changes hard limits. It informs the model and trusts it to self-moderate. Your existing architecture stays unchanged — this layers on top.
Why This Matters
As models get post-trained on agentic RL (Tool-R1, ARTIST, DAPO), they'll internalize iteration efficiency. Until then, the harness needs to bridge the gap. "Inform, then trust" is a bridge strategy that works today and gracefully becomes unnecessary as models improve.
References
- Blog post: "Inform, Then Trust" (publishing this week)
- Research: Tool-R1 (arXiv 2509.12867), ARTIST (Microsoft), DAPO (ByteDance)
- Related Codex issue: #13946 (compaction loop guard)
Happy to discuss integration patterns or contribute directly if there's interest.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗