Introduction
Craft Agents is a flexible AI agent framework built around workspaces, sessions, and agent backends. The architecture emphasizes isolation boundaries, multi-provider support, and extensibility through sources (MCP servers and API connections).Core Architecture
Workspaces
Project-scoped configuration with isolated sources and sessions
Sessions
Conversation boundaries with 1:1 SDK session mapping
Agent Backends
Provider-agnostic agent implementations (Claude, Pi, OpenAI)
Sources
MCP servers and API connections for external data
Key Design Principles
Sessions as Primary Boundary
Sessions are the primary isolation boundary in Craft Agents, not workspaces:- Each session maps 1:1 with an SDK session (Claude Agent SDK, Pi SDK, etc.)
- Sessions have their own permission mode, working directory, and conversation history
- Multiple sessions can coexist in the same workspace with different configurations
- Sessions persist their complete state (messages, token usage, metadata) in JSONL format
Why sessions? This design allows multiple conversations with different contexts to run in the same project without contaminating each other’s state.
Multi-Provider Support
TheBaseAgent abstract class provides a unified interface across AI providers:
- ClaudeAgent - Anthropic Claude models via Claude Agent SDK
- PiAgent - Pi coding agents via Pi SDK (subprocess)
- CodexAgent - OpenAI models via Codex app-server (planned)
- CopilotAgent - GitHub Copilot integration (planned)
Source Architecture
Sources are workspace-scoped external data connections that provide tools to agents:MCP Sources
MCP Sources
Model Context Protocol servers running as subprocesses:
API Sources
API Sources
Direct HTTP API integrations with authentication:
Local Sources
Local Sources
Local filesystem directories with custom tools:
Permission System
Three-level permission modes provide granular control over agent actions:| Mode | Display | Behavior |
|---|---|---|
safe | Explore | Read-only, blocks all write operations |
ask | Ask to Edit | Prompts for bash commands (default) |
allow-all | Auto | Auto-approves all commands |
Permission mode is per-session, allowing different trust levels for different conversations in the same workspace.
Data Flow
Event Stream
All agent backends emit standardizedAgentEvent types:
Storage Layout
All data is stored under~/.craft-agent/:
JSONL Format: Sessions use JSONL (JSON Lines) for efficient streaming writes and incremental reads. Line 1 is the header (metadata), subsequent lines are messages.
Package Structure
The codebase is organized as a monorepo:Next Steps
Workspaces
Learn about workspace configuration and storage
Sessions
Understand session lifecycle and persistence
Agents
Explore agent backends and the BaseAgent class
Sources
Configure MCP servers and API connections