Skip to content

System Architecture

y-agent follows a strict 6-layer architecture where dependencies always point inward. Each layer has a clear responsibility boundary.

Layer Diagram

Layer Responsibilities

1. Core (y-core)

The boundary-defining crate. Contains only trait definitions and shared types -- zero business logic.

TraitPurpose
LlmProviderchat_completion(), chat_completion_stream(), metadata()
ProviderPoolMulti-provider routing with freeze/thaw
Toolexecute(), definition(), check_permissions()
ToolRegistryTool index, search, register/unregister
RuntimeAdapterexecute(), spawn(), kill(), health_check()
Middlewareexecute(), chain_type(), priority()
AgentRunnerrun(AgentRunConfig) -> AgentRunOutput
AgentDelegatorCross-crate agent delegation without circular deps

Key types: Message, ChatRequest, ChatResponse, ToolDefinition, SessionNode, Memory, TokenUsage.

2. Infrastructure

Safely abstracts all external state. No business logic -- only persistence, retrieval, and protocol adaptation.

CrateResponsibility
y-providerLLM provider pool with tag-based routing, freeze/thaw failover, priority scheduling
y-sessionSession lifecycle state machine, tree traversal, transcripts
y-contextContext assembly pipeline, compaction engine, pruning, working memory
y-storageSQLite (WAL) backends, JSONL transcript writers, migration runner
y-knowledgeExternal knowledge ingestion, BM25 + vector hybrid retrieval, multi-resolution chunking
y-diagnosticsTrace storage, cost intelligence, search, replay

3. Middleware

Intercepts and transforms data flowing through the system.

CrateResponsibility
y-hooksMiddleware chain execution, event bus, hook registry
y-guardrailsLoop detection, permission model, taint tracking, risk scoring, HITL protocol
y-promptPrompt template engine with mode overlays, section budgets, lazy loading
y-mcpModel Context Protocol client (stdio + HTTP), tool adapter, connection manager

4. Capabilities

Discrete functional units.

CrateResponsibility
y-toolsTool registry (4 types), lazy activation (LRU), JSON Schema validation, multi-format parser
y-skillsSkill ingestion pipeline, content-addressable versioning, security screening, evolution capture
y-runtimeDocker / Native (bubblewrap) / SSH sandbox execution, resource monitoring, audit trail
y-schedulerCron / interval / one-time / event scheduling, concurrency policy, missed-run handling
y-browserChrome DevTools Protocol client, SSRF protection, search result extraction
y-journalFile mutation journaling, three-tier storage (inline / blob / git-ref), rollback

5. Orchestration

Coordination of agents and external platform adapters.

CrateResponsibility
y-agentDAG workflow engine, typed state channels, agent registry, delegation protocol, trust tiers
y-botFeishu / Discord / Telegram platform adapters, event parsing, message routing

6. Service (y-service)

The sole orchestration hub. All business logic lives here. ServiceContainer is the DI root that wires every domain service from config.

7. Presentation

Thin I/O wrappers. No domain logic.

CrateTransportDetails
y-clistdin/stdoutclap CLI + ratatui TUI, 15+ subcommands
y-webHTTPaxum REST API, SSE streaming, CORS
y-guiIPCTauri v2 + React 19, in-process ServiceContainer (zero network overhead)

Data Store Architecture

Dependency Rules

  1. All arrows point inward -- an outer layer may depend on an inner layer but never the reverse
  2. y-core has zero dependencies on other workspace crates
  3. Presentation crates depend only on y-service -- never on infrastructure or capabilities directly
  4. y-service is the only crate that may depend on all other layers
  5. Cross-layer peer dependencies (e.g., y-tools -> y-hooks) are permitted within the same layer or from outer to inner
  6. Every new subsystem must be behind a Cargo feature flag

Concurrency Model

y-agent is async-first on Tokio. Key concurrency patterns:

  • Provider pool: per-provider semaphores + optional global semaphore for system-wide concurrency cap
  • Agent pool: max_concurrent_agents (default 5) enforced via tokio::Semaphore
  • Tool execution: sequential within a turn (tool calls processed in order), parallel across agents
  • Session access: Arc<RwLock<...>> for shared state, optimistic locking for transcript writes
  • Event bus: tokio::broadcast channels for hook notifications
  • Cancellation: CancellationToken propagated through every async operation

Released under the MIT License.