Skip to main content

System Architecture

Tiny Claw is built from scratch as a native framework with a philosophy of keeping the core tiny and making everything else pluggable. This architectural approach ensures minimal footprint, maximum flexibility, and zero dependency on external AI frameworks.

Core Design Principles

Tiny Core

The core stays minimal. All non-essential features live as plugins.

Plugin Everything

Channels, providers, and tools are all plugins. Easy to extend.

Native, Not Wrapped

Every component is built from scratch with zero external AI framework dependencies.

Bun-Native

Built on Bun for maximum performance and minimal footprint.

Architecture Diagram

Tiny Claw Architecture
Everything above the plugin line is the tiny core. Channels, extra providers, and additional tools live as plugins in plugins/.

Layer Breakdown

User Layer

Users interact with Tiny Claw through various channels:
  • Web UI — Discord-like interface with SSE streaming
  • Discord — Native Discord bot integration
  • Friends — Private chat invites for trusted users
  • CLI — Command-line interface (planned)

Channel Plugins (Pluggable)

Channel plugins connect external messaging platforms to the agent loop:
export interface ChannelPlugin extends PluginMeta {
  readonly type: 'channel';
  start(context: PluginRuntimeContext): Promise<void>;
  stop(): Promise<void>;
  getPairingTools?(secrets: SecretsManagerInterface, configManager: ConfigManagerInterface): Tool[];
  sendToUser?(userId: string, message: OutboundMessage): Promise<void>;
  readonly channelPrefix?: string;
}
Lifecycle:
  1. getPairingTools() — called during boot to merge pairing tools
  2. start(context) — called after agentContext is built
  3. The plugin drives messages into the agent via context.enqueue
  4. stop() — called during graceful shutdown

Tiny Core (packages/core/)

The core contains:
1

Router

Smart query classification using 8-dimension scoring to route queries to appropriate providers
2

Memory

Adaptive memory with episodic storage, FTS5 semantic search, and temporal decay
3

Built-in Tools

Essential tools for memory management, file operations, and system control
4

Delegation

Sub-agent orchestration with lifecycle management and blackboard collaboration
5

Heartware

Personality engine with sandboxed self-configuration workspace
6

Shield

Runtime SHIELD.md threat evaluation and enforcement
7

SQLite DB

Persistent storage for messages, memory, agents, and templates

Tool Plugins (Pluggable)

Additional capabilities can be added via tool plugins:
export interface ToolsPlugin extends PluginMeta {
  readonly type: 'tools';
  createTools(context: AgentContext): Tool[];
}
Future plugins might include:
  • Web browsing and scraping
  • Image generation and analysis
  • Calendar and scheduling
  • Email and notifications
  • Cloud service integrations

Model Provider Plugins (Pluggable)

Provider plugins register additional LLM providers:
export interface ProviderPlugin extends PluginMeta {
  readonly type: 'provider';
  createProvider(secrets: SecretsManagerInterface): Promise<Provider>;
  getPairingTools?(secrets: SecretsManagerInterface, configManager: ConfigManagerInterface): Tool[];
}
Built-in: Ollama Cloud (default) Plugin examples:
  • OpenAI (GPT-4, GPT-4o)
  • Anthropic (Claude)
  • Local Ollama
  • Google Gemini

LLM Layer

Providers abstract the underlying LLM APIs:
export interface Provider {
  id: string;
  name: string;
  chat(messages: Message[], tools?: Tool[]): Promise<LLMResponse>;
  isAvailable(): Promise<boolean>;
}
The orchestrator handles:
  • Multi-provider support with automatic failover
  • Query tier routing (simple → cheap models, complex → powerful models)
  • Provider health checks and fallback chains

Package Structure

tinyclaw/
  packages/          Core library packages (tiny, focused, no circular deps)
    core/            Agent loop, database, built-in Ollama provider
    types/           Shared interfaces (leaf dependency)
    config/          Zod-validated configuration engine
    compactor/       Context compaction engine (4-layer pipeline)
    heartware/       Personality engine + safety layers
    memory/          Adaptive memory with episodic + FTS5
    delegation/      Sub-agent orchestration + blackboard
    router/          Smart provider routing (8-dim classifier)
    learning/        Behavioral pattern detection
    sandbox/         Bun Worker code execution
    shell/           Controlled shell execution with permission engine
    shield/          Runtime SHIELD.md enforcement + anti-malware
    pulse/           Cron-like proactive scheduler
    queue/           Per-session message locking queue
    intercom/        Pub/sub inter-agent communication
    matcher/         Hybrid semantic matcher (TF-IDF + fuzzy + synonyms)
    logger/          Singleton logger with emoji mappings
    secrets/         Encrypted secrets management (AES-256-GCM)
    plugins/         Plugin discovery and loading
  plugins/           Plugin packages (keep the core tiny)
    channel/         Messaging integrations (Discord, Friends, etc.)
    provider/        LLM providers (OpenAI, etc.)
  src/
    cli/             CLI entry point
    landing/         Official landing page (Svelte + Vite)
    web/             Web UI (Svelte 5, Discord-like experience)

Data Flow

1

User Input

User sends a message through a channel (Web UI, Discord, Friends)
2

Channel Plugin

Channel plugin receives the message and enqueues it via context.enqueue(userId, message)
3

Agent Loop

Core agent loop processes the message:
  • Loads conversation history from SQLite
  • Retrieves relevant memories (episodic + semantic search)
  • Builds system prompt with heartware personality context
  • Classifies query complexity via Router
  • Selects appropriate provider based on tier
4

LLM Call

Provider sends messages to LLM and streams response back
5

Tool Execution

If LLM requests tool calls:
  • Shield evaluates each tool call for threats
  • Tools are executed (memory, delegation, heartware, etc.)
  • Results are fed back to LLM
6

Response

Final response is:
  • Saved to SQLite message history
  • Analyzed by Learning engine for patterns
  • Streamed back to user through the channel

Key Interfaces

AgentContext

The central context object passed to tools and agents:
packages/types/src/index.ts
export interface AgentContext {
  db: Database;
  provider: Provider;
  learning: LearningEngine;
  tools: Tool[];
  heartwareContext?: string;
  secrets?: SecretsManagerInterface;
  configManager?: ConfigManagerInterface;
  modelName?: string;
  providerName?: string;
  ownerId?: string;
  memory?: MemoryEngine;
  shield?: ShieldEngine;
  delegation?: DelegationContext;
  compactor?: CompactionEngine;
  updateContext?: string;
}

Tool Interface

packages/types/src/index.ts
export interface Tool {
  name: string;
  description: string;
  parameters: Record<string, unknown>;
  execute(args: Record<string, unknown>): Promise<string>;
}

Message Format

packages/types/src/index.ts
export interface Message {
  role: 'system' | 'user' | 'assistant' | 'tool';
  content: string;
  toolCalls?: ToolCall[];
  toolCallId?: string;
}

Why This Architecture?

By keeping only essential features in core, Tiny Claw remains lightweight and fast. The entire core is under 50KB compressed.
Users only load what they need. Don’t need Discord? Don’t load the plugin. Want to add GitHub integration? Write a tool plugin.
Unlike frameworks built on top of other AI frameworks, Tiny Claw owns its entire stack. No dependency on proprietary systems.
Bun is 3x faster than Node.js for I/O operations and provides a single binary runtime with built-in TypeScript support.

Comparison with Other Frameworks

Tiny ClawOther AI Agent Frameworks
ArchitectureNative framework, built from scratchBuilt on existing frameworks (Pi, Claude Code, Codex)
Core sizeTiny by design, everything else is a pluginLarge monolith that grows over time
RuntimeBun-native, single binaryNode.js 22+, pnpm, multiple processes
RoutingAdapts to whichever provider plugins you installHardcoded to a single provider
SecurityBuilt-in SHIELD.md anti-malware enforcementNo native threat model
UIDiscord-like web experience out of the boxTerminal-only or separate UI dependency

Next: Plugin System

Learn how to build and extend Tiny Claw with plugins