# chartyr/sts2-agent architecture

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

- Interactive diagram: https://gitdiagram.com/chartyr/sts2-agent
- Repository: https://github.com/chartyr/sts2-agent

## Overview

STS2 AI Agent is an in-game Slay the Spire 2 companion mod with autonomous play, a configurable overlay, local APIs, and an optional co-op teammate. The player starts auto-play through the overlay; the runtime coordinates turns, obtains game state, requests model decisions, and dispatches game actions. Separate branches provide co-op coordination, live events, and developer access through HTTP/MCP. Relationships are grounded in the README and indexed excerpts; unsampled implementation details are represented conservatively.

Main entry points: [`STS2AIAgent/Agent/AgentRuntime.cs`](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Agent/AgentRuntime.cs) (Agent runtime), [`STS2AIAgent/Game/GameStateService.cs`](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Game/GameStateService.cs) (Game state), [`STS2AIAgent/Agent/AgentLoop.cs`](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Agent/AgentLoop.cs) (Auto-play loop), [`STS2AIAgent/Server/Router.cs`](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Server/Router.cs) (API routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Mod and Overlay"]
  node_mod["Mod startup<br/>[ModEntry.cs]"]
  node_overlay["In-game overlay"]
  node_settings["Settings and models<br/>[AgentSettings.cs]"]
end

subgraph group_play["Gameplay Runtime"]
  node_runtime["Agent runtime<br/>[AgentRuntime.cs]"]
  node_loop["Auto-play loop<br/>[AgentLoop.cs]"]
  node_decision["Strategy planning<br/>[StrategyPlanner.cs]"]
  node_budget["Session guards"]
  node_history[("Play history")]
  node_llm["Chat completion client"]
end

subgraph group_game["Game Integration"]
  node_bridge["Game bridge<br/>[GameBridge.cs]"]
  node_state["Game state"]
  node_actions["Game actions"]
  node_thread["Game-thread dispatch<br/>[GameThread.cs]"]
  node_screenshots["Screenshot capture"]
end

subgraph group_services["Local Services"]
  node_http["HTTP API<br/>[HttpServer.cs]"]
  node_router["API routes<br/>[Router.cs]"]
  node_events["Game event stream"]
  node_mcp["Native MCP server<br/>[NativeMcpServer.cs]"]
end

subgraph group_coop["Co-op Companion"]
  node_coop["Co-op coordination"]
  node_teamchat["Team conversation"]
end

node_player(("Player"))
node_provider(("LLM endpoint"))
node_game(("Slay the Spire 2"))
node_developers(("External agent tools"))
node_companion(("Companion instance"))

node_player -->|"opens and controls"| node_overlay
node_mod -->|"initializes"| node_overlay
node_mod -->|"initializes"| node_runtime
node_mod -->|"starts"| node_http
node_overlay -->|"configures"| node_settings
node_overlay -->|"controls play"| node_runtime
node_runtime -->|"starts turns"| node_loop
node_runtime -->|"creates"| node_bridge
node_runtime -->|"stores sessions"| node_history
node_runtime -->|"binds runtime"| node_mcp
node_loop -.->|"plans decisions"| node_decision
node_loop -.->|"checks limits"| node_budget
node_loop -.->|"requests decisions"| node_llm
node_settings -.->|"configures endpoint"| node_llm
node_llm -->|"sends completions"| node_provider
node_bridge -.->|"reads state"| node_state
node_bridge -.->|"dispatches actions"| node_actions
node_state -->|"observes"| node_game
node_actions -->|"executes actions"| node_game
node_actions -->|"dispatches game work"| node_thread
node_state -->|"builds state on"| node_thread
node_screenshots -->|"captures on"| node_thread
node_http -.->|"routes requests"| node_router
node_router -->|"controls agent"| node_runtime
node_router -->|"serves state"| node_state
node_router -->|"dispatches actions"| node_actions
node_events -->|"polls state"| node_state
node_developers -->|"uses API"| node_http
node_developers -->|"connects via MCP"| node_mcp
node_runtime -.->|"coordinates launch"| node_coop
node_runtime -->|"handles team chat"| node_teamchat
node_coop -->|"launches instance"| node_companion
node_player -->|"sends instructions"| node_teamchat

click node_mod "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/ModEntry.cs"
click node_overlay "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Ui/AgentOverlayHost.cs"
click node_settings "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Config/AgentSettings.cs"
click node_runtime "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Agent/AgentRuntime.cs"
click node_loop "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Agent/AgentLoop.cs"
click node_decision "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Agent/StrategyPlanner.cs"
click node_budget "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Agent/SessionBudgetGuard.cs"
click node_history "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Agent/PlaySessionStore.cs"
click node_llm "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Llm/OpenAiCompatibleClient.cs"
click node_bridge "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Agent/GameBridge.cs"
click node_state "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Game/GameStateService.cs"
click node_actions "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Game/GameActionService.cs"
click node_thread "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Game/GameThread.cs"
click node_screenshots "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Vision/ScreenshotService.cs"
click node_http "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Server/HttpServer.cs"
click node_router "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Server/Router.cs"
click node_events "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Server/GameEventService.cs"
click node_mcp "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Server/NativeMcpServer.cs"
click node_coop "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Multiplayer/DualInstanceCoordinator.cs"
click node_teamchat "https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Multiplayer/TeamConversation.cs"

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_mod,node_overlay,node_settings toneBlue
class node_runtime,node_loop,node_decision,node_budget,node_history,node_llm toneAmber
class node_bridge,node_state,node_actions,node_thread,node_screenshots toneMint
class node_http,node_router,node_events,node_mcp toneRose
class node_coop,node_teamchat,node_player,node_provider,node_game,node_developers,node_companion toneIndigo
```

## Components

### Mod and Overlay

- [Mod startup](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/ModEntry.cs): `STS2AIAgent/ModEntry.cs`
- [In-game overlay](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Ui/AgentOverlayHost.cs): `STS2AIAgent/Ui/AgentOverlayHost.cs`
- [Settings and models](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Config/AgentSettings.cs): `STS2AIAgent/Config/AgentSettings.cs`

### Gameplay Runtime

- [Agent runtime](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Agent/AgentRuntime.cs): `STS2AIAgent/Agent/AgentRuntime.cs`
- [Auto-play loop](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Agent/AgentLoop.cs): `STS2AIAgent/Agent/AgentLoop.cs`
- [Strategy planning](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Agent/StrategyPlanner.cs): `STS2AIAgent/Agent/StrategyPlanner.cs`
- [Session guards](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Agent/SessionBudgetGuard.cs): `STS2AIAgent/Agent/SessionBudgetGuard.cs`
- [Play history](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Agent/PlaySessionStore.cs): `STS2AIAgent/Agent/PlaySessionStore.cs`
- [Chat completion client](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Llm/OpenAiCompatibleClient.cs): `STS2AIAgent/Llm/OpenAiCompatibleClient.cs`

### Game Integration

- [Game bridge](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Agent/GameBridge.cs): `STS2AIAgent/Agent/GameBridge.cs`
- [Game state](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Game/GameStateService.cs): `STS2AIAgent/Game/GameStateService.cs`
- [Game actions](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Game/GameActionService.cs): `STS2AIAgent/Game/GameActionService.cs`
- [Game-thread dispatch](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Game/GameThread.cs): `STS2AIAgent/Game/GameThread.cs`
- [Screenshot capture](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Vision/ScreenshotService.cs): `STS2AIAgent/Vision/ScreenshotService.cs`

### Local Services

- [HTTP API](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Server/HttpServer.cs): `STS2AIAgent/Server/HttpServer.cs`
- [API routes](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Server/Router.cs): `STS2AIAgent/Server/Router.cs`
- [Game event stream](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Server/GameEventService.cs): `STS2AIAgent/Server/GameEventService.cs`
- [Native MCP server](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Server/NativeMcpServer.cs): `STS2AIAgent/Server/NativeMcpServer.cs`

### Co-op Companion

- [Co-op coordination](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Multiplayer/DualInstanceCoordinator.cs): `STS2AIAgent/Multiplayer/DualInstanceCoordinator.cs`
- [Team conversation](https://github.com/chartyr/sts2-agent/blob/main/STS2AIAgent/Multiplayer/TeamConversation.cs): `STS2AIAgent/Multiplayer/TeamConversation.cs`

### Other components

- **Player**
- **LLM endpoint**
- **Slay the Spire 2**
- **External agent tools**
- **Companion instance**

## Connections

- Player → In-game overlay: opens and controls (evidence: `README.md`)
- Mod startup → In-game overlay: initializes (evidence: `STS2AIAgent/ModEntry.cs`)
- Mod startup → Agent runtime: initializes (evidence: `STS2AIAgent/ModEntry.cs`)
- Mod startup → HTTP API: starts (evidence: `STS2AIAgent/ModEntry.cs`)
- In-game overlay → Settings and models: configures (evidence: `STS2AIAgent/Ui/AgentOverlayHost.Settings.cs`)
- In-game overlay → Agent runtime: controls play (evidence: `STS2AIAgent/Ui/AgentOverlayHost.Settings.cs`)
- Agent runtime → Auto-play loop: starts turns (evidence: `STS2AIAgent/Agent/AgentRuntime.cs`)
- Agent runtime → Game bridge: creates (evidence: `STS2AIAgent/Agent/AgentRuntime.cs`)
- Agent runtime → Play history: stores sessions (evidence: `STS2AIAgent/Agent/AgentRuntime.cs`)
- Agent runtime → Native MCP server: binds runtime (evidence: `STS2AIAgent/Agent/AgentRuntime.cs`)
- Auto-play loop → Strategy planning: plans decisions
- Auto-play loop → Session guards: checks limits
- Auto-play loop → Chat completion client: requests decisions
- Settings and models → Chat completion client: configures endpoint
- Chat completion client → LLM endpoint: sends completions (evidence: `STS2AIAgent/Llm/OpenAiCompatibleClient.cs`)
- Game bridge → Game state: reads state
- Game bridge → Game actions: dispatches actions
- Game state → Slay the Spire 2: observes (evidence: `STS2AIAgent/Game/GameStateService.cs`)
- Game actions → Slay the Spire 2: executes actions (evidence: `STS2AIAgent/Game/GameActionService.cs`)
- Game actions → Game-thread dispatch: dispatches game work (evidence: `STS2AIAgent/Game/GameActionService.cs`)
- Game state → Game-thread dispatch: builds state on (evidence: `STS2AIAgent/Server/GameEventService.cs`)
- Screenshot capture → Game-thread dispatch: captures on (evidence: `STS2AIAgent/Vision/ScreenshotService.cs`)
- HTTP API → API routes: routes requests (evidence: `STS2AIAgent/Server/HttpServer.cs`)
- API routes → Agent runtime: controls agent (evidence: `STS2AIAgent/Server/Router.cs`)
- API routes → Game state: serves state (evidence: `STS2AIAgent/Server/Router.cs`)
- API routes → Game actions: dispatches actions (evidence: `STS2AIAgent/Server/Router.cs`)
- Game event stream → Game state: polls state (evidence: `STS2AIAgent/Server/GameEventService.cs`)
- External agent tools → HTTP API: uses API (evidence: `README.md`)
- External agent tools → Native MCP server: connects via MCP (evidence: `README.md`)
- Agent runtime → Co-op coordination: coordinates launch (evidence: `STS2AIAgent/Agent/AgentRuntime.cs`)
- Agent runtime → Team conversation: handles team chat (evidence: `STS2AIAgent/Agent/AgentRuntime.cs`)
- Co-op coordination → Companion instance: launches instance (evidence: `README.md`)
- Player → Team conversation: sends instructions (evidence: `README.md`)
