Agent Layer
22 Personas
🔄 Agent Loop
Core execution: LLM call, tool parse, execute, stream. Up to 200 turns.
Agent Loop
The heart of Waggle. Sends messages to LLM, parses tool calls, executes them through capability routing, and streams results via SSE. Supports approval gates, cost tracking, and loop guards.
packages/agent/src/agent-loop.ts
🎯 Orchestrator
Builds system prompt, recalls memory, assembles context per turn.
Orchestrator
Constructs the system prompt from persona + behavioral spec + skills + recalled memory. Calls recallMemory() to fuse personal and workspace mind results into context.
packages/agent/src/orchestrator.ts
🧰 97+ Tools
12 categories: system, memory, web, git, plan, doc, sub-agent, skill, KVARK, team, audit, connector.
Tool System
Organized across 12 categories. Each tool follows the ToolDefinition interface. Sensitive tools go through approval gates. Tool pool is filtered per-persona via allowlist + denylist.
packages/agent/src/tool-filter.ts
⚡ GEPA Optimizer
Prompt expansion and optimization engine. Iterative refinement with constraint gates.
GEPA (Guided Expansion Prompt Algorithm)
Expands terse user prompts into detailed, high-quality instructions. Iterative refinement with constraint gates ensures quality. Core to the self-evolution stack.
packages/optimizer/
🛡 Behavioral Spec
Safety rules, disclaimer logic, persona constraints. Non-negotiable agent boundaries.
Behavioral Specification
Defines the non-negotiable rules all agents follow. Includes memory-conflict handling (CRITICAL), disclaimer requirements, and persona-specific behavioral constraints.
packages/agent/src/behavioral-spec.ts
🔍 Injection Scanner
3 pattern sets for prompt injection defense on all external input.
Injection Scanner
scanForInjection() runs 3 pattern sets against all connector and external input. Mandatory security gate — never bypass.
packages/agent/src/injection-scanner.ts
22 Personas
Researcher
Writer
Analyst
Coder
PM
Exec Asst
Sales
Marketer
Product
HR
Legal
Finance
Consultant
General
Planner
Verifier
Coordinator
Support
Designer
Educator
Translator
DevOps
Intelligence Layer
Self-Evolution
Self-Evolution Pipeline (closed loop)
TraceRecorder
→
EvalDataset
→
LLM Judge
→
GEPA
→
EvolveSchema
→
Gates
→
Deploy
Result: Gemma 4 + Waggle-evolved prompts scored higher than raw Opus 4.6 by all 4 blind judges (C/A ratio: 108.8%)
🎭 Workflow Harness
research-verify, code-review-fix, document-draft templates.
Workflow Harness
Bridges workflow templates to the evolution system. Traces flow through the harness into the TraceRecorder for continuous improvement of multi-step workflows.
packages/agent/src/workflow-harness.ts
💡 Skill Extraction
Auto-extract patterns. Promote: personal, workspace, team, enterprise.
Skill Auto-Extraction + Promotion
Detects recurring patterns in agent behavior and promotes them through a 4-level hierarchy: personal skill, workspace skill, team skill, enterprise skill.
packages/agent/src/skill-frontmatter.ts
💲 Cost Tracker
Per-model pricing, session budgets, token accounting.
Cost Tracker
Tracks token usage and costs per model. Supports session-level budget caps. Includes pricing table for all supported models.
packages/agent/src/cost-tracker.ts
🚫 Loop Guard
Detects and breaks infinite loops in agent execution.
Loop Guard
Monitors agent execution patterns for repetitive tool calls or circular reasoning. Breaks infinite loops before they consume budget.
packages/agent/src/loop-guard.ts
Memory Layer
SQLite + sqlite-vec
💾 FrameStore
I/P/B frames grouped by GOP. Append-only event log with compaction and dedup.
FrameStore (I/P/B Frames)
Memory is stored as frames: I-frames (complete snapshots), P-frames (deltas), B-frames (bidirectional refs). Grouped by GOP (Group of Pictures) for efficient retrieval. Supports compaction, dedup, and importance scoring.
packages/core/src/mind/frames.ts
🔍 HybridSearch
FTS5 + vec0 fused via Reciprocal Rank Fusion. Configurable scoring profiles.
HybridSearch (FTS5 + Vector)
Combines full-text search (FTS5 with porter + unicode61 tokenizer) and vector similarity search (vec0 with 1024-dim embeddings) using Reciprocal Rank Fusion. Re-ranked by configurable scoring profiles.
packages/core/src/mind/search.ts
🕸 KnowledgeGraph
Typed entities and relations with bitemporal validity (valid_from/valid_to).
KnowledgeGraph
Entity-relation graph with typed nodes and edges. Supports temporal validity windows (bitemporal) and confidence scoring. The structured distillation of the frame log.
packages/core/src/mind/knowledge.ts
👤 IdentityLayer
Single-row table: name, role, personality, capabilities. Injected into system prompt.
IdentityLayer
Persists who this mind is. Single row with name, role, department, personality, capabilities. toContext() output is pasted directly into the agent system prompt.
packages/core/src/mind/identity.ts
📡 AwarenessLayer
10 rolling items: current tasks, goals, active context. Real-time state.
AwarenessLayer
Tracks what the mind is currently working on. Maximum 10 rolling items with category constraints. Provides real-time context about active tasks and goals.
packages/core/src/mind/awareness.ts
📖 Wiki Compiler
Compiles memory into wiki pages. Entity, concept, and synthesis pages with incremental compilation.
Wiki Compiler
Transforms raw memory frames into structured wiki pages. 4 adapters (md/txt/pdf/url). Entity pages, concept pages, and LLM-synthesized summary pages. Incremental compilation with health reports.
packages/wiki-compiler/
FTS5 keyword
+
vec0 semantic
=
Reciprocal Rank Fusion
FREE FOREVER
— Memory + agents are the lock-in moat. Never paywalled.
Harvest Layer
11 Adapters
Source Adapters
ChatGPT
Claude
Claude Code
Gemini
Perplexity
Markdown
Plaintext
PDF
URL
Universal
🛡 Injection Scanner
Security gate: all imported content scanned for prompt injection.
Injection Scanner (Security Gate)
Every piece of harvested content passes through scanForInjection() with 3 pattern sets before entering the memory substrate. Non-negotiable security boundary.
packages/agent/src/injection-scanner.ts
🔃 Dedup Pipeline
Content-hash deduplication prevents duplicate memory frames.
Deduplication Pipeline
SHA-256 content hashing detects and prevents duplicate frames from being stored. Runs as part of the harvest pipeline before frame insertion.
packages/core/src/harvest/dedup.ts
🧪 Cognify
Memory extraction pipeline. Classifies and structures harvested knowledge.
Cognify
Post-harvest processing that classifies imported content, extracts structured knowledge (entities, concepts, decisions), and routes it to the appropriate memory layer.
packages/agent/src/cognify.ts
→
Your AI history → Waggle memory
Import conversations from any AI platform. Every insight becomes searchable, persistent memory.
FREE FOREVER
— Harvest is the lock-in moat. Import everything, keep everything.
Infrastructure
Sidecar + LiteLLM
🚀 Fastify Sidecar
Node.js backend bundled into Tauri. 29 route modules. SSE streaming.
Fastify Sidecar
Node.js server running alongside the Tauri shell. Handles all API routes: chat, workspaces, sessions, memory, settings, vault, skills, marketplace, cron, fleet. Streams chat via SSE.
sidecar/ + packages/server/
🔀 LiteLLM Router
LLM routing layer. Model normalization, key resolution from vault.
LiteLLM Router
3-layer LLM routing: built-in proxy to LiteLLM to echo fallback. Normalizes model names across providers. Resolves API keys from the vault at call time.
litellm-config.yaml
🔒 Vault
AES-256-GCM encrypted secret storage. API keys, credentials, tokens.
Vault
Encrypted secret storage using AES-256-GCM. Stores API keys, connector credentials, and sensitive metadata. The ONLY place secrets live. Never committed to source.
packages/core/src/mind/vault.ts
📦 Marketplace
120+ packages. Skills, plugins, MCP servers. Security gate + FTS5 search.
Marketplace
SQLite-based catalog with 120+ packages across skills, plugins, and MCP servers. SecurityGate scans for dangerous patterns before install. Auto-seeded from bundled data.
packages/marketplace/
💃 WaggleDance
Multi-agent swarm coordination. Task dispatch, HiveQuery broadcast.
WaggleDance
Swarm orchestration protocol for multi-agent coordination. Includes task dispatcher (routes by capability/load), HiveQuery (broadcast queries across agents), and result collection.
packages/waggle-dance/
💳 Stripe Billing
Subscription management. Wired to tier enforcement.
Stripe Billing
Stripe SDK v21.0.1 installed. Handles subscription lifecycle: checkout, upgrade/downgrade, webhook processing. Wired to the 5-tier capability system.
stripe@^21.0.1 in package.json
🏭 KVARK Enterprise — On-Prem Sovereign AI
"Everything Waggle does — on your infrastructure, connected to all your internal systems. Full data pipeline injection, your permissions, complete audit trail, governance. Your data never leaves your perimeter."
ENTERPRISE
Consultative pricing — www.kvark.ai