Overview
Grip AI uses a dual-engine architecture that lets you choose between two execution backends:- Claude Agent SDK (primary) — Full agentic loop delegated to the Claude CLI
- LiteLLM (fallback) — Internal agent loop supporting 100+ models via LiteLLM
EngineProtocol interface, so switching between them requires zero code changes. The factory pattern automatically selects the appropriate engine based on your configuration.
Engine Protocol
Both engines implement three core methods:AgentRunResult dataclass is unified across both engines:
Claude Agent SDK Engine
Architecture
The SDK engine (SDKRunner) delegates the full agentic loop to the Claude Agent SDK. Grip only provides:
- System prompt assembly (identity files, memory, skills)
- Custom tools (send_message, send_file, remember, recall)
- MCP server configuration translation
- History persistence via MemoryManager
When to Use
Use the Claude SDK engine when:
- You’re using Claude models (claude-3-5-sonnet, claude-3-opus, etc.)
- You want the latest Claude agentic capabilities
- You need native computer use support
- You prefer Claude’s native tool execution loop
System Prompt Assembly
The SDK engine builds prompts from multiple sources:Custom Tools
The SDK engine exposes custom tools via in-process MCP server:- send_message — Route messages through gateway callbacks
- send_file — Send files via configured channels
- remember — Store facts in MEMORY.md
- recall — Search long-term memory
- stock_quote — (optional) Fetch stock prices if yfinance installed
MCP Server Translation
Grip’s MCP config format is translated to SDK-compatible format:LiteLLM Engine
Architecture
The LiteLLM engine (LiteLLMRunner) wraps Grip’s internal AgentLoop stack:
create_provider(config)→ LLM providercreate_default_registry(...)→ tool registry- Optionally
SemanticCache(...)if enabled in config AgentLoop(...)with all dependencies wired together
When to Use
Use the LiteLLM engine when:
- You need non-Claude models (GPT-4, Gemini, Mistral, local models, etc.)
- You want full control over the agent loop
- You need custom provider configurations
- The Claude SDK is not installed or unavailable
Agent Loop
The LiteLLM engine uses Grip’s internal agent loop with:- Iterative tool execution — Loop until LLM returns text (no tool calls)
- Mid-run compaction — Summarize old messages when context exceeds 50 messages
- Self-correction — Inject reflection prompts when tools fail
- Cost-aware routing — Use cheaper models for simple queries
- Semantic caching — Cache identical queries to save tokens
Tool Registry
The LiteLLM engine creates a full tool registry:Engine Factory
Thecreate_engine factory reads your config and returns the appropriate engine:
Switching Engines
- Configuration File
- Environment Variable
- CLI Flag
Edit your
grip.yml:Automatic Fallback
If you configureengine: claude_sdk but the SDK package is not installed, Grip automatically falls back to LiteLLM:
Engine Wrappers
Both engines are wrapped with additional capabilities:Learning Engine
Extracts behavioral patterns from tool executions and stores them in the knowledge base (zero LLM calls, rule-based):Tracked Engine
Enforces daily token limits:Configuration Reference
Key configuration options for engines:Next Steps
- Learn about Agent lifecycle and profiles
- Understand the Tool registry system
- Explore Memory management
- Configure Session persistence