Architecture
System overview, key modules, token pipeline, and error recovery.
System Overview
Franklin is structured as a pipeline. Every user message flows through these stages:
text
CLI Entry → Agent Loop → LLM Client → Tool Dispatch → x402 Payment- CLI Entry— parses flags, loads config, initializes the session
- Agent Loop— orchestrates the think-act-observe cycle until the task is complete
- LLM Client— routes requests to the optimal model via the Smart Router
- Tool Dispatch— executes tool calls (file ops, shell, search, MCP) and returns results
- x402 Payment— settles micropayments per API call using USDC on Base or Solana
Key Modules
text
agent/ Agent loop, planning, and orchestration
tools/ Built-in tool implementations (file, shell, search, browser)
router/ Smart Router — model selection, cost optimization, fallback chains
wallet/ Wallet management, x402 payment signing
session/ Session persistence, crash recovery, replay
brain/ Long-term memory storage and retrieval
learnings/ Self-evolution rules (learnings.jsonl)Token Pipeline
Franklin aggressively compacts context to stay within model limits and minimize cost. The pipeline runs in order:
- optimize— strips redundant whitespace, collapses repeated tool outputs
- reduce— summarizes older conversation turns into compact representations
- microCompact— applies token-level compression (abbreviations, deduplication)
- autoCompact— triggered automatically when context approaches the model's limit
Automatic compaction
You never need to manually compact. When the context window fills, Franklin summarizes the conversation and continues seamlessly. The
/compact slash command forces immediate compaction if needed.Error Recovery
Franklin handles failures at every layer with specific strategies:
- Context overflow— triggers autoCompact to summarize and free tokens
- Transient errors— exponential backoff with jitter, up to 3 retries
- Rate limits— falls back to the next model in the Smart Router's ranked list
- Payment failure— tries alternate payment chain, then falls back to free NVIDIA models
Design Principles
- Tool-agnostic core— the agent loop is decoupled from tool implementations. Any tool that satisfies the
CapabilityHandlerinterface can be plugged in. - Plugin-first extensibility— new capabilities are added as plugins, not core changes. The plugin discovery system loads dev, user, and bundled plugins automatically.
- Crash-safe sessions— sessions are persisted to disk after every turn. If Franklin crashes, restart and your conversation resumes from the last completed turn.