# gsiros/saga architecture

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

- Interactive diagram: https://gitdiagram.com/gsiros/saga
- Repository: https://github.com/gsiros/saga

## Overview

SAGA governs agent identity, registration, access policy, and agent-to-agent communication. The main workflow is user registration with the Provider, agent registration and credential provisioning, then an agent going online and processing peer conversations through its local LLM wrapper and tools. The graph also preserves the documented CA, Provider state, and attack-model evaluation areas. Several implementation links rely on README statements or SOURCE INDEX references; unsampled internals are not treated as inspected.

Main entry points: [`saga/agent.py`](https://github.com/gsiros/saga/blob/main/saga/agent.py) (SAGA agent), [`saga/common/contact_policy.py`](https://github.com/gsiros/saga/blob/main/saga/common/contact_policy.py) (Contact policy), [`agent_backend/base.py`](https://github.com/gsiros/saga/blob/main/agent_backend/base.py) (LLM agent backend), [`saga/provider/provider.py`](https://github.com/gsiros/saga/blob/main/saga/provider/provider.py) (Provider service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_identity["Identity and registration"]
  node_user_client["User client<br/>[user.py]"]
  node_provider["Provider service<br/>[provider.py]"]
  node_provider_store[("Provider MongoDB")]
  node_ca["Certificate authority<br/>[CA.py]"]
  node_crypto["Cryptographic primitives<br/>[crypto.py]"]
end

subgraph group_protocol["Agent protocol"]
  node_agent["SAGA agent<br/>[agent.py]"]
  node_contact_policy["Contact policy<br/>[contact_policy.py]"]
  node_monitor["Overhead monitor<br/>[overhead.py]"]
  node_logger["SAGA logger<br/>[logger.py]"]
end

subgraph group_runtime["Agent runtime"]
  node_local_agent["Local agent adapter<br/>[local_agent.py]"]
  node_backend["LLM agent backend<br/>[base.py]"]
  node_email_tool["Email tools<br/>[email.py]"]
  node_calendar_tool["Calendar tools<br/>[calendar.py]"]
  node_documents_tool["Document tools<br/>[documents.py]"]
  node_tool_base["Tool base<br/>[base.py]"]
  node_tool_mongo[("Tool MongoDB")]
end

subgraph group_evaluation["Security evaluation"]
  node_adversary_a2["Adversary A2<br/>[A2.py]"]
  node_adversary_a3["Adversary A3<br/>[A3.py]"]
  node_adversary_a5["Adversary A5<br/>[A5.py]"]
  node_benign_a5["Benign A5<br/>[A5.py]"]
end

node_user_actor(("Agent owner"))

node_user_actor -->|"operates"| node_user_client
node_user_client -->|"registers with"| node_provider
node_provider -->|"stores records"| node_provider_store
node_provider -->|"gets credentials signed"| node_ca
node_user_client -->|"generates keys"| node_crypto
node_agent -.->|"uses provider services"| node_provider
node_agent -->|"uses certificates"| node_ca
node_ca -->|"signs and verifies"| node_crypto
node_agent -->|"uses cryptography"| node_crypto
node_agent -->|"checks access policy"| node_contact_policy
node_agent -->|"delegates tasks"| node_local_agent
node_local_agent -->|"wraps local implementation"| node_backend
node_backend -->|"exposes tools"| node_email_tool
node_backend -->|"exposes tools"| node_calendar_tool
node_backend -->|"exposes tools"| node_documents_tool
node_email_tool -->|"inherits from"| node_tool_base
node_calendar_tool -->|"inherits from"| node_tool_base
node_documents_tool -->|"uses base"| node_tool_base
node_email_tool -->|"reads and writes"| node_tool_mongo
node_calendar_tool -->|"reads and writes"| node_tool_mongo
node_agent -->|"measures overhead"| node_monitor
node_agent -->|"logs events"| node_logger
node_adversary_a2 -->|"uses policy"| node_contact_policy
node_adversary_a3 -->|"uses policy"| node_contact_policy
node_adversary_a5 -->|"uses policy"| node_contact_policy
node_benign_a5 -->|"uses policy"| node_contact_policy

click node_user_client "https://github.com/gsiros/saga/blob/main/saga/user/user.py"
click node_provider "https://github.com/gsiros/saga/blob/main/saga/provider/provider.py"
click node_ca "https://github.com/gsiros/saga/blob/main/saga/ca/CA.py"
click node_crypto "https://github.com/gsiros/saga/blob/main/saga/common/crypto.py"
click node_agent "https://github.com/gsiros/saga/blob/main/saga/agent.py"
click node_contact_policy "https://github.com/gsiros/saga/blob/main/saga/common/contact_policy.py"
click node_local_agent "https://github.com/gsiros/saga/blob/main/saga/local_agent.py"
click node_backend "https://github.com/gsiros/saga/blob/main/agent_backend/base.py"
click node_email_tool "https://github.com/gsiros/saga/blob/main/agent_backend/tools/email.py"
click node_calendar_tool "https://github.com/gsiros/saga/blob/main/agent_backend/tools/calendar.py"
click node_documents_tool "https://github.com/gsiros/saga/blob/main/agent_backend/tools/documents.py"
click node_tool_base "https://github.com/gsiros/saga/blob/main/agent_backend/tools/base.py"
click node_monitor "https://github.com/gsiros/saga/blob/main/saga/common/overhead.py"
click node_logger "https://github.com/gsiros/saga/blob/main/saga/common/logger.py"
click node_adversary_a2 "https://github.com/gsiros/saga/blob/main/saga/attack_models/adversaries/A2.py"
click node_adversary_a3 "https://github.com/gsiros/saga/blob/main/saga/attack_models/adversaries/A3.py"
click node_adversary_a5 "https://github.com/gsiros/saga/blob/main/saga/attack_models/adversaries/A5.py"
click node_benign_a5 "https://github.com/gsiros/saga/blob/main/saga/attack_models/benign/A5.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_user_client,node_provider,node_provider_store,node_ca,node_crypto toneBlue
class node_agent,node_contact_policy,node_monitor,node_logger toneAmber
class node_local_agent,node_backend,node_email_tool,node_calendar_tool,node_documents_tool,node_tool_base,node_tool_mongo toneMint
class node_adversary_a2,node_adversary_a3,node_adversary_a5,node_benign_a5 toneRose
class node_user_actor toneIndigo
```

## Components

### Identity and registration

- [User client](https://github.com/gsiros/saga/blob/main/saga/user/user.py): `saga/user/user.py`
- [Provider service](https://github.com/gsiros/saga/blob/main/saga/provider/provider.py): `saga/provider/provider.py`
- **Provider MongoDB**
- [Certificate authority](https://github.com/gsiros/saga/blob/main/saga/ca/CA.py): `saga/ca/CA.py`
- [Cryptographic primitives](https://github.com/gsiros/saga/blob/main/saga/common/crypto.py): `saga/common/crypto.py`

### Agent protocol

- [SAGA agent](https://github.com/gsiros/saga/blob/main/saga/agent.py): `saga/agent.py`
- [Contact policy](https://github.com/gsiros/saga/blob/main/saga/common/contact_policy.py): `saga/common/contact_policy.py`
- [Overhead monitor](https://github.com/gsiros/saga/blob/main/saga/common/overhead.py): `saga/common/overhead.py`
- [SAGA logger](https://github.com/gsiros/saga/blob/main/saga/common/logger.py): `saga/common/logger.py`

### Agent runtime

- [Local agent adapter](https://github.com/gsiros/saga/blob/main/saga/local_agent.py): `saga/local_agent.py`
- [LLM agent backend](https://github.com/gsiros/saga/blob/main/agent_backend/base.py): `agent_backend/base.py`
- [Email tools](https://github.com/gsiros/saga/blob/main/agent_backend/tools/email.py): `agent_backend/tools/email.py`
- [Calendar tools](https://github.com/gsiros/saga/blob/main/agent_backend/tools/calendar.py): `agent_backend/tools/calendar.py`
- [Document tools](https://github.com/gsiros/saga/blob/main/agent_backend/tools/documents.py): `agent_backend/tools/documents.py`
- [Tool base](https://github.com/gsiros/saga/blob/main/agent_backend/tools/base.py): `agent_backend/tools/base.py`
- **Tool MongoDB**

### Security evaluation

- [Adversary A2](https://github.com/gsiros/saga/blob/main/saga/attack_models/adversaries/A2.py): `saga/attack_models/adversaries/A2.py`
- [Adversary A3](https://github.com/gsiros/saga/blob/main/saga/attack_models/adversaries/A3.py): `saga/attack_models/adversaries/A3.py`
- [Adversary A5](https://github.com/gsiros/saga/blob/main/saga/attack_models/adversaries/A5.py): `saga/attack_models/adversaries/A5.py`
- [Benign A5](https://github.com/gsiros/saga/blob/main/saga/attack_models/benign/A5.py): `saga/attack_models/benign/A5.py`

### Other components

- **Agent owner**

## Connections

- Agent owner → User client: operates (evidence: `README.md`)
- User client → Provider service: registers with (evidence: `README.md`)
- Provider service → Provider MongoDB: stores records (evidence: `README.md`)
- Provider service → Certificate authority: gets credentials signed (evidence: `README.md`)
- User client → Cryptographic primitives: generates keys (evidence: `README.md`)
- SAGA agent → Provider service: uses provider services (evidence: `README.md`)
- SAGA agent → Certificate authority: uses certificates (evidence: `saga/agent.py`)
- Certificate authority → Cryptographic primitives: signs and verifies (evidence: `saga/ca/CA.py`)
- SAGA agent → Cryptographic primitives: uses cryptography (evidence: `saga/agent.py`)
- SAGA agent → Contact policy: checks access policy (evidence: `saga/agent.py`)
- SAGA agent → Local agent adapter: delegates tasks (evidence: `saga/agent.py`)
- Local agent adapter → LLM agent backend: wraps local implementation (evidence: `README.md`)
- LLM agent backend → Email tools: exposes tools (evidence: `agent_backend/base.py`)
- LLM agent backend → Calendar tools: exposes tools (evidence: `agent_backend/base.py`)
- LLM agent backend → Document tools: exposes tools (evidence: `agent_backend/base.py`)
- Email tools → Tool base: inherits from (evidence: `agent_backend/tools/email.py`)
- Calendar tools → Tool base: inherits from (evidence: `agent_backend/tools/calendar.py`)
- Document tools → Tool base: uses base (evidence: `agent_backend/tools/documents.py`)
- Email tools → Tool MongoDB: reads and writes (evidence: `agent_backend/tools/email.py`)
- Calendar tools → Tool MongoDB: reads and writes (evidence: `agent_backend/tools/calendar.py`)
- SAGA agent → Overhead monitor: measures overhead (evidence: `saga/agent.py`)
- SAGA agent → SAGA logger: logs events (evidence: `saga/agent.py`)
- Adversary A2 → Contact policy: uses policy (evidence: `saga/attack_models/adversaries/A2.py`)
- Adversary A3 → Contact policy: uses policy (evidence: `saga/attack_models/adversaries/A3.py`)
- Adversary A5 → Contact policy: uses policy (evidence: `saga/attack_models/adversaries/A5.py`)
- Benign A5 → Contact policy: uses policy (evidence: `saga/attack_models/benign/A5.py`)
