Skip to content

SebaWag/confucius-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ›๏ธ Confucius Agent

Hierarchical Memory for AI Agents on Qwen Cloud

"Not all context is equal." โ€” Confucius Paper (Meta + Harvard, arXiv:2512.10398)

Live Demo ย  GitHub ย  Paper


๐Ÿ† Global AI Hackathon Series with Qwen Cloud โ€” Track: MemoryAgent

Confucius Agent implements the 3-tier hierarchical memory system from the Confucius paper on top of Qwen Cloud. Unlike traditional RAG that treats all context equally, our architecture distinguishes between:

Tier Priority Type Storage Description
๐Ÿ›๏ธ Mental Models ๐Ÿ”ด Highest Canonical knowledge ChromaDB + Vector Search Company policies, rules, verified facts
๐Ÿ“ Observations ๐ŸŸก Medium Persistent learnings PostgreSQL + Time-index Patterns, decisions, notes from sessions
๐Ÿ“ฆ Raw Facts ๐ŸŸข Lowest Ephemeral context Redis + TTL decay Conversation logs, temporary data

Result: An agent that never contradicts itself, reduces token consumption by up to 60%, and retrieves relevant information in milliseconds.


๐ŸŽฎ Live Demo

๐Ÿš€ Try it now without installing anything:
๐Ÿ‘‰ https://confucius.wagnersolutionsai.com

Upload documents, chat with the agent, and inspect the 3-tier memory in real time.


๐Ÿš€ Quick Start

Prerequisites

  • Python 3.12+
  • Docker & Docker Compose
  • Qwen Cloud API key (or any OpenAI-compatible API for dev)

1. Clone & Setup

git clone https://github.com/your-org/confucius-agent.git
cd confucius-agent
cp .env.example .env
# Edit .env with your API keys

2. Start Infrastructure

docker compose up -d

Starts: Redis (Raw Facts), PostgreSQL (Observations), ChromaDB (Mental Models)

3. Run Demo

pip install -r requirements.txt
streamlit run demo/app.py

4. Chat with the Agent

Open http://localhost:8501 and ask anything. The agent:

  1. ๐Ÿ›๏ธ Checks Mental Models first (canonical truth)
  2. ๐Ÿ“ Queries Observations (past learnings)
  3. ๐Ÿ“ฆ Reviews Raw Facts (current context)
  4. ๐Ÿง  Answers with priority-ranked knowledge

๐Ÿ“ Project Structure

confucius-agent/
โ”œโ”€โ”€ confucius/                  # Core library
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ config.py               # Dual API config (Qwen โ†” Fallback)
โ”‚   โ”œโ”€โ”€ qwen_client.py          # OpenAI-compatible client
โ”‚   โ”œโ”€โ”€ agent.py                # Main agent with tool calling
โ”‚   โ””โ”€โ”€ memory/
โ”‚       โ”œโ”€โ”€ mental_models.py    # Layer 1: ChromaDB + embeddings
โ”‚       โ”œโ”€โ”€ observations.py     # Layer 2: PostgreSQL + time-index
โ”‚       โ”œโ”€โ”€ raw_facts.py        # Layer 3: Redis + TTL decay
โ”‚       โ””โ”€โ”€ retrieval_pipeline.py  # Priority-based orchestrator
โ”œโ”€โ”€ demo/
โ”‚   โ””โ”€โ”€ app.py                  # Streamlit interface
โ”œโ”€โ”€ tests/                      # Test suite
โ”œโ”€โ”€ docker-compose.yml          # Infrastructure as code
โ”œโ”€โ”€ Dockerfile                  # Demo container
โ””โ”€โ”€ requirements.txt            # Python dependencies

๐Ÿ”„ Dual API Mode

Develop with any OpenAI-compatible API (DeepSeek, Kimi, OpenAI), then switch to Qwen Cloud for submission:

# In .env:
API_MODE=fallback                    # Use during development
FALLBACK_API_KEY=sk-...              # Your dev API key
FALLBACK_BASE_URL=https://api.deepseek.com/v1

# Switch to Qwen Cloud for submission:
API_MODE=qwen
QWEN_API_KEY=sk-...                  # Qwen Cloud hackathon credits
QWEN_BASE_URL=https://dashscope-intl.aliyuncs.com/compatible-mode/v1

๐Ÿ“Š Memory Retrieval Pipeline

User Query
    โ”‚
    โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚       Parallel Query All Tiers          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  ๐Ÿ›๏ธ Mental     โ”‚ ๐Ÿ“ Obser-  โ”‚ ๐Ÿ“ฆ Raw    โ”‚
โ”‚  Models        โ”‚ vations    โ”‚ Facts     โ”‚
โ”‚  (ChromaDB)    โ”‚ (Postgres) โ”‚ (Redis)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜
        โ”‚              โ”‚            โ”‚
        โ–ผ              โ–ผ            โ–ผ
    Priority      Recency       TTL-based
    Score +      Weight ร—      Age Check
    Threshold    Confidence
        โ”‚              โ”‚            โ”‚
        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                    โ”‚
                    โ–ผ
        Ranked Context (by priority)
                    โ”‚
                    โ–ผ
        LLM (Qwen Cloud) โ†’ Response

๐Ÿงช Testing

pytest tests/ -v

๐Ÿ“ License

MIT โ€” Open source for the Qwen Cloud Global AI Hackathon 2026

Built with โค๏ธ by Wagner Solutions AI for the MemoryAgent track.

About

๐Ÿ›๏ธ Hierarchical Memory for AI Agents โ€” 3-tier memory (Mental Models, Observations, Raw Facts) on Qwen Cloud. Built for the Global AI Hackathon 2026 MemoryAgent track.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors