Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Crate Reference

Koyal is an 11-crate Cargo workspace plus the root CLI/library package. Strict dependency layering is validated by scripts/ci/check_workspace_contract.sh on every CI run.


Dependency Graph

koyal-api                                      (no heavy deps)
  ↑
  ├── koyal-config        (api)
  ├── koyal-memory        (api)
  ├── koyal-chains        (api)
  ├── koyal-dexes         (api + chains)
  ├── koyal-exchanges     (api)
  ├── koyal-providers     (api + config)
  ├── koyal-core          (api + memory)
  └── koyal-runtime       (api + config + memory + providers + core)
         ↑
         ├── koyal-gateway        (api + config + core + runtime + integrations)
         └── koyal-integrations   (api + config + runtime)
                ↑
                └── koyal            (CLI facade — depends on everything)

koyal-api — Public Traits

Zero heavy dependencies. Every other crate depends on this one. Defines all trait boundaries.

Trait / TypeFilePurpose
AgentHarnessharness.rsTick engine — tick(), capabilities(), supports()
ModelProviderprovider.rsAI provider interface — call(), health_check(), capabilities()
Memorymemory.rsStorage — store(), recall(), forget(), prefetch(), sync_turn()
TradingExecutorHandlerexecutor.rsDEX executor — execute(), validate(), lifecycle
Tooltool.rsAgent tool interface — execute(), schema(), is_read_only()
ApprovalDecisionapproval.rsPermission result: Allow, Deny(String), Prompt{request_id}
ClassifiedErrorerror.rsError taxonomy: 15 FailoverReason values with recovery hints
ManagedAgentagent_types.rsAgent + Bot + Loop + Executor + Wallet data types

koyal-config — Configuration

FilePurpose
schema.rsAppConfig — env-driven with dotenvy, serde derive
frontmatter.rsYAML frontmatter parser for legacy agent.md files

Environment variables: AI_GATEWAY, AI_MODEL, OPENAI_API_KEY, ANTHROPIC_API_KEY, SOLANA_RPC_URL, SOLANA_KEYPAIR_PATH, etc.


koyal-memory — Persistence

FilePurpose
sqlite.rsSqliteMemory — rusqlite with FTS5 full-text search, WAL mode, agent isolation
store.rsAgentMemory — high-level memory operations
jsonl.rsAppend-only JSONL for audit-compatible trade ledgers
journal.rsStructured journal.md writer
learnings_store.rslearnings.md with word-overlap deduplication
positions.rsDerive positions from trade ledger
vault.rsMarkdownVault — agent bible manager (soul, instructions, memories, bots)

koyal-providers — AI Providers

FilePurpose
lib.rsresolve_provider() — priority-based provider selection
openai.rsOpenAI Chat Completions
anthropic.rsAnthropic Messages API
catalog.rs55+ provider presets (OpenRouter, DeepSeek, Groq, Together, etc.)
auth_store.rsAES-256-GCM encrypted credential vault
model_router.rsFailover chain with circuit breaker
health_monitor.rsPeriodic provider health pings
secret_mask.rsAPI key redaction for safe logging
usage_store.rsToken/latency usage tracking

koyal-core — Stores and Types

In-memory stores for the runtime state:

StorePurpose
ManagedAgentStoreAgent registry
BotStoreBot registry, scoped by agent
AgentLoopStoreLoop definitions and state
TradeStoreTrade proposal queue
OrderStoreExecutor order tracking
WalletStoreWallet registry
SettingsStoreRuntime settings key-value
LogStoreStructured log buffer
McpServerStoreMCP server registry
ConnectionStoreIntegration connections

koyal-chains — Chain Protocols

ModulePurpose
solana/Solana RPC client, transaction signing, Ed25519 keys
evm/alloy provider, SECP256k1 signing, multi-chain RPC
wallet.rsBIP39 mnemonic generation, BIP32 derivation

koyal-dexes — DEX Integrations

ModulePurpose
jupiter/Jupiter v6 swap API — quote, route, execute
uniswap/Uniswap v3 SDK + v4 SDK wrappers

koyal-exchanges — Centralized / Perp Venues

ModulePurpose
hyperliquid/hyperliquid-rust-sdk + hypersdk. Orders, positions, leverage.
polymarket/polymarket-client-sdk. Market queries, CLOB orders.

koyal-runtime — Tick Engine

The core execution engine.

FilePurpose
harness.rsCoreHarness — coordinates everything
tick.rsSingle agent tick: load bible → RAG recall → provider call → approval check → execute
permission.rsPermissionEngine — bot policies, wallet roles, scoped authorize
approval.rsApproval flow manager
scheduler.rsCron scheduler for loops
skills/SkillRegistry — load, state, pin/unpin
guardrails.rsPre/post tick safety checks

koyal-gateway — HTTP API

Axum-based HTTP gateway.

FilePurpose
lib.rsAppState, create_router_with_state(), start_server()
routes.rsAll 50+ route handlers
static_files.rsServes web/dist/ — SPA fallback, asset caching
mcp.rsMCP server — harness_tools(), dispatch_mcp_call()
connectors.rsIntegration connector catalog and defaults
setup.rsSetup checklist logic

koyal-integrations — Loop Blueprints and Channels

ModulePurpose
loops/blueprints.rsBuilt-in loop blueprints: price_watcher, wallet_monitor, etc.
loops/runner.rsLoop execution runner
telegram/Telegram bot, sender pairing, channel provisioning
webhook/Outbound webhook integration
metrics/Prometheus metrics export
polymarket/Polymarket integration hooks

koyal — CLI

Root package. Thin facade over the workspace crates.

FilePurpose
src/lib.rsCommands enum (clap derive), all subcommand enums
src/main.rsmain() — parse args, dispatch to crates
src/gateway/mod.rsRe-exports from koyal-gateway