Skip to content

Architecture Overview

y-agent is organized into 7 architectural layers, from user-facing clients down to persistent infrastructure.

System Diagram

Layer Responsibilities

LayerPurpose
ClientThin I/O wrappers -- CLI, TUI, Tauri GUI, REST API, bot adapters
ServiceBusiness logic -- Chat, Agent, Bot, Workflow, Knowledge, Skill, Scheduler, Cost, Diagnostics, System; DI container (ServiceContainer)
CoreRequest routing, agent orchestration, DAG engine with typed channels and checkpointing
Middleware5-domain middleware chains (Context, Tool, LLM, Compaction, Memory), guardrails, async event bus
ExecutionLLM provider pool with tag routing/failover/freeze-thaw, tool registry (builtin + dynamic + MCP + browser), sandboxed runtimes (Native/Docker/SSH)
StateSession tree, three-tier memory (STM / LTM / WM), skill registry with versioning, knowledge base with hybrid retrieval, file journal with rollback
InfrastructureSQLite (sessions, checkpoints, transcripts, traces, schedules, workflows, provider metrics), Qdrant (semantic vector search for memory and knowledge)

Design Principles

  1. Trait-driven contracts -- All inter-crate communication via y-core traits
  2. Middleware-first -- Cross-cutting concerns (guardrails, logging, journaling) as middleware in 5 chains
  3. Lazy loading -- Tools and skills loaded on demand to minimize context window usage
  4. Checkpoint everything -- DAG execution state persisted at every step for crash recovery
  5. Service-layer ownership -- All business logic in y-service; presentation crates are thin I/O wrappers

Chat Request Lifecycle

User Input
  -> CLI / GUI / API (parse, validate)
  -> Session (load/create via SessionManager)
  -> Context Assembly (8-stage pipeline)
    1. BuildSystemPrompt
    2. InjectBootstrap
    3. InjectMemory
    4. InjectKnowledge
    5. InjectSkills
    6. InjectTools
    7. LoadHistory
    8. InjectContextStatus
  -> LLM Provider (chat completion via ProviderPool)
  -> Tool Dispatch (if tool calls present)
    -> Multi-format parser (OpenAI, DeepSeek, MiniMax, GLM4, Qwen3Coder, ...)
    -> JSON Schema validation
    -> Guardrail check (permission + risk scoring)
    -> File journal capture (if file-mutating)
    -> Runtime execution (Native / Docker)
    -> Result formatting and injection
  -> Loop back to LLM (if needed)
  -> Response to user
  -> Transcript save
  -> Memory extraction (async)
  -> Diagnostics trace recording

Key Traits (y-core)

TraitModulePurpose
LlmProviderproviderLLM API abstraction (chat completion, streaming)
ProviderPoolproviderTag-based provider routing and failover
TooltoolTool execution contract
ToolRegistrytoolTool discovery, lookup, and search
MiddlewarehookChain-based data transformation (priority-sorted)
HookHandlerhookLifecycle event observers
EventSubscriberhookAsync event bus subscriber
HookLlmRunnerhookLLM execution within hook handlers
HookAgentRunnerhookAgent execution within hook handlers
RuntimeAdapterruntimeSandboxed execution backend
CommandRunnerruntimeShell command execution
SessionStoresessionSession metadata CRUD
TranscriptStoresessionMessage history persistence
DisplayTranscriptStoresessionFormatted transcript for display
ChatCheckpointStoresessionTurn-level checkpoint and rollback
ChatMessageStoresessionChat message persistence
CheckpointStoragecheckpointWorkflow checkpoint persistence
MemoryClientmemoryMemory read/write operations
ExperienceStorememoryExperience capture for skill evolution
SkillRegistryskillSkill discovery, search, loading
EmbeddingProviderembeddingVector embedding generation
AgentDelegatoragentMulti-agent delegation protocol
AgentRunneragentSingle-turn agent execution
ClassifiedErrorerrorError classification for retry/reporting
RedactableerrorSecret redaction in error messages

Storage Architecture

BackendPurposeData
SQLiteOperational stateSessions, checkpoints, transcripts, traces, costs, schedules, workflows, provider metrics
QdrantSemantic searchMemory embeddings, knowledge base vectors

Released under the MIT License.