GitHunt
PO

pooyaphoenix/RA3G-Agent

Local RAG system with a built-in governance agent that filters sensitive or restricted information with separated agent logging systems to keep privacy and security

RA3G-logo

Policy-Aware RAG Multi-Agent AI System

Release Version GitHub stars Email


๐Ÿš€ Quick Start

git clone https://github.com/pooyaphoenix/RA3G-Agent.git
cd RA3G-Agent
docker compose up --build

Option 2: Local Installation

git clone https://github.com/pooyaphoenix/RA3G-Agent.git
cd RA3G-Agent
python3 -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt
python ra3g.py --api-port 8010 --ui-port 8501

Access the application:


โœจ Features

  • ๐Ÿ” Local RAG System - Query your documents without external APIs
  • ๐Ÿ›ก๏ธ Governance Agent - Automatically filters sensitive information
  • ๐Ÿค– Multi-Agent Architecture - Retriever, Reasoning, and Governance agents
  • ๐Ÿ’พ Session Memory - Remembers previous queries and context
  • ๐Ÿ“Š Real-time Logs - Monitor agent activity with live log streaming
  • ๐Ÿ“„ PDF Document Upload - Automatic PDF upload and vector store building
  • ๐ŸŽจ Streamlit UI - Beautiful web interface for easy interaction
  • ๐Ÿ”Œ REST API - Full programmatic access via FastAPI
  • โš™๏ธ Fully Customizable - Easy configuration via config.yml

๐ŸŽฌ Demo

Interface Demo


๐Ÿ—๏ธ Architecture

Architecture Diagram

Agent Flow:

  1. Retriever Agent - Finds relevant passages from your corpus
  2. Reasoning Agent - Generates answers using Ollama LLM
  3. Governance Agent - Validates and filters responses based on policies

๐Ÿ“– Usage Examples

Web UI

  1. Open http://localhost:8501
  2. Navigate to the Chat tab
  3. Type your question and get instant answers

API Request

curl -X POST 'http://localhost:8010/query' \
  -H 'Content-Type: application/json' \
  -H 'session-id: my-session' \
  -d '{
    "query": "What are the benefits of regular hand washing?",
    "top_k": 5
  }'

API Response

{
  "query": "What are the benefits of regular hand washing?",
  "answer": "Preventing the spread of infections is one of the simplest ways.",
  "governance": {
    "approved": true,
    "reason": "approved"
  },
  "trace": [
    {
      "index": 0,
      "note": "relevant passage about benefits of hand washing"
    }
  ],
  "retrieved": [
    {
      "id": "corpus_medical_general.txt#p0",
      "text": "...",
      "source": "corpus_medical_general.txt",
      "score": 0.51
    }
  ],
  "confidence": 0.512,
  "session_id": "my-session"
}

Python Client Example

import requests

response = requests.post(
    'http://localhost:8010/query',
    headers={'session-id': 'my-session'},
    json={'query': 'What is machine learning?', 'top_k': 5}
)
print(response.json()['answer'])

๐Ÿ”Œ API Endpoints

Method Endpoint Description
POST /query Ask a question through RAG
GET /health Health check for all agents
GET /health/{agent} Health check for specific agent
GET /trace Get session query history
DELETE /memory/clear Clear session memory
GET /docs Interactive Swagger UI
GET /logs/stream/{log_type} Stream logs in real-time (SSE)

Try it live: http://localhost:8010/docs


๐Ÿ›ก๏ธ Governance Rules

The governance agent automatically blocks or approves queries based on:

โŒ Blocked:

  • Personal names, phone numbers, addresses
  • Medical records and patient data
  • Confidential corporate information
  • Banned phrases (configurable in config.yml)

โœ… Allowed:

  • General medical, scientific questions
  • Educational content
  • Public information

๐Ÿ“‚ Adding Documents

  1. Place your documents in data/corpus/ directory (.txt or .md files)
  2. Automatic indexing - The system builds the FAISS index on startup
  3. Manual indexing (optional):
    python indexer.py --corpus data/corpus

Configuration: Edit config.yml to customize corpus directory and indexing behavior.


โš™๏ธ Configuration

All settings are in config.yml:

# Ollama Configuration
OLLAMA_URL: http://localhost:11434/api/generate
OLLAMA_MODEL: qwen2.5:7b-instruct

# Embedding Model
EMBED_MODEL: all-MiniLM-L6-v2

# Confidence Thresholds
THRESHOLDS:
  retriever: 0.72
  reasoner: 0.81

# Auto-build index on startup
AUTO_BUILD_FAISS: true
CORPUS_DIR: data/corpus

# Banned phrases for governance
BANNED_PHRASES:
  - diagnosis
  - prescription
  - classified
  - confidential

๐Ÿงช Testing

# Health check
curl http://localhost:8010/health

# Test query
curl -X POST http://localhost:8010/query \
  -H 'Content-Type: application/json' \
  -H 'session-id: test' \
  -d '{"query": "Hello", "top_k": 3}'

๐Ÿ“ Requirements

  • Python 3.8+
  • Ollama (for LLM inference)
  • Docker (optional, for containerized deployment)

See requirements.txt for Python dependencies.


๐Ÿค Contributing

See CONTRIBUTING.md for guidelines.


๐Ÿ“ง Contact

pooyachavoshi@gmail.com


๐Ÿ“„ License

See LICENSE file for details.