Architecture
Yunque Agent is a modular AI agent runtime with 40+ core modules, all wired in cmd/agent/main.go. It uses a "control plane + execution plane" dual-layer architecture, decoupling the cognitive engine from external integrations.
Request Flow
HTTP / WebSocket / IM Channel → Gateway (Auth · CORS · Rate-limit · RBAC)
→ Guardrails (Input: PII redaction · Injection detection · Shell Guard)
→ Session Manager (History load · Fork/Branch)
→ Smart Router (Model selection by complexity: fast / smart / expert)
→ Cost Tracker (Budget check · Real-time billing)
→ Context Manager (Token budget · Compression · Sliding window)
→ Planner (LLM planning loop + Memory + Knowledge RAG + Skill orchestration)
→ Guardrails (Output: PII redaction · Content filter)
→ Memory Pipeline (Async fact extraction → 5-layer memory)
→ Audit Trail (Merkle immutable log)
→ Reflection Loop (Experience accumulation → Strategy compilation)Core Modules
Cognitive Layer (agentcore)
| Module | Function |
|---|---|
| llm | LLM client, streaming, provider registry, circuit breaker |
| planner | Multi-step planning loop, skill orchestration, emotion-aware, Reverie |
| memory | 5-layer memory (short/mid/long/editable/knowledge graph) |
| knowledge | Hybrid RAG: BM25 + vector + RRF + Rerank |
| skills | Skill registry, execution, parameter validation |
| skillmarket | Skill installation, ClawHub/ToriHub market, SkillFileLoader |
| emotion | Emotion analysis, history, sticker mapping |
| persona | Persona chain, feature switches, templates |
| task | Task lifecycle, thread management, working memory |
| workflow | DAG workflow engine, conditional branching, parallel execution |
Security & Governance
| Module | Function |
|---|---|
| guardrails | Content safety, PII redaction, injection detection, Shell Guard |
| audit | Merkle chain immutable audit log |
| trust | Trust score system, progressive permissions |
| approval | High-risk operation approval, 4-tier risk classification |
| rbac | Role-based access control, 4-level inheritance |
Execution Layer
| Module | Function |
|---|---|
| channel | 16+ IM channel adapters with resilience wrappers |
| sandbox | Code sandbox (process/Docker/K8s/Wasm), E2B Desktop |
| scheduler | Task scheduler, Q-Learning optimization |
Directory Structure
internal/
├── agentcore/ # 40+ cognitive modules
├── controlplane/ # HTTP/WS API gateway
├── execution/ # Sandbox, scheduler, 16+ channel adapters
├── experimental/ # Reflection, distillation, causal chains
├── storage/ # SQLite storage layer
├── ledger/ # KV storage + persistence bridge
cmd/agent/ # Entry point
plugins/ # Go skill plugins
pkg/ # Shared libraries (plugin loader, skills)
data/
├── plugins/ # Script plugins (Python/Node/Shell)
├── skills/ # File-based skills (SKILL.md)
└── knowledge/ # Knowledge base documents
heroui-web/ # HeroUI v3 + Next.js dashboard
docs/ # VitePress documentation