How glaborie/agentguard works
AgentGuard is a self-hosted reliability control plane for RAG and agent applications. Its primary request path accepts chat through the API, dispatches by model mode, and returns direct, RAG-grounded, or agent-generated completions; a CLI also exposes RAG query and ingestion. Separate product branches manage knowledge ingestion and retrieval, runtime protection and configuration, evaluation and red teaming, and telemetry. The graph preserves documented capabilities whose source was not sampled, but their internal calls are omitted where evidence is unavailable.
Main entry points: chain.py RAG chain · service.py RAG service · chat_service.py Mode dispatcher · app.py HTTP API
Components 32
Product interfaces
- HTTP API
app/api/app.py - Chat endpoint
app/api/routes/chat.py - Mode dispatcher
app/api/services/chat_service.py - Direct completion
app/api/services/direct_llm.py - RAG completion
app/api/services/rag_llm.py - Agent completion
app/api/services/agent_llm.py - Agent graph
app/agent/graph.py - GitHub MCP client
app/agent/mcp_client.py - CLI commands
app/cli/commands/query.py - Ingest command
app/cli/commands/ingest.py
RAG knowledge workflow
- RAG service
app/rag/service.py - Document ingestion
app/rag/ingest.py - RAG chain
app/rag/chain.py - Hybrid retrieval
app/rag/hybrid_retriever.py - BM25 index
app/rag/bm25_index.py
Runtime controls
- Runtime flags
app/core/feature_flags.py - Config endpoint
app/api/routes/config.py - PII masking
app/core/pii.py - Guardrails
guardrails/custom_guardrails.py - Semantic cache
guardrails/semantic_cache.py
Evaluation and testing
- Evaluation service
app/eval/service.py - Experiment runner
app/eval/experiments/runner.py - DeepEval metrics
app/eval/deepeval_metrics.py - RAGAS metrics
app/eval/ragas_metrics.py - Red teaming
app/cli/commands/red_team.py
Observability
- Trace callbacks
app/core/tracing.py - Telemetry setup
app/core/telemetry.py
Other components
- AI user
- Qdrant store
- Model gateway
- Langfuse
- OpenTelemetry backends
Connections 34
- AI user → HTTP API: sends chat
README.md - HTTP API → Chat endpoint: routes requests
app/api/app.py - Chat endpoint → Mode dispatcher: delegates
app/api/routes/chat.py - Mode dispatcher → Direct completion: dispatches direct
app/api/services/chat_service.py - Mode dispatcher → RAG completion: dispatches RAG
app/api/services/chat_service.py - Mode dispatcher → Agent completion: dispatches agent
app/api/services/chat_service.py - Agent completion → Agent graph: runs graph
- Agent graph → GitHub MCP client: uses client
app/agent/graph.py - RAG completion → RAG service: queries RAG
app/api/services/rag_llm.py - RAG service → PII masking: masks input
app/rag/service.py - RAG service → RAG chain: delegates query
app/rag/service.py - CLI commands → RAG service: queries
app/cli/commands/query.py - Ingest command → RAG service: starts ingestion
app/cli/commands/ingest.py - RAG service → Document ingestion: delegates ingestion
app/rag/service.py - Document ingestion → Qdrant store: stores vectors
app/rag/ingest.py - Document ingestion → BM25 index: invalidates index
app/rag/ingest.py - RAG chain → Hybrid retrieval: builds retriever
app/rag/chain.py - RAG chain → Qdrant store: retrieves vectors
app/rag/chain.py - RAG chain → Model gateway: generates answer
app/rag/chain.py - Hybrid retrieval → BM25 index: combines results
app/rag/chain.py - HTTP API → Config endpoint: routes config
app/api/app.py - Config endpoint → Runtime flags: reads and updates
app/api/routes/config.py - RAG chain → Runtime flags: selects retrieval
app/rag/chain.py - RAG completion → Guardrails: applies protection
README.md - Mode dispatcher → Semantic cache: may use cache
- Evaluation service → DeepEval metrics: runs metrics
app/eval/service.py - Experiment runner → RAG chain: evaluates chain
app/eval/experiments/runner.py - Experiment runner → RAGAS metrics: uses metrics
app/eval/experiments/runner.py - Red teaming → Model gateway: probes models
README.md - HTTP API → Telemetry setup: initializes
app/api/app.py - CLI commands → Telemetry setup: initializes
app/cli/app.py - RAG chain → Trace callbacks: uses callbacks
app/rag/chain.py - Trace callbacks → Langfuse: sends traces
app/core/tracing.py - Telemetry setup → OpenTelemetry backends: exports telemetry
README.md