High-level architecture
A Singleship Agent in D can be structured as an HTTP‑speaking “mini
service” with clear perception–decision–action–learning stages around
the Galaxy Simulator’s vibe.d API.
The diagram below shows the major components inside a Singleship
Agent and how it talks to the Galaxy Simulator over HTTP.
Key parts inside the Singleship Agent:
- HTTP Client Layer
- Wraps vibe.d HTTP client; handles auth tokens, session management, retries, backoff, and rate limiting.
-
Exposes typed methods like
getShipState(),postAction(NavigateTo ...),subscribeEvents().
- Domain Models
-
structs/classes for
ShipState,WorldState,Goal,Policy,Action, etc., as the internal canonical representation. - All HTTP JSON is translated into and out of these types so the rest of the agent never sees raw JSON.
-
structs/classes for
- Perception Module
- Periodically (or event‑driven) pulls data via HTTP (ship status, local space, contacts, missions) and normalizes it into Domain Models.
- Can precompute derived values (threat levels, fuel margin, ETA) so the policy engine consumes higher‑level features.
- Decision / Policy Engine
-
Chooses the next high‑level action given current
ShipState,WorldState, and activeGoalset. - Initially rule‑based (D code / tables); later you can swap or augment it with RL or LLM‑assisted policies without touching the HTTP or domain layers.
-
Chooses the next high‑level action given current
- Planning Module
- Expands goals like “survey system X” into an ordered/branching plan: navigate → scan → log results → refuel if needed.
- Maintains an action queue that the executor consumes; can replan when perception reports big state changes.
- Action Executor
-
Dequeues actions (e.g.,
ChangeCourse,FireThrusters,ScanSector,Dock) and turns them into concrete HTTP calls to the Galaxy Simulator API. - Interprets responses, handles transient failures, and feeds success/failure back into Domain Models and the Learning Module.
-
Dequeues actions (e.g.,
- Learning Module
- Records tuples like (state features, chosen action, outcome, reward) in a local store (files, embedded DB) for offline or online learning.
- Periodically updates the Policy Engine (e.g., tweak thresholds, choose better heuristics, or retrain an external model that the D agent queries).
- Persistence & Logs
- Stores configuration (policy parameters, personality), last known state, and detailed logs for GM replay/debugging.
- Lets a GM reload an agent with its “experience” and reattach it to a running ship.
- Telemetry / Debug Interface
- Simple HTTP (or WebSocket) endpoint served by the agent itself, or a CLI/REPL, exposing introspection: current plans, goals, recent decisions.
- A GM/Developer Console can connect here to observe or nudge the agent without going through the Galaxy Simulator API.