# choria-io/fisk-ai architecture

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

- Interactive diagram: https://gitdiagram.com/choria-io/fisk-ai
- Repository: https://github.com/choria-io/fisk-ai

## Overview

#### Purpose and Entry Points
Fisk AI is a Go CLI that turns a Fisk-based command tree into a constrained LLM agent. The executable bootstraps subcommands for interactive runs, MCP serving, RAG, agent-to-agent operations, discovery, and session handling. Primary entry points: `main.go`, `run_command.go`, `mcp_command.go`, `a2a_command.go`, `rag_command.go`.

#### Configuration and Assembly
Configuration centralizes agent behavior, allowed Fisk commands, Anthropic access, remote tools, MCP built-ins, and RAG options. Command handlers assemble these dependencies before starting the relevant runtime. Paths: `config/config.go`, `run_command.go`, `remote_tools.go`.

#### Agent Execution Loop
The agent layer owns the prompt-to-action lifecycle: it invokes the LLM, emits execution events, dispatches tool calls, and coordinates runner state. Tool invocation results feed subsequent model turns until completion or termination. Paths: `internal/agent/agent.go`, `internal/agent/runner.go`, `internal/agent/events.go`.

#### Tool Boundary and Safety
The toolkit is the principal safety boundary between LLM output and local execution. It describes tools/schemas, obtains confirmation through a prompter, normalizes results, and adapts introspected Fisk commands into callable agent tools. Built-in tools expose controlled memory and RAG capabilities. Paths: `internal/toolkit/tool.go`, `internal/toolkit/fisk/fisk.go`, `internal/toolkit/builtin/builtin.go`, `internal/toolkit/prompter.go`.

#### LLM, Terminal, and Interactive UI
Anthropic is the material external LLM service; utility code provides LLM request handling and Anthropic-specific integration. The terminal UI renders live agent activity and implements interactive prompting/viewing, while run-event adapters connect agent events to it. Paths: `internal/util/anthropic.go`, `internal/util/llm.go`, `internal/tui/live.go`, `run_tui_events.go`.

#### Persistence: Sessions and Memory
Run state persists replayable session records with versioned JSON schemas, validation, fingerprints, and a file-backed store. A separate memory abstraction provides keyed storage with a file implementation. Session/resume commands operate at this persistence boundary. Paths: `internal/runstate/store.go`, `internal/runstate/file/file.go`, `internal/runstate/schemas/v1/session.meta.json`, `internal/memory/store.go`, `internal/memory/file/file.go`, `resume_replay.go`.

#### RAG Knowledge Pipeline
RAG ingests local content, chunks and embeds it, stores vectors, and serves similarity search. It includes filesystem safety/locking and a watch mode for maintaining an index as source content changes. The agent receives RAG through built-in toolkit tools rather than direct store access. Paths: `internal/rag/index.go`, `internal/rag/embed.go`, `internal/rag/search.go`, `internal/rag/watch.go`, `internal/toolkit/builtin/builtin_rag.go`.

#### Interoperability: MCP, Remote Tools, and A2A
The MCP server exposes capabilities to MCP clients; remote-tools support integrates externally supplied tools. The A2A subsystem defines versioned protocol messages, transport/server/client interfaces, a registry, remote dispatch, and a NATS transport implementation. These are network boundaries distinct from local Fisk execution. Paths: `internal/mcpserver/mcpserver.go`, `internal/remotetools/remotetools.go`, `internal/a2a/server.go`, `internal/a2a/client.go`, `internal/a2a/nats/nats.go`, `internal/a2a/schemas/v1/request.json`.

Main entry points: [`run_command.go`](https://github.com/choria-io/fisk-ai/blob/main/run_command.go) (Command handlers), [`internal/toolkit/tool.go`](https://github.com/choria-io/fisk-ai/blob/main/internal/toolkit/tool.go) (Toolkit), [`internal/agent/runner.go`](https://github.com/choria-io/fisk-ai/blob/main/internal/agent/runner.go) (Agent runner), [`internal/agent/agent.go`](https://github.com/choria-io/fisk-ai/blob/main/internal/agent/agent.go) (Agent core)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI &amp; assembly"]
  node_main["CLI bootstrap<br/>Go entrypoint<br/>[main.go]"]
  node_commands["Command handlers<br/>CLI commands<br/>[run_command.go]"]
  node_config["Configuration<br/>[config.go]"]
  node_remote_setup["Remote tool setup<br/>CLI integration<br/>[remote_tools.go]"]
end

subgraph group_agent["Agent runtime"]
  node_runner["Agent runner<br/>execution loop<br/>[runner.go]"]
  node_agent_core["Agent core<br/>agent orchestration<br/>[agent.go]"]
  node_events["Execution events<br/>event model<br/>[events.go]"]
  node_llm{{"Anthropic LLM<br/>LLM integration<br/>[anthropic.go]"}}
  node_tui["Live terminal UI<br/>interactive UI<br/>[live.go]"]
  node_tui_events["TUI event adapter<br/>[run_tui_events.go]"]
end

subgraph group_tools["Tool safety &amp; knowledge"]
  node_toolkit["Toolkit<br/>tool safety boundary<br/>[tool.go]"]
  node_fisk_tools["Fisk command adapter<br/>local tool adapter<br/>[fisk.go]"]
  node_builtin_tools["Built-in tools<br/>agent tools<br/>[builtin.go]"]
  node_prompter["Confirmation prompter<br/>safety interaction<br/>[prompter.go]"]
  node_rag[("RAG index &amp; search<br/>knowledge pipeline<br/>[index.go]")]
  node_rag_watch["RAG watch mode<br/>index maintenance<br/>[watch.go]"]
end

subgraph group_state["State"]
  node_sessions[("Session store<br/>replayable run state<br/>[file.go]")]
  node_memory[("File memory store<br/>keyed storage<br/>[file.go]")]
end

subgraph group_interop["Interoperability"]
  node_mcp{{"MCP server<br/>MCP boundary<br/>[mcpserver.go]"}}
  node_remote_tools{{"Remote tools<br/>external tool boundary<br/>[remotetools.go]"}}
  node_a2a{{"A2A server &amp; client<br/>agent network protocol<br/>[server.go]"}}
  node_nats{{"NATS transport<br/>A2A transport<br/>[nats.go]"}}
end

node_main -->|"starts"| node_commands
node_commands -->|"loads"| node_config
node_commands -->|"launches runs"| node_runner
node_commands -->|"serves"| node_mcp
node_commands -->|"runs A2A"| node_a2a
node_commands -->|"indexes/searches"| node_rag
node_commands -->|"configures"| node_remote_setup
node_remote_setup -->|"connects"| node_remote_tools
node_runner -->|"coordinates"| node_agent_core
node_agent_core -->|"requests turns"| node_llm
node_agent_core -->|"dispatches calls"| node_toolkit
node_runner -->|"emits"| node_events
node_events -->|"adapts"| node_tui_events
node_tui_events -->|"renders"| node_tui
node_toolkit -->|"confirms actions"| node_prompter
node_toolkit -->|"exposes"| node_fisk_tools
node_toolkit -->|"exposes"| node_builtin_tools
node_toolkit -->|"calls"| node_remote_tools
node_builtin_tools -->|"reads/writes"| node_memory
node_builtin_tools -->|"queries"| node_rag
node_rag_watch -->|"updates"| node_rag
node_runner -->|"persists runs"| node_sessions
node_a2a -->|"uses transport"| node_nats
node_mcp -->|"exposes tools"| node_toolkit

click node_main "https://github.com/choria-io/fisk-ai/blob/main/main.go"
click node_commands "https://github.com/choria-io/fisk-ai/blob/main/run_command.go"
click node_config "https://github.com/choria-io/fisk-ai/blob/main/config/config.go"
click node_remote_setup "https://github.com/choria-io/fisk-ai/blob/main/remote_tools.go"
click node_runner "https://github.com/choria-io/fisk-ai/blob/main/internal/agent/runner.go"
click node_agent_core "https://github.com/choria-io/fisk-ai/blob/main/internal/agent/agent.go"
click node_events "https://github.com/choria-io/fisk-ai/blob/main/internal/agent/events.go"
click node_llm "https://github.com/choria-io/fisk-ai/blob/main/internal/util/anthropic.go"
click node_tui "https://github.com/choria-io/fisk-ai/blob/main/internal/tui/live.go"
click node_tui_events "https://github.com/choria-io/fisk-ai/blob/main/run_tui_events.go"
click node_toolkit "https://github.com/choria-io/fisk-ai/blob/main/internal/toolkit/tool.go"
click node_fisk_tools "https://github.com/choria-io/fisk-ai/blob/main/internal/toolkit/fisk/fisk.go"
click node_builtin_tools "https://github.com/choria-io/fisk-ai/blob/main/internal/toolkit/builtin/builtin.go"
click node_prompter "https://github.com/choria-io/fisk-ai/blob/main/internal/toolkit/prompter.go"
click node_rag "https://github.com/choria-io/fisk-ai/blob/main/internal/rag/index.go"
click node_rag_watch "https://github.com/choria-io/fisk-ai/blob/main/internal/rag/watch.go"
click node_sessions "https://github.com/choria-io/fisk-ai/blob/main/internal/runstate/file/file.go"
click node_memory "https://github.com/choria-io/fisk-ai/blob/main/internal/memory/file/file.go"
click node_mcp "https://github.com/choria-io/fisk-ai/blob/main/internal/mcpserver/mcpserver.go"
click node_remote_tools "https://github.com/choria-io/fisk-ai/blob/main/internal/remotetools/remotetools.go"
click node_a2a "https://github.com/choria-io/fisk-ai/blob/main/internal/a2a/server.go"
click node_nats "https://github.com/choria-io/fisk-ai/blob/main/internal/a2a/nats/nats.go"

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_main,node_commands,node_config,node_remote_setup toneBlue
class node_runner,node_agent_core,node_events,node_llm,node_tui,node_tui_events toneAmber
class node_toolkit,node_fisk_tools,node_builtin_tools,node_prompter,node_rag,node_rag_watch toneMint
class node_sessions,node_memory toneRose
class node_mcp,node_remote_tools,node_a2a,node_nats toneIndigo
```

## Components

### CLI & assembly

- [CLI bootstrap](https://github.com/choria-io/fisk-ai/blob/main/main.go): Go entrypoint · Registers operational subcommands. · `main.go`
- [Command handlers](https://github.com/choria-io/fisk-ai/blob/main/run_command.go): CLI commands · Assemble dependencies for run, MCP, A2A, and RAG modes. · `run_command.go`
- [Configuration](https://github.com/choria-io/fisk-ai/blob/main/config/config.go): config · Defines agent, command, provider, tool, MCP, and RAG options. · `config/config.go`
- [Remote tool setup](https://github.com/choria-io/fisk-ai/blob/main/remote_tools.go): CLI integration · `remote_tools.go`

### Agent runtime

- [Agent runner](https://github.com/choria-io/fisk-ai/blob/main/internal/agent/runner.go): execution loop · Coordinates model turns, tool actions, and completion. · `internal/agent/runner.go`
- [Agent core](https://github.com/choria-io/fisk-ai/blob/main/internal/agent/agent.go): agent orchestration · Invokes the LLM and dispatches requested tools. · `internal/agent/agent.go`
- [Execution events](https://github.com/choria-io/fisk-ai/blob/main/internal/agent/events.go): event model · `internal/agent/events.go`
- [Anthropic LLM](https://github.com/choria-io/fisk-ai/blob/main/internal/util/anthropic.go): LLM integration · Handles provider requests and Anthropic-specific integration. · `internal/util/anthropic.go`
- [Live terminal UI](https://github.com/choria-io/fisk-ai/blob/main/internal/tui/live.go): interactive UI · Renders agent activity and gathers interactive input. · `internal/tui/live.go`
- [TUI event adapter](https://github.com/choria-io/fisk-ai/blob/main/run_tui_events.go): event adapter · `run_tui_events.go`

### Tool safety & knowledge

- [Toolkit](https://github.com/choria-io/fisk-ai/blob/main/internal/toolkit/tool.go): tool safety boundary · Describes tools, confirms execution, and normalizes results. · `internal/toolkit/tool.go`
- [Fisk command adapter](https://github.com/choria-io/fisk-ai/blob/main/internal/toolkit/fisk/fisk.go): local tool adapter · Converts introspected Fisk commands into callable tools. · `internal/toolkit/fisk/fisk.go`
- [Built-in tools](https://github.com/choria-io/fisk-ai/blob/main/internal/toolkit/builtin/builtin.go): agent tools · Exposes controlled memory and RAG capabilities. · `internal/toolkit/builtin/builtin.go`
- [Confirmation prompter](https://github.com/choria-io/fisk-ai/blob/main/internal/toolkit/prompter.go): safety interaction · `internal/toolkit/prompter.go`
- [RAG index & search](https://github.com/choria-io/fisk-ai/blob/main/internal/rag/index.go): knowledge pipeline · Indexes, embeds, and similarity-searches local content. · `internal/rag/index.go`
- [RAG watch mode](https://github.com/choria-io/fisk-ai/blob/main/internal/rag/watch.go): index maintenance · Maintains the index as source content changes. · `internal/rag/watch.go`

### State

- [Session store](https://github.com/choria-io/fisk-ai/blob/main/internal/runstate/file/file.go): replayable run state · Persists versioned, validated session records in files. · `internal/runstate/file/file.go`
- [File memory store](https://github.com/choria-io/fisk-ai/blob/main/internal/memory/file/file.go): keyed storage · `internal/memory/file/file.go`

### Interoperability

- [MCP server](https://github.com/choria-io/fisk-ai/blob/main/internal/mcpserver/mcpserver.go): MCP boundary · Exposes capabilities to MCP clients. · `internal/mcpserver/mcpserver.go`
- [Remote tools](https://github.com/choria-io/fisk-ai/blob/main/internal/remotetools/remotetools.go): external tool boundary · Integrates externally supplied tools. · `internal/remotetools/remotetools.go`
- [A2A server & client](https://github.com/choria-io/fisk-ai/blob/main/internal/a2a/server.go): agent network protocol · Provides protocol, registry, remote dispatch, and transport interfaces. · `internal/a2a/server.go`
- [NATS transport](https://github.com/choria-io/fisk-ai/blob/main/internal/a2a/nats/nats.go): A2A transport · `internal/a2a/nats/nats.go`

## Connections

- CLI bootstrap → Command handlers: starts
- Command handlers → Configuration: loads
- Command handlers → Agent runner: launches runs
- Command handlers → MCP server: serves
- Command handlers → A2A server & client: runs A2A
- Command handlers → RAG index & search: indexes/searches
- Command handlers → Remote tool setup: configures
- Remote tool setup → Remote tools: connects
- Agent runner → Agent core: coordinates
- Agent core → Anthropic LLM: requests turns
- Agent core → Toolkit: dispatches calls
- Agent runner → Execution events: emits
- Execution events → TUI event adapter: adapts
- TUI event adapter → Live terminal UI: renders
- Toolkit → Confirmation prompter: confirms actions
- Toolkit → Fisk command adapter: exposes
- Toolkit → Built-in tools: exposes
- Toolkit → Remote tools: calls
- Built-in tools → File memory store: reads/writes
- Built-in tools → RAG index & search: queries
- RAG watch mode → RAG index & search: updates
- Agent runner → Session store: persists runs
- A2A server & client → NATS transport: uses transport
- MCP server → Toolkit: exposes tools
