Skip to content

incidentfox/self-learning-ai-agent

Repository files navigation

Self-Learning AI Agents

AI agents that learn from your team's Slack, meetings, docs, and code — and get smarter every day.

License

Add the bot to any Slack channel. It scans history, extracts knowledge, and starts answering questions — no manual setup required. New conversations are picked up daily, checked for conflicts with existing knowledge, and committed with human approval. The knowledge base just grows.

Under the hood: RAPTOR hierarchical trees, a knowledge graph, multi-strategy retrieval (semantic + BM25 + graph traversal), and 5 proactive behaviors that make the agent feel like a team member, not a search box.


Quick Start

git clone https://github.com/incidentfox/self-learning-ai-agent.git
cd self-learning-ai-agent

cp .env.example .env
# Edit .env — set OPENAI_API_KEY and ANTHROPIC_API_KEY

make dev          # Starts postgres + config-service + learning-engine + agent-service
make dev-slack    # Also starts slack-bot (needs SLACK_BOT_TOKEN + SLACK_APP_TOKEN)
make dev-web      # Also starts web-ui on http://localhost:3000

Prerequisites

  • Docker and Docker Compose
  • An OpenAI API key (for embeddings) + Anthropic API key (for completions)
  • For Slack: a Slack app with Socket Mode

What It Does

Self-Learning Loop

  1. Onboard — Bot scans channel history, extracts knowledge, builds a RAPTOR tree
  2. Answer — @mention the bot. It answers using multi-strategy RAG retrieval.
  3. Learn daily — New messages → extract → conflict check → auto-approve or queue for review
  4. Correct — Say "actually, it's X not Y" in a thread → bot detects and learns
  5. Escalate — Low confidence → asks designated buddies in a private channel

Proactive Behaviors

  • Daily digest — Summary of questions answered, knowledge learned, corrections
  • Stale knowledge alerts — Flags knowledge past its freshness threshold
  • Contradiction detection — Catches when new info conflicts with existing knowledge
  • Follow-up tracking — Reminds about open action items and decisions
  • Context surfacing — Proactively injects relevant context when discussions match existing knowledge

Use Cases

Every behavior is parameterized by the channel's use case:

Use Case Extraction Focus Staleness Example
Help Desk FAQs, resolution patterns, escalation paths 30 days Support channels
Engineering Architecture decisions, debugging patterns, conventions 90 days Engineering channels
Onboarding Processes, contacts, tool guides, tribal knowledge 60 days New hire channels
Chief of Staff Decisions, action items, blockers, competitive intel 14 days Strategy channels
Custom Describe your team → LLM generates prompts Configurable Anything

Architecture

Slack → slack-bot (Bolt) → agent-service (LLM + RAG) → learning-engine (RAPTOR + Knowledge Graph)
Web UI → agent-service ↗                    ↕
                                     config-service (PostgreSQL + pgvector)
Service Port Purpose
config-service 8001 Control plane: teams, channels, integrations, analytics
learning-engine 8002 Self-learning core: RAG, teaching, conflict resolution, pipelines
agent-service 8003 Chat agent with RAG tools, SSE streaming, public API
slack-bot 3001 Slack UI: OAuth, setup modals, chat, buddy escalation
web-ui 3000 Admin dashboard: knowledge explorer, analytics, chat
meeting-bot 8004 Meeting transcript processing (Recall.ai / Circleback)

Integrations

Connect data sources for automatic ingestion:

Integration What's Ingested Method
Slack Channel history, threads Onboarding scan + daily
GitHub README/docs, merged PRs Daily crawl
Notion Pages + block content OAuth or API key
Confluence Recently updated pages API key
Jira Issues (summary, status, assignee) API key
Linear Issues via GraphQL API key
Zoom/Meets Meeting transcripts Recall.ai / Circleback webhook

Slack App Setup

Option A: Import Manifest (Recommended)

  1. Go to api.slack.com/appsCreate New AppFrom a manifest
  2. Select your workspace
  3. Paste the contents of slack-app-manifest.yml
  4. Install to workspace
  5. Copy Bot User OAuth Token (xoxb-...) → SLACK_BOT_TOKEN in .env
  6. Go to Socket Mode → Enable → Create app-level token → copy (xapp-...) → SLACK_APP_TOKEN in .env

Option B: Manual Setup

Create a Slack app with these scopes:

Bot Token Scopes: app_mentions:read, channels:history, channels:read, chat:write, files:read, groups:history, groups:read, groups:write, im:history, im:read, im:write, reactions:write, users:read, commands

Event Subscriptions: app_mention, message.channels, message.groups, message.im, member_joined_channel, app_home_opened

Socket Mode: Enabled


Web UI

The admin dashboard at http://localhost:3000 provides:

  • Dashboard — Stats, activity feed, service health
  • Chat — Talk to the agent from your browser (SSE streaming)
  • Knowledge Base — Interactive RAPTOR tree visualization, search, detail panel
  • Teaching Queue — Review and approve/reject pending knowledge
  • Integrations — Connect and manage data sources
  • Analytics — Questions answered, confidence trends, knowledge growth
  • Feed Knowledge — Upload documents, paste URLs, or enter text directly

API

The agent-service exposes a public REST API:

# Query the knowledge base
curl -X POST http://localhost:8003/api/v1/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "What did we decide about pricing?", "team_id": "YOUR_TEAM_ID"}'

# Create an agent run
curl -X POST http://localhost:8003/api/v1/runs \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{"query": "Summarize this week", "mode": "fast"}'

Full API docs at http://localhost:8003/docs (OpenAPI / Swagger).


Deployment

Local Development

make dev           # Core services
make dev-slack     # + Slack bot
make dev-web       # + Web UI
make test-e2e      # Run E2E tests (requires running services)

Production (Docker Compose + EC2)

# Infrastructure (Terraform)
cd infra/terraform && terraform init && terraform apply

# Build AMD64 images → push to ECR (or use GitHub Actions)
git push origin main  # GHA builds automatically

# Deploy on EC2
ssh ubuntu@YOUR_EC2_IP
cd /opt/sla && docker compose -f docker-compose.prod.yml up -d

See infra/ for Terraform configs, nginx reverse proxy, and SSL setup scripts.


Tech Stack

  • Backend: Python 3.11, FastAPI, SQLAlchemy (async), Alembic
  • LLM: litellm (provider-agnostic) — Claude Sonnet for completions, text-embedding-3-small for embeddings
  • Knowledge: RAPTOR hierarchical trees + pgvector + NetworkX knowledge graph
  • Retrieval: 6-strategy ensemble (semantic, BM25, graph, HyDE, multi-query, query decomposition)
  • Slack: Bolt SDK with Socket Mode
  • Frontend: Next.js 15, React 19, TailwindCSS v4
  • Database: PostgreSQL 16 with pgvector extension
  • Infrastructure: Docker Compose (dev), EC2 + nginx (staging), GHA CI/CD

Contributing

See CONTRIBUTING.md for development setup, coding standards, and PR guidelines.


License

Apache License 2.0 — see LICENSE.

Built by IncidentFox (YC W25).

About

Self-learning AI agents that get smarter from your Slack, docs, meetings, and code. RAPTOR trees + knowledge graph + multi-strategy RAG. Drop into any Slack channel — it starts learning automatically.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors