Skip to content

Repository files navigation

Anubis Agent

Anubis Agent ⚖️

Python 3.12+ LangGraph DeepSeek 2700+ tests License: MIT 中文

A deep research agent kernel with long-term memory. Every claim is weighed on the scales of evidence before it is reported. The kernel is middleware-first: memory, skills, sandbox, context governance, and reflection are pluggable cross-cutting concerns layered around a ReAct loop — not embedded agent logic. Each layer is independently designed, independently tested, independently verifiable, guarded by 2,700+ tests.


Highlights

A real terminal interfaceFull-screen TUI (Textual) with side panel, live token usage in the status bar, slash-command palette, and settings screen — plus a traditional scrolling CLI (prompt_toolkit + rich) and a one-shot anubis run mode.
Five-layer long-term memoryCognitive-science-inspired memory: Ebbinghaus decay with lazy strength computation (no background tasks), BM25 hybrid retrieval with write-back reinforcement, per-call HumanMessage recall injection that protects prompt caching, and non-blocking auto-consolidation that logs-and-skips instead of blocking the loop.
Context engineering governanceA live token budget resolved against the real model window at call time — no hardcoded thresholds. Dual strategies (compaction + externalization) keep long research sessions from overflowing without losing critical information.
Delegates and parallelizesRoute sub-tasks to external specialists (pi / codex / claude) via MCP, or spawn self-copy subagents with isolated context that share the parent's Docker sandbox — same artifacts, zero re-acquisition.
Sandbox isolation with path enforcementDocker and local providers. Write-path whitelisting forces agent output into the mount area — nothing is lost to --rm. Warm pool, idle auto-destroy, cross-process lock, WSL2 executor.
A closed skill-evolution loopSkills are prompt-level research knowledge bundles (not executable functions). When the effective rate drops below threshold, LLM-driven mutation runs through score gating and GitRatchet rollback — evolution can only move forward.
Use any model, degrade gracefullyRole-based routing chain (researcher / reporter) with automatic fallback on rate limits, timeouts, and 5xx — DeepSeek always sits at the chain tail as the ultimate fallback.
Evaluable by design2,700+ tests guard every layer independently. A structured run journal records skill selections, memory encodes, compactions, and token budgets for post-hoc analysis.

How It Works

flowchart LR
    U["Question"] --> P[prepare] --> L["LeaderAgent<br/>ReAct Loop"] --> F[finalize] --> A["Answer + Evidence"]
    subgraph MW["22 Middleware · every lifecycle hook"]
        direction TB
        BM[before_model<br/>memory recall · skill injection] --> M[model call]
        M --> AM[after_model<br/>consolidation · context governance]
    end
    L <--> MW
    MW --> T[tool calls]
    T --> SB["Docker Sandbox<br/>path-guarded"]
    T --> MC["MCP Servers<br/>stdio / sse / http"]
    T --> BT["Builtin Tools<br/>ddg · files · skills"]
Loading

The Five-Layer Memory Stack

flowchart TB
    L5["L5 · Auto-Consolidation<br/>daemon worker · queue · log-and-skip"] -->|"every N turns"| L4
    L4["L4 · Middleware + Bootstrap<br/>per-call HumanMessage · set_turn_id"] -->|"recall"| L3
    L3["L3 · Store + Retriever<br/>MarkdownFileStore · BM25 · write-back reinforce"] -->|"strategies"| L2
    L2["L2 · Default Strategies<br/>Ebbinghaus decay · lazy strength · forgotten filter"] -->|"schema"| L1
    L1["L1 · Schema + Protocol<br/>MemoryTrace · 5 atomic ops · tools have no LLM"]
Loading

Memory strength is computed lazily at retrieve time — no background tasks, no scheduler to babysit:

strength = base × (1 − decay)^hours + log(1 + access) × 0.1 + importance × 0.05

Quick Start

Requirements: Python 3.12+, optional Docker for the sandbox provider.

git clone https://github.com/fxl112233/anubis-agent.git
cd anubis-agent
pip install -e .

# First run (or anytime .env is missing) launches a setup wizard.
# Alternatively, copy the template and fill in at least one provider key:
cp .env.example .env

# Full-screen TUI (default)
anubis

# Traditional scrolling CLI
anubis cli

# One-shot deep research, then exit
anubis run "Compare LK-99 replication attempts since 2024" --no-expert

CLI Usage

Command Description
anubis Full-screen TUI (Textual): conversation + side panel, live token status bar, / command palette
anubis cli Scrolling CLI with rich streaming and slash-command completion
anubis run "<question>" One-shot research run; prints the final report and run ID. --expert (default) enables deep-research mode, --no-expert is lightweight
anubis run ... --thread-id <id> Continue an existing research thread
anubis run ... --no-artifact Skip writing the final report file

Slash Commands (chat modes)

Command Description
/expert / /default Switch between deep-research and lightweight modes (thread state is kept)
/model <provider> [model] Hot-swap the LLM mid-session
/report Manually trigger report synthesis
/skill <name> Override the active skill set
/mcp reload Reload MCP tools without restarting
/help, /exit Show all commands / quit

Configuration

All configuration lives in .env (template: .env.example). At least one provider key is required; each provider can be disabled with {NAME}_ENABLED=false and its default model overridden with {NAME}_MODEL.

Provider Env var Notes
DeepSeek DEEPSEEK_API_KEY Default provider; tail of every fallback chain
OpenAI OPENAI_API_KEY Any OpenAI-compatible base URL supported
Qwen QWEN_API_KEY OpenAI-compatible endpoint
Anthropic Claude ANTHROPIC_API_KEY Requires pip install langchain-anthropic
Google Gemini GEMINI_API_KEY Requires pip install langchain-google-genai
Moonshot / Kimi MOONSHOT_API_KEY OpenAI-compatible endpoint

Model behavior profiles (routing, budgets, expert mode) live in anubis/backend/agents/config/profiles/: fast.yaml, general.yaml, expert.yaml.

Project Layout

anubis/backend/
├── app/                  # CLI, TUI (Textual), setup wizard, stream services
├── agents/
│   ├── leader/           # LeaderAgent ReAct loop + prompts
│   ├── middlewares/      # 22 lifecycle middlewares (memory, skills, governance…)
│   ├── memory/           # five-layer long-term memory stack
│   ├── context_engineering/  # live token budget, compaction + externalization
│   ├── skill/            # builtin skills + closed evolution loop
│   ├── multiagent/       # MCP delegation, self-copy subagents, specialist runtimes
│   ├── sandbox/          # Docker/local sandboxes with path enforcement
│   ├── mcp/              # MCP client, loader, health, credential guards
│   ├── config/           # provider config, model router, fallback chain
│   ├── reporting/        # report synthesis
│   ├── journal/          # structured run journal
│   └── observability/    # events and traces
└── tests/                # 2,700+ tests across every layer

Development

# Full test suite
pytest

# Run a single layer (unit tests are organized per module)
pytest anubis/backend/tests/v1/unit/memory

# Integration tests (CLI chat/run, agent loop e2e)
pytest anubis/backend/tests/v1/integration

License

MIT License — 随意使用、修改、商用,保留 License 声明即可。

如果这个项目对你有帮助,欢迎点个 ⭐ Star

有问题欢迎提 Issue

About

Anubis agent framework

Resources

Stars

65 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages