Reference service
The reference decision service is a small Python service on FastAPI and uvicorn, with a Docker image. It implements the server side of the protocol for any game that sends a valid manifest.
Source and releases: github.com/agent2game/a2g-service. Current release: v0.1.2 (protocol 0.1), Docker image ghcr.io/agent2game/a2g-service for amd64 and arm64.
What it does
Section titled “What it does”- Validates sessions, manifests (all field types, scopes, profiles, events, token budgets, cache rules) and every decide request against the client’s manifest; returns the manifest hash.
- Applies
/v1/contextupdates to scopes and profiles atomically. - Sends one request per batch to the active provider: OpenAI Decisions (default) or TypeSafe Jev, with one typed
choicequestion per entity offering only its legal actions. The input follows the specified order (world, scope chain, profiles, type descriptions, state, situation context, then entities), and all game values are passed as data, separate from the service’s instructions. - Computes session-scoped situation context:
population,nearby,observed_entities, theparentdecision andmembersof groups. - Enforces token budgets (~4 characters per token; warns in the console when a type’s budget is below its question size) and serves the decision cache (in memory, game-wide for trusted
localsessions). - Issues a
decision_idwith every AI decision and applies a report only once, for the session and entity it was issued to; stores the last 8 as memory. - Serves the Agent2Game Console at
/(optional,A2G_CONSOLE=offruns the service headless): a Provider switch saved across restarts, clients, context (scopes, profiles, entity types), entities with groups, decisions, cache hits, fallback codes, memory, costs and logs, with a Pretty/JSON view per card, a manifest editor (download, or apply as a console-side override for testing) and deletion of old sessions. - Stores session summaries, every priced provider call, manifest overrides and the provider choice in a local SQLite file, so spend survives restarts. Telemetry, memory and logs stay in memory.
- Holds the provider key; it is never sent to the game or the Agent2Game Console.
docker run -d --name a2g -p 127.0.0.1:8787:8787 -v a2g-data:/data -e TYPESAFE_API_KEY=... -e A2G_PROVIDER=jev ghcr.io/agent2game/a2g-service:0.1.2Use OPENAI_API_KEY (and no A2G_PROVIDER) for OpenAI Decisions. Keep -p 127.0.0.1:...: the local profile has no authentication, and publishing the port on all interfaces would expose the service, and your key’s budget, to your network. From a checkout of the repository: cp .env.example .env, add a key, docker compose up -d --build.
Settings (-e in Docker, or .env; the process environment wins):
| Variable | Meaning |
|---|---|
OPENAI_API_KEY, TYPESAFE_API_KEY |
Provider keys; only the active provider’s key is needed |
A2G_PROVIDER |
openai (default) or jev; a choice made in the Agent2Game Console overrides it |
A2G_ALLOWED_ORIGINS |
Exact loopback origins of browser games on local dev servers, comma-separated, for example http://localhost:5173 (rules) |
A2G_CONSOLE |
off serves only /v1/* and /health |
A2G_PROVIDER_CALLS |
Concurrent provider calls (default 16); match your provider’s rate limit |
A2G_QUESTIONS_PER_CALL |
Questions per provider call (default 64); bigger batches are split into parallel calls |
A2G_PORT, A2G_DB |
Listen port (default 8787) and SQLite file |
Without Docker: pip install -r requirements.txt, then python3 decision_service.py (Python 3.12+).
The service listens on http://127.0.0.1:8787 (Docker publishes it on 127.0.0.1 only; the SQLite file lives in a volume). It runs as one process, because sessions, the decision cache and memory are held in it. The local profile has no authentication, so do not expose it on a public interface. Open / for the Agent2Game Console and /health for status. The console uses relative paths, so it also works under a sub-path behind a game’s admin proxy (see Integrate).
Implementation status
Section titled “Implementation status”The specification leads; the reference implementations follow. Status of protocol 0.1 features:
| Feature | Reference service | Godot SDK | JS/TS SDK |
|---|---|---|---|
Scopes, profiles, /v1/context |
yes | yes: scope_provider, update_context() (replayed after a new session), track(..., {"profile": ...}) |
yes: scope option, updateContext(), track(..., { profile }) |
Groups (parent, members) |
yes | yes: set_parent() |
yes: setParent() |
Events (events, trigger, refresh_ms) |
yes | yes: adapter trigger(); refresh_ms as the default interval |
yes: adapter trigger(); refresh_ms as the default interval |
Field types vector2, vector3, entity_ref, lists, numeric enums |
yes | yes (passed through from the adapter) | yes (passed through from the adapter) |
| Token budget | yes (~4 chars/token) | n/a | n/a |
| Decision cache | yes: in memory, game-wide for local sessions; decisions with confidence below 0.5 are not cached; equivalent entities in one batch are asked once |
n/a (transparent) | n/a (transparent) |
| Decision slots | yes: no cap on slots; one question per slot, split across parallel provider calls above A2G_QUESTIONS_PER_CALL (default 64); per-slot fallback, cache and budget per entity |
yes: legal_actions / execute with {slot: ...} |
yes: same |
| Probabilities and sampling | yes: provider probabilities over the legal actions; reports may carry any legal action | yes: sample = sampler(rng) |
yes: sample: sampler(rng) |
| Manifest drift | yes: rejected decide requests and SDK-reported mismatches are counted and shown as a banner in the Agent2Game Console | yes: checks before sending, validate(node), a2g/debug/strict |
yes: checks before sending, validate(entity), strict: true |
| Fallback codes | yes | yes: kept per entity for debugging | yes: decision(entity) |
| Manifest hash | yes | yes: stored from the session response | yes |
decision_id in decisions and reports |
yes | yes | yes |
Local-profile request checks (Host, Origin, Content-Type) |
yes | n/a | n/a |
| Developer-listed browser origins | yes: A2G_ALLOWED_ORIGINS (comma-separated exact loopback origins) |
n/a | n/a (works with it) |
| Session-scoped context | yes | n/a | n/a |
401/403/409/429 handling |
409 only (no authentication in local) |
yes: reopen on 401/409, stop on 403, back off on 429 Retry-After |
yes: same as Godot |
Security: server/client profiles, API keys, join tokens, session tokens |
no: local profile only (loopback, no authentication) |
no | no (a headers option is ready for credentials) |
| Registered manifests, rate limits, client-session cache isolation | no | n/a | n/a |
The service rejects manifests with unknown keys and texts over the length limits, and checks its own examples against the JSON Schema in its test suite.
Planned: decision log and training
Section titled “Planned: decision log and training”- Persistent decision log per game and manifest hash (JSONL): context, legal actions, full probabilities, outcome, local prediction. Today all history is in memory and lost on restart.
- Training of local policies per entity type: decision trees first, then ensembles and small neural networks. Soft labels from the teacher’s probabilities; optional outcome weighting.
- Training report: agreement with the teacher per type and per situation, coverage map, model size, readable rules for trees.
- Agent2Game Console Policy tab: data per manifest version and data epoch, Train button, policy versions with metrics, shadow agreement, share of service calls in cascade.
- Local routes:
POST /v1/policy/trainandGET /v1/policy, part of the reference service, not of the protocol.
Limits
Section titled “Limits”| Limit | Value |
|---|---|
| Bind address | 127.0.0.1 only, the local security profile; never expose it |
| Concurrent provider calls | 16 by default (A2G_PROVIDER_CALLS); extra batches get FALLBACK with code: "busy" |
| Provider timeout | 3 s |
| Clients | No cap (one client per match on a game server); clients idle for 1 hour leave memory, their summaries stay in SQLite |
| Log events per client | 300 |
| Storage | Telemetry, memory and logs in memory; session summaries, costs, overrides and the provider choice in SQLite |
The service is meant for local development and evaluation. Hosted deployment needs authentication and an access model first.