Agent engine
How the XibeCode agent loop works — iterations, modes, tools, auto-compact, completion, and learning.
Agent engine
XibeCode’s core (xibecode-core) runs an autonomous coding agent: model calls → tool use → file/shell changes → verify → continue until the task is done or you stop it.
Surfaces
| Surface | Command | Notes |
|---|---|---|
| One-shot task | xibecode run "…" | Non-interactive autonomous run |
| Task + PR | xibecode run-pr "…" | Branch + GitHub PR after work |
| Interactive chat | xibecode chat / xc | TUI with slash commands |
| Messaging | xibecode daemon / gateway | Telegram / Discord / Slack |
| Scheduled | xibecode cron + daemon | Periodic agent jobs |
| IDE / ACP | VS Code extension, ACP stdio | Same engine, different hosts |
Agent loop
- Build context (project files, curated memory, skills, session history).
- Call the LLM with tools (read/write/edit, shell, search, MCP, etc.).
- Execute tool calls safely under permission rules.
- Feed results back; repeat until:
- the model finishes with a final answer, or
- you abort (Ctrl+C, chat cancel, daemon
/stop), or - a finite iteration cap is hit.
On tool failure, the engine injects a recovery message (retry with new params, alternative tool, or finish with a failure summary) so runs do not spin silently.
Max iterations (unlimited by default)
| Value | Behavior |
|---|---|
0 (default) | Unlimited — loop until completion or abort |
| Positive integer | Hard stop after N model turns |
# Unlimited (default)
xibecode run "refactor auth module"
# Cap at 100 turns
xibecode run "…" -d 100
# Profile default
xibecode config # or setup agent → Max agent iterations = 0Economy cost mode still applies a separate lower cap (economyMaxIterations) so cheap runs stay bounded.
Anti-runaway: repeated identical tool calls are blocked by the loop detector; you can always interrupt.
Auto-compact
When the conversation nears the model’s context budget, XibeCode auto-compacts so long tasks can continue.
When it triggers
- Preflight and post-turn checks each agent iteration.
- Roughly ~75% of context for typical windows (≤512k), ~50% for huge windows.
- Always leaves headroom: never later than
window − autoCompactThreshold(default ~13k tokens free for the next reply).
What happens
- Microcompact — strip or shrink old tool results.
- Full handoff — structured summary + grounded facts ledger + token-budget tail (not a fixed message count).
- Prior compaction summaries are folded in; the model is told not to re-answer resolved work.
User-visible status
- Compacting context — summarizing earlier conversation…
- Context compacted · … tokens
(Telegram/daemon shows the same as progress messages.)
Disable / tune
{
"autoCompactEnabled": false,
"autoCompactThreshold": 13000
}XIBECODE_AUTO_COMPACT=0 # disableLifecycle hooks: PreCompact / PostCompact (see Hooks).
Modes
Modes control tool categories and behavior (agent, plan, review, debugger, …). See Modes. Plan and review modes still allow shell where needed for verification.
Tools
File ops, shell, search, web fetch, memory (curated_memory, project memory), skills (list_skills / view_skill), swarm, MCP tools, screenshots, and more. See Tools.
Browser note: Playwright is not bundled. Prefer agent-browser (optional install) or host Chromium for screenshots; other browser audit tools may return guidance stubs.
Learning & memory
After turns, optional learning loop features:
- Curated
MEMORY.md/USER.md(frozen at session start; disk updates immediate for next session) - Post-turn review (optional cheap model)
- Write-approval for sensitive memory/skill writes
- Session search across past work
- Skill learner for reusable procedures
See Memory.
Providers & models
Any catalog entry from Providers. Live /models, models.dev registry, and curated fallbacks. Failover pools improve reliability under rate limits.
Cloud execution
Optional E2B sandbox runtime: shell in the cloud while files stay on host (host_only) or full workspace sync (sandbox_full). See Cloud / E2B.
File history / checkpoints
On-disk checkpoints under ~/.xibecode/file-history/ with message-linked snapshots. Disable with XIBECODE_DISABLE_FILE_CHECKPOINTING=1.
Best practices
- Run
xibecode setuponce, thenxibecode chatfor interactive work. - Prefer unlimited iterations for large refactors; use
-d Nonly when you want a hard budget. - Use economy mode for cheap drafts; normal mode for production changes.
- For always-on coding from phone/Telegram, install the daemon and use
/stopif a run goes wrong;/cmdfor quick shell without the agent. - Let auto-compact run on long chats; only disable if you need the full raw history in context.