Skip to main content
Karen is built as a multi-layer system that enables both autonomous AI agents and external integrations to securely manage Solana wallets.

Architecture Overview

The system follows a clean separation of concerns across four layers:
External Agents (OpenClaw, LangChain, etc.)

    ┌─────┴─────┐
    │ MCP Server │──── REST API
    └─────┬─────┘

    ┌─────┴──────────────┐
    │    Agent Runtime    │
    │ Observe→Think→Act  │
    │    (LLM-powered)   │
    └─────┬──────────────┘

    ┌─────┴──────────────┐
    │   Core Engine       │
    │ Wallet Manager      │
    │ Transaction Engine  │
    │ Security Guardrails │
    └─────┬──────────────┘

    Solana Devnet RPC

Layer Breakdown

Karen provides three ways for external systems to interact with the wallet infrastructure:MCP Server
  • Model Context Protocol server for AI assistants
  • Exposes 17 tools for wallet operations
  • Used by Claude Desktop, OpenClaw, and other MCP-compatible agents
  • Located in src/mcp/server.ts
REST API
  • HTTP endpoints for programmatic access
  • Bearer token authentication
  • Rate limiting and spending caps per API key
  • Located in src/api/server.ts
Direct SDK
  • Import Karen’s core modules directly into Node.js applications
  • Full programmatic control over all components
  • Best for building custom agent platforms
The autonomous agent layer implements a continuous decision-making loop:Core Loop: Observe → Think → Act → Remember
  1. Observe - Gather current wallet state, balances, recent transactions
  2. Think - Send context to LLM with available skills and strategy
  3. Act - Execute the chosen skill via the skill registry
  4. Remember - Persist decision and outcome to memory for future context
Components:
  • AgentRuntime (src/agent/runtime.ts) - Main agent execution loop
  • Orchestrator (src/agent/orchestrator.ts) - Manages multiple concurrent agents
  • MemoryStore (src/agent/memory/memory-store.ts) - Persistent decision history
  • SkillRegistry (src/agent/skills/index.ts) - 17 pluggable agent capabilities
The foundational wallet and transaction infrastructure:Wallet Manager (src/core/wallet/wallet-manager.ts)
  • Create wallets with HD derivation (BIP-44)
  • Secure keystore encryption (AES-256-GCM)
  • Balance queries for SOL and SPL tokens
Transaction Engine (src/core/transaction/transaction-engine.ts)
  • Build, sign, and send transactions
  • Automatic guardrail validation
  • Comprehensive audit logging
Security Guardrails (src/core/transaction/guardrails.ts)
  • Per-transaction spending limits
  • Rate limiting (transactions per minute)
  • Daily spending caps
  • Program allowlists
  • Address blocklists
Audit Logger (src/core/audit-logger.ts)
  • JSONL append-only logs for all transactions
  • Agent decision tracking
  • Event streaming for monitoring
High-level interfaces for DeFi protocols:
  • JupiterAdapter - Token swaps via Jupiter DEX aggregator
  • TokenLauncherAdapter - Create and manage SPL tokens
  • StakingAdapter - Native SOL staking to validators
  • SplTokenAdapter - SPL token operations (burn, close, freeze)
  • WrappedSolAdapter - Wrap/unwrap SOL to wSOL
Located in src/protocols/

Directory Structure

karen/
├── src/
│   ├── core/                 # Core wallet & transaction infrastructure
│   │   ├── wallet/           # WalletManager, Keystore, HD derivation
│   │   ├── transaction/      # TransactionEngine, Guardrails
│   │   ├── solana/           # RPC connection management
│   │   ├── audit-logger.ts   # Transaction & event logging
│   │   └── types.ts          # TypeScript type definitions
│   │
│   ├── agent/                # Autonomous agent runtime
│   │   ├── llm/              # LLM provider adapters (OpenAI, Anthropic, etc.)
│   │   ├── skills/           # 17 pluggable agent skills
│   │   ├── memory/           # Persistent agent memory store
│   │   ├── runtime.ts        # Agent execution loop
│   │   └── orchestrator.ts   # Multi-agent management
│   │
│   ├── protocols/            # DeFi protocol adapters
│   │   ├── jupiter.ts        # Jupiter DEX swaps
│   │   ├── spl-token.ts      # SPL token operations
│   │   ├── token-launcher.ts # Token creation & minting
│   │   ├── staking.ts        # Native SOL staking
│   │   └── wrapped-sol.ts    # wSOL wrapping
│   │
│   ├── api/                  # REST API server
│   ├── mcp/                  # MCP server
│   └── cli/                  # CLI interface

├── dashboard/                # Next.js monitoring dashboard
├── data/                     # Runtime data (keystores, logs, memory)
│   ├── keystores/            # Encrypted wallet files
│   ├── logs/                 # Audit logs (JSONL)
│   └── memory/               # Agent memory (JSON)
└── SKILLS.md                 # Agent skill reference

Integration Methods

Data Flow Example

Here’s what happens when an agent decides to swap SOL for USDC:
  1. Agent Runtime observes current wallet state (2 SOL, 0 USDC)
  2. LLM Provider receives context + available skills, decides to invoke swap
  3. Skill Registry executes the swap skill with parameters {inputToken: "SOL", outputToken: "USDC", amount: 0.5}
  4. Jupiter Adapter fetches a quote and builds the swap transaction
  5. Transaction Engine validates against guardrails (spending limit, rate limit, program allowlist)
  6. Wallet Manager decrypts the keypair to sign the transaction
  7. Solana RPC broadcasts the signed transaction
  8. Audit Logger records the transaction details
  9. Memory Store persists the decision + outcome for future context
  10. Agent proceeds to next cycle
All Karen operations run on Solana Devnet by default. To use mainnet, update the RPC URL in src/core/solana/connection.ts.

Next Steps

Wallets

Learn about HD derivation, keystore encryption, and wallet management

Agents

Understand the agent runtime, LLM integration, and decision-making loop

Security

Explore guardrails, spending limits, and audit logging

Quick Start

Get Karen running in 5 minutes

Build docs developers (and LLMs) love