# r1khilt/claymore architecture

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

- Interactive diagram: https://gitdiagram.com/r1khilt/claymore
- Repository: https://github.com/r1khilt/claymore

## Overview

#### Purpose and System Shape
Claymore is a closed-loop scientific-research platform: it ingests lab context, builds attributed scientific memory, identifies and plans investigations, performs computational or robotic work, and incorporates results into future decisions. The backend is Python/FastAPI; the optional operator UI is React/TypeScript with 2D/3D lab and graph views.

#### Runtime Entry Points
The HTTP application and runtime composition live in `src/claymore/api/app.py` and `src/claymore/api/runtime.py`. API route groups expose agent interaction, questions, connector administration, actions, local operations, and Telegram/WhatsApp channels under `src/claymore/api/routes/`. An MCP integration surface is separately hosted by `src/claymore/mcp_server/server.py`. The browser client starts at `web/src/main.tsx` and routes UI state through `web/src/App.tsx`.

#### Ingestion and Knowledge Construction
The ingestion pipeline gathers external lab artifacts, normalizes them, and turns them into episodes suitable for memory storage: `src/claymore/ingest/pipeline.py`, `src/claymore/ingest/normalize.py`, and `src/claymore/ingest/episodes.py`. Composio is the connector boundary for sources such as Slack, GitHub, Gmail, and Notion, managed through `src/claymore/ingest/composio/manager.py` and `src/claymore/ingest/composio/hub.py`. Source state supports incremental/repeatable ingestion.

#### Scientific Memory and Retrieval
Memory is modeled as a scientific graph with ontology, identity resolution, reconciliation, and retrieval layers in `src/claymore/memory/graph.py`, `src/claymore/memory/ontology.py`, and `src/claymore/memory/retrieval.py`. Graphiti and FalkorDB are the material graph-memory services. Reconciliation (`src/claymore/memory/reconcile.py`) is a key boundary between noisy external events and canonical, attributed lab knowledge.

#### Agent Orchestration and Planning
The agent loop coordinates conversation context, LLM calls, routing, tools, temporal reasoning, hardware awareness, and scene/protocol design: `src/claymore/agent/agent_loop.py`, `src/claymore/agent/router.py`, and `src/claymore/agent/scene_designer.py`. It uses the Claude API and Claude Agent SDK through `src/claymore/agent/llm.py` and `src/claymore/agent/sdk_loop.py`. Agent-facing API flows enter through `src/claymore/api/routes/agent.py` and `src/claymore/api/routes/ask.py`.

#### Research Execution and Feedback Loop
Execution dispatches work to computational analysis, ML, datasets, workflow coordination, Claude Science, and laboratory automation: `src/claymore/execute/science_agent.py`, `src/claymore/execute/claude_science.py`, and `src/claymore/execute/workflows.py`. Physical execution integrates Opentrons (and, per project scope, PyLabRobot) via `src/claymore/execute/opentrons.py`; hardware context is represented in `src/claymore/agent/hardware.py`. Results are expected to re-enter ingestion/memory, closing the discover → plan → execute → learn loop.

#### Human Control, Safety, and External Channels
Potentially consequential operations cross an approval/writeback boundary in `src/claymore/actions/approvals.py`, `src/claymore/actions/writeback.py`, and `src/claymore/execute/approvals.py`, with audit support in `src/claymore/audit.py`. Authentication/security are backend concerns in `src/claymore/auth/models.py` and `src/claymore/api/security.py`. Telegram, WhatsApp, and SMS adapters provide alternate interaction/notification paths through `src/claymore/messaging/telegram.py`, `src/claymore/messaging/whatsapp.py`, and `src/claymore/messaging/twilio_sms.py`.

#### Operator Interface and Deployment
The web UI presents ask/agent turns, approvals, sources, projects, memory, and proactive work; its primary integration boundary is `web/src/lib/api.ts`. Scientific-workflow visualization is concentrated in `web/src/components/bench/ProtocolWorkspace.tsx` and Three.js components under `web/src/components/bench/three/`; graph visualization is in `web/src/components/projects/KnowledgeGraph3D.tsx`. Local multi-service deployment is defined in `docker-compose.yml`; environment configuration begins with `.env.example`.

Main entry points: [`src/claymore/agent/agent_loop.py`](https://github.com/r1khilt/claymore/blob/main/src/claymore/agent/agent_loop.py) (Agent loop), [`src/claymore/ingest/pipeline.py`](https://github.com/r1khilt/claymore/blob/main/src/claymore/ingest/pipeline.py) (Ingestion pipeline), [`src/claymore/memory/graph.py`](https://github.com/r1khilt/claymore/blob/main/src/claymore/memory/graph.py) (Scientific memory graph), [`src/claymore/execute/science_agent.py`](https://github.com/r1khilt/claymore/blob/main/src/claymore/execute/science_agent.py) (Research execution)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["Interfaces"]
  node_web["Operator UI<br/>React client<br/>[App.tsx]"]
  node_web_api["Web API client<br/>API adapter<br/>[api.ts]"]
  node_http_app["HTTP application<br/>FastAPI<br/>[app.py]"]
  node_agent_routes["Agent &amp; ask routes<br/>API routes<br/>[agent.py]"]
  node_mcp["MCP server<br/>integration server<br/>[server.py]"]
  node_channels["Messaging channels<br/>channel adapters<br/>[telegram.py]"]
end

subgraph group_knowledge["Knowledge Loop"]
  node_ingest["Ingestion pipeline<br/>[pipeline.py]"]
  node_normalize["Normalize to episodes<br/>transformation<br/>[episodes.py]"]
  node_connectors{{"Composio connectors<br/>source boundary<br/>[manager.py]"}}
  node_reconcile["Reconciliation<br/>canonicalization<br/>[reconcile.py]"]
  node_memory[("Scientific memory graph<br/>knowledge graph<br/>[graph.py]")]
  node_graph_services[("Graphiti &amp; FalkorDB<br/>graph services")]
end

subgraph group_agent["Agent Planning"]
  node_agent_loop["Agent loop<br/>orchestrator<br/>[agent_loop.py]"]
  node_router["Agent router<br/>intent router<br/>[router.py]"]
  node_scene_designer["Scene &amp; protocol design<br/>planner<br/>[scene_designer.py]"]
  node_claude{{"Claude APIs &amp; SDK<br/>LLM runtime<br/>[llm.py]"}}
end

subgraph group_execution["Execution &amp; Control"]
  node_execution_dispatch["Research execution<br/>dispatcher<br/>[science_agent.py]"]
  node_lab_automation{{"Lab automation<br/>robot integration<br/>[opentrons.py]"}}
  node_approvals{{"Approval &amp; writeback<br/>safety boundary<br/>[approvals.py]"}}
  node_audit["Audit trail<br/>audit log<br/>[audit.py]"]
end

node_web -->|"uses"| node_web_api
node_web_api -->|"HTTP"| node_http_app
node_channels -->|"alternate interaction"| node_http_app
node_mcp -->|"tool interaction"| node_agent_loop
node_http_app -->|"mounts"| node_agent_routes
node_agent_routes -->|"requests"| node_agent_loop
node_connectors -->|"source artifacts"| node_ingest
node_ingest -->|"raw context"| node_normalize
node_normalize -->|"episodes"| node_reconcile
node_reconcile -->|"canonical knowledge"| node_memory
node_memory -->|"persists and queries"| node_graph_services
node_memory -->|"retrieval context"| node_agent_loop
node_agent_loop -->|"routes work"| node_router
node_agent_loop -->|"LLM calls"| node_claude
node_agent_loop -->|"plans investigations"| node_scene_designer
node_scene_designer -->|"protocols and tasks"| node_execution_dispatch
node_execution_dispatch -->|"consequential actions"| node_approvals
node_approvals -->|"approved protocols"| node_lab_automation
node_approvals -->|"decision record"| node_audit
node_execution_dispatch -.->|"results feedback"| node_ingest
node_lab_automation -.->|"experimental results"| node_ingest

click node_web "https://github.com/r1khilt/claymore/blob/main/web/src/App.tsx"
click node_web_api "https://github.com/r1khilt/claymore/blob/main/web/src/lib/api.ts"
click node_http_app "https://github.com/r1khilt/claymore/blob/main/src/claymore/api/app.py"
click node_agent_routes "https://github.com/r1khilt/claymore/blob/main/src/claymore/api/routes/agent.py"
click node_mcp "https://github.com/r1khilt/claymore/blob/main/src/claymore/mcp_server/server.py"
click node_channels "https://github.com/r1khilt/claymore/blob/main/src/claymore/messaging/telegram.py"
click node_ingest "https://github.com/r1khilt/claymore/blob/main/src/claymore/ingest/pipeline.py"
click node_normalize "https://github.com/r1khilt/claymore/blob/main/src/claymore/ingest/episodes.py"
click node_connectors "https://github.com/r1khilt/claymore/blob/main/src/claymore/ingest/composio/manager.py"
click node_reconcile "https://github.com/r1khilt/claymore/blob/main/src/claymore/memory/reconcile.py"
click node_memory "https://github.com/r1khilt/claymore/blob/main/src/claymore/memory/graph.py"
click node_agent_loop "https://github.com/r1khilt/claymore/blob/main/src/claymore/agent/agent_loop.py"
click node_router "https://github.com/r1khilt/claymore/blob/main/src/claymore/agent/router.py"
click node_scene_designer "https://github.com/r1khilt/claymore/blob/main/src/claymore/agent/scene_designer.py"
click node_claude "https://github.com/r1khilt/claymore/blob/main/src/claymore/agent/llm.py"
click node_execution_dispatch "https://github.com/r1khilt/claymore/blob/main/src/claymore/execute/science_agent.py"
click node_lab_automation "https://github.com/r1khilt/claymore/blob/main/src/claymore/execute/opentrons.py"
click node_approvals "https://github.com/r1khilt/claymore/blob/main/src/claymore/actions/approvals.py"
click node_audit "https://github.com/r1khilt/claymore/blob/main/src/claymore/audit.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_web,node_web_api,node_http_app,node_agent_routes,node_mcp,node_channels toneBlue
class node_ingest,node_normalize,node_connectors,node_reconcile,node_memory,node_graph_services toneAmber
class node_agent_loop,node_router,node_scene_designer,node_claude toneMint
class node_execution_dispatch,node_lab_automation,node_approvals,node_audit toneRose
```

## Components

### Interfaces

- [Operator UI](https://github.com/r1khilt/claymore/blob/main/web/src/App.tsx): React client · `web/src/App.tsx`
- [Web API client](https://github.com/r1khilt/claymore/blob/main/web/src/lib/api.ts): API adapter · `web/src/lib/api.ts`
- [HTTP application](https://github.com/r1khilt/claymore/blob/main/src/claymore/api/app.py): FastAPI · Composes the backend runtime and route groups. · `src/claymore/api/app.py`
- [Agent & ask routes](https://github.com/r1khilt/claymore/blob/main/src/claymore/api/routes/agent.py): API routes · `src/claymore/api/routes/agent.py`
- [MCP server](https://github.com/r1khilt/claymore/blob/main/src/claymore/mcp_server/server.py): integration server · `src/claymore/mcp_server/server.py`
- [Messaging channels](https://github.com/r1khilt/claymore/blob/main/src/claymore/messaging/telegram.py): channel adapters · `src/claymore/messaging/telegram.py`

### Knowledge Loop

- [Ingestion pipeline](https://github.com/r1khilt/claymore/blob/main/src/claymore/ingest/pipeline.py): pipeline · Collects source artifacts and supports incremental ingestion. · `src/claymore/ingest/pipeline.py`
- [Normalize to episodes](https://github.com/r1khilt/claymore/blob/main/src/claymore/ingest/episodes.py): transformation · `src/claymore/ingest/episodes.py`
- [Composio connectors](https://github.com/r1khilt/claymore/blob/main/src/claymore/ingest/composio/manager.py): source boundary · Connects Slack, GitHub, Gmail, Notion, and similar sources. · `src/claymore/ingest/composio/manager.py`
- [Reconciliation](https://github.com/r1khilt/claymore/blob/main/src/claymore/memory/reconcile.py): canonicalization · Converts noisy events into attributed canonical knowledge. · `src/claymore/memory/reconcile.py`
- [Scientific memory graph](https://github.com/r1khilt/claymore/blob/main/src/claymore/memory/graph.py): knowledge graph · Ontology, identity, provenance, and retrieval layer. · `src/claymore/memory/graph.py`
- **Graphiti & FalkorDB**: graph services

### Agent Planning

- [Agent loop](https://github.com/r1khilt/claymore/blob/main/src/claymore/agent/agent_loop.py): orchestrator · Coordinates context, tools, temporal reasoning, and investigation work. · `src/claymore/agent/agent_loop.py`
- [Agent router](https://github.com/r1khilt/claymore/blob/main/src/claymore/agent/router.py): intent router · `src/claymore/agent/router.py`
- [Scene & protocol design](https://github.com/r1khilt/claymore/blob/main/src/claymore/agent/scene_designer.py): planner · `src/claymore/agent/scene_designer.py`
- [Claude APIs & SDK](https://github.com/r1khilt/claymore/blob/main/src/claymore/agent/llm.py): LLM runtime · `src/claymore/agent/llm.py`

### Execution & Control

- [Research execution](https://github.com/r1khilt/claymore/blob/main/src/claymore/execute/science_agent.py): dispatcher · Dispatches analysis, ML, datasets, workflows, and science agents. · `src/claymore/execute/science_agent.py`
- [Lab automation](https://github.com/r1khilt/claymore/blob/main/src/claymore/execute/opentrons.py): robot integration · Opentrons and project-scope PyLabRobot execution. · `src/claymore/execute/opentrons.py`
- [Approval & writeback](https://github.com/r1khilt/claymore/blob/main/src/claymore/actions/approvals.py): safety boundary · Gates consequential operations and external writes. · `src/claymore/actions/approvals.py`
- [Audit trail](https://github.com/r1khilt/claymore/blob/main/src/claymore/audit.py): audit log · `src/claymore/audit.py`

## Connections

- Operator UI → Web API client: uses
- Web API client → HTTP application: HTTP
- Messaging channels → HTTP application: alternate interaction
- MCP server → Agent loop: tool interaction
- HTTP application → Agent & ask routes: mounts
- Agent & ask routes → Agent loop: requests
- Composio connectors → Ingestion pipeline: source artifacts
- Ingestion pipeline → Normalize to episodes: raw context
- Normalize to episodes → Reconciliation: episodes
- Reconciliation → Scientific memory graph: canonical knowledge
- Scientific memory graph → Graphiti & FalkorDB: persists and queries
- Scientific memory graph → Agent loop: retrieval context
- Agent loop → Agent router: routes work
- Agent loop → Claude APIs & SDK: LLM calls
- Agent loop → Scene & protocol design: plans investigations
- Scene & protocol design → Research execution: protocols and tasks
- Research execution → Approval & writeback: consequential actions
- Approval & writeback → Lab automation: approved protocols
- Approval & writeback → Audit trail: decision record
- Research execution → Ingestion pipeline: results feedback · Execution results re-enter the knowledge loop.
- Lab automation → Ingestion pipeline: experimental results
