# krishhcodes/agentguard architecture

> Architecture diagram of the GitHub repository krishhcodes/agentguard, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/krishhcodes/agentguard
- Repository: https://github.com/krishhcodes/agentguard

## Overview

AgentGuard runs tool-using RAG scenarios through a LangGraph agent, optionally protecting retrieved content with the Content Firewall and proposed actions with the Action Guard. The guarded path derives user-request scope, tracks untrusted/confidential data, and can pause for human approval; tools operate in an in-memory sandbox. Runs produce audit outcomes, while the evaluation harness measures attack and task results. The README documents the demo UI, alerts, and session monitoring; sampled excerpts do not expose every runtime connection, so those links are limited to documented or indexed relationships.

Main entry points: [`agentguard/agent/nodes.py`](https://github.com/krishhcodes/agentguard/blob/main/agentguard/agent/nodes.py) (Agent nodes), [`agentguard/runner.py`](https://github.com/krishhcodes/agentguard/blob/main/agentguard/runner.py) (Scenario runner), [`agentguard/firewall/pipeline.py`](https://github.com/krishhcodes/agentguard/blob/main/agentguard/firewall/pipeline.py) (Content firewall), [`agentguard/eval/harness.py`](https://github.com/krishhcodes/agentguard/blob/main/agentguard/eval/harness.py) (Evaluation harness)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["Run interfaces"]
  node_cli["CLI<br/>[cli.py]"]
  node_demo["Demo UI<br/>[app.py]"]
end

subgraph group_agent["Agent workflow"]
  node_runner["Scenario runner<br/>[runner.py]"]
  node_graph["Agent graph<br/>[graph.py]"]
  node_agentnodes["Agent nodes<br/>[nodes.py]"]
  node_state["Run state<br/>[state.py]"]
  node_retriever["RAG retrieval<br/>[retriever.py]"]
end

subgraph group_defenses["Security layers"]
  node_scope["Request scope<br/>[extractor.py]"]
  node_firewall["Content firewall<br/>[pipeline.py]"]
  node_heuristics["Injection heuristics<br/>[heuristics.py]"]
  node_classifier["LLM classifier<br/>[classifier.py]"]
  node_textviews["Text views<br/>[views.py]"]
  node_actionguard["Action rules<br/>[rules.py]"]
  node_taint["Taint ledger<br/>[taint.py]"]
  node_monitor["Session monitor<br/>[session.py]"]
end

subgraph group_runtime["Runtime and evidence"]
  node_sandbox[("Tool sandbox<br/>[env.py]")]
  node_tools["Tool registry<br/>[tools.py]"]
  node_llm["LLM gateway<br/>[llm.py]"]
  node_audit["Audit events<br/>[events.py]"]
  node_alerts["Run alerts<br/>[alerts.py]"]
  node_policy["Security policy<br/>[policy.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_eval["Evaluation harness<br/>[harness.py]"]
  node_suites["Scenario suites<br/>[suites.py]"]
  node_metrics["Evaluation metrics<br/>[metrics.py]"]
end

node_user(("User"))

node_user -->|"starts runs"| node_cli
node_user -->|"uses demo"| node_demo
node_cli -->|"runs scenario"| node_runner
node_demo -->|"runs scenario"| node_runner
node_runner -->|"invokes graph"| node_graph
node_graph -->|"dispatches nodes"| node_agentnodes
node_agentnodes -->|"updates state"| node_state
node_agentnodes -->|"retrieves context"| node_retriever
node_agentnodes -->|"scans content"| node_firewall
node_firewall -->|"scores text"| node_heuristics
node_firewall -->|"classifies ambiguity"| node_classifier
node_firewall -->|"uses text views"| node_textviews
node_agentnodes -->|"requests completion"| node_llm
node_agentnodes -.->|"extracts scope"| node_scope
node_agentnodes -->|"checks tool calls"| node_actionguard
node_agentnodes -->|"records provenance"| node_taint
node_actionguard -->|"checks data flow"| node_taint
node_agentnodes -.->|"dispatches tools"| node_tools
node_tools -->|"operates on"| node_sandbox
node_agentnodes -->|"emits decisions"| node_audit
node_runner -.->|"creates sandbox"| node_sandbox
node_runner -.->|"supports sessions"| node_monitor
node_monitor -->|"uses guard rules"| node_actionguard
node_runner -.->|"produces alerts"| node_alerts
node_actionguard -->|"applies policy"| node_policy
node_firewall -->|"uses thresholds"| node_policy
node_cli -->|"starts evaluation"| node_eval
node_eval -->|"loads scenarios"| node_suites
node_eval -->|"runs scenarios"| node_runner
node_eval -->|"computes metrics"| node_metrics
node_runner -->|"records lifecycle"| node_audit

click node_cli "https://github.com/krishhcodes/agentguard/blob/main/agentguard/cli.py"
click node_demo "https://github.com/krishhcodes/agentguard/blob/main/ui/app.py"
click node_runner "https://github.com/krishhcodes/agentguard/blob/main/agentguard/runner.py"
click node_graph "https://github.com/krishhcodes/agentguard/blob/main/agentguard/agent/graph.py"
click node_agentnodes "https://github.com/krishhcodes/agentguard/blob/main/agentguard/agent/nodes.py"
click node_state "https://github.com/krishhcodes/agentguard/blob/main/agentguard/agent/state.py"
click node_retriever "https://github.com/krishhcodes/agentguard/blob/main/agentguard/rag/retriever.py"
click node_scope "https://github.com/krishhcodes/agentguard/blob/main/agentguard/scope/extractor.py"
click node_firewall "https://github.com/krishhcodes/agentguard/blob/main/agentguard/firewall/pipeline.py"
click node_heuristics "https://github.com/krishhcodes/agentguard/blob/main/agentguard/firewall/heuristics.py"
click node_classifier "https://github.com/krishhcodes/agentguard/blob/main/agentguard/firewall/classifier.py"
click node_textviews "https://github.com/krishhcodes/agentguard/blob/main/agentguard/text/views.py"
click node_actionguard "https://github.com/krishhcodes/agentguard/blob/main/agentguard/guard/rules.py"
click node_taint "https://github.com/krishhcodes/agentguard/blob/main/agentguard/guard/taint.py"
click node_monitor "https://github.com/krishhcodes/agentguard/blob/main/agentguard/monitor/session.py"
click node_sandbox "https://github.com/krishhcodes/agentguard/blob/main/agentguard/sandbox/env.py"
click node_tools "https://github.com/krishhcodes/agentguard/blob/main/agentguard/sandbox/tools.py"
click node_llm "https://github.com/krishhcodes/agentguard/blob/main/agentguard/llm.py"
click node_audit "https://github.com/krishhcodes/agentguard/blob/main/agentguard/audit/events.py"
click node_alerts "https://github.com/krishhcodes/agentguard/blob/main/agentguard/alerts.py"
click node_policy "https://github.com/krishhcodes/agentguard/blob/main/agentguard/policy.py"
click node_eval "https://github.com/krishhcodes/agentguard/blob/main/agentguard/eval/harness.py"
click node_suites "https://github.com/krishhcodes/agentguard/blob/main/agentguard/eval/suites.py"
click node_metrics "https://github.com/krishhcodes/agentguard/blob/main/agentguard/eval/metrics.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_demo,node_user toneBlue
class node_runner,node_graph,node_agentnodes,node_state,node_retriever toneAmber
class node_scope,node_firewall,node_heuristics,node_classifier,node_textviews,node_actionguard,node_taint,node_monitor toneMint
class node_sandbox,node_tools,node_llm,node_audit,node_alerts,node_policy toneRose
class node_eval,node_suites,node_metrics toneIndigo
```

## Components

### Run interfaces

- [CLI](https://github.com/krishhcodes/agentguard/blob/main/agentguard/cli.py): `agentguard/cli.py`
- [Demo UI](https://github.com/krishhcodes/agentguard/blob/main/ui/app.py): `ui/app.py`

### Agent workflow

- [Scenario runner](https://github.com/krishhcodes/agentguard/blob/main/agentguard/runner.py): `agentguard/runner.py`
- [Agent graph](https://github.com/krishhcodes/agentguard/blob/main/agentguard/agent/graph.py): `agentguard/agent/graph.py`
- [Agent nodes](https://github.com/krishhcodes/agentguard/blob/main/agentguard/agent/nodes.py): `agentguard/agent/nodes.py`
- [Run state](https://github.com/krishhcodes/agentguard/blob/main/agentguard/agent/state.py): `agentguard/agent/state.py`
- [RAG retrieval](https://github.com/krishhcodes/agentguard/blob/main/agentguard/rag/retriever.py): `agentguard/rag/retriever.py`

### Security layers

- [Request scope](https://github.com/krishhcodes/agentguard/blob/main/agentguard/scope/extractor.py): `agentguard/scope/extractor.py`
- [Content firewall](https://github.com/krishhcodes/agentguard/blob/main/agentguard/firewall/pipeline.py): `agentguard/firewall/pipeline.py`
- [Injection heuristics](https://github.com/krishhcodes/agentguard/blob/main/agentguard/firewall/heuristics.py): `agentguard/firewall/heuristics.py`
- [LLM classifier](https://github.com/krishhcodes/agentguard/blob/main/agentguard/firewall/classifier.py): `agentguard/firewall/classifier.py`
- [Text views](https://github.com/krishhcodes/agentguard/blob/main/agentguard/text/views.py): `agentguard/text/views.py`
- [Action rules](https://github.com/krishhcodes/agentguard/blob/main/agentguard/guard/rules.py): `agentguard/guard/rules.py`
- [Taint ledger](https://github.com/krishhcodes/agentguard/blob/main/agentguard/guard/taint.py): `agentguard/guard/taint.py`
- [Session monitor](https://github.com/krishhcodes/agentguard/blob/main/agentguard/monitor/session.py): `agentguard/monitor/session.py`

### Runtime and evidence

- [Tool sandbox](https://github.com/krishhcodes/agentguard/blob/main/agentguard/sandbox/env.py): `agentguard/sandbox/env.py`
- [Tool registry](https://github.com/krishhcodes/agentguard/blob/main/agentguard/sandbox/tools.py): `agentguard/sandbox/tools.py`
- [LLM gateway](https://github.com/krishhcodes/agentguard/blob/main/agentguard/llm.py): `agentguard/llm.py`
- [Audit events](https://github.com/krishhcodes/agentguard/blob/main/agentguard/audit/events.py): `agentguard/audit/events.py`
- [Run alerts](https://github.com/krishhcodes/agentguard/blob/main/agentguard/alerts.py): `agentguard/alerts.py`
- [Security policy](https://github.com/krishhcodes/agentguard/blob/main/agentguard/policy.py): `agentguard/policy.py`

### Evaluation

- [Evaluation harness](https://github.com/krishhcodes/agentguard/blob/main/agentguard/eval/harness.py): `agentguard/eval/harness.py`
- [Scenario suites](https://github.com/krishhcodes/agentguard/blob/main/agentguard/eval/suites.py): `agentguard/eval/suites.py`
- [Evaluation metrics](https://github.com/krishhcodes/agentguard/blob/main/agentguard/eval/metrics.py): `agentguard/eval/metrics.py`

### Other components

- **User**

## Connections

- User → CLI: starts runs (evidence: `README.md`)
- User → Demo UI: uses demo (evidence: `README.md`)
- CLI → Scenario runner: runs scenario (evidence: `agentguard/cli.py`)
- Demo UI → Scenario runner: runs scenario (evidence: `ui/app.py`)
- Scenario runner → Agent graph: invokes graph (evidence: `agentguard/runner.py`)
- Agent graph → Agent nodes: dispatches nodes (evidence: `agentguard/agent/graph.py`)
- Agent nodes → Run state: updates state (evidence: `agentguard/agent/nodes.py`)
- Agent nodes → RAG retrieval: retrieves context (evidence: `agentguard/agent/nodes.py`)
- Agent nodes → Content firewall: scans content (evidence: `agentguard/agent/nodes.py`)
- Content firewall → Injection heuristics: scores text (evidence: `agentguard/firewall/pipeline.py`)
- Content firewall → LLM classifier: classifies ambiguity (evidence: `agentguard/firewall/pipeline.py`)
- Content firewall → Text views: uses text views (evidence: `agentguard/firewall/pipeline.py`)
- Agent nodes → LLM gateway: requests completion (evidence: `agentguard/agent/nodes.py`)
- Agent nodes → Request scope: extracts scope (evidence: `README.md`)
- Agent nodes → Action rules: checks tool calls (evidence: `agentguard/agent/nodes.py`)
- Agent nodes → Taint ledger: records provenance (evidence: `agentguard/agent/nodes.py`)
- Action rules → Taint ledger: checks data flow (evidence: `agentguard/guard/rules.py`)
- Agent nodes → Tool registry: dispatches tools
- Tool registry → Tool sandbox: operates on (evidence: `agentguard/sandbox/tools.py`)
- Agent nodes → Audit events: emits decisions (evidence: `agentguard/agent/nodes.py`)
- Scenario runner → Tool sandbox: creates sandbox (evidence: `README.md`)
- Scenario runner → Session monitor: supports sessions (evidence: `README.md`)
- Session monitor → Action rules: uses guard rules (evidence: `agentguard/monitor/session.py`)
- Scenario runner → Run alerts: produces alerts (evidence: `README.md`)
- Action rules → Security policy: applies policy (evidence: `agentguard/guard/rules.py`)
- Content firewall → Security policy: uses thresholds (evidence: `agentguard/firewall/pipeline.py`)
- CLI → Evaluation harness: starts evaluation (evidence: `agentguard/cli.py`)
- Evaluation harness → Scenario suites: loads scenarios (evidence: `agentguard/eval/harness.py`)
- Evaluation harness → Scenario runner: runs scenarios (evidence: `agentguard/eval/harness.py`)
- Evaluation harness → Evaluation metrics: computes metrics (evidence: `agentguard/eval/harness.py`)
- Scenario runner → Audit events: records lifecycle (evidence: `agentguard/runner.py`)
