Godot SDK
The Godot SDK is a Godot 4 addon, addons/a2g/, that registers the autoload A2G. It implements the client side of the protocol and contains no game-specific code.
Source and releases: github.com/agent2game/a2g-sdk-godot. Current release: v0.3.0 (protocol 0.1, Godot 4.7). The repository also has a minimal demo and offline tests.
Install
Section titled “Install”- Download
addons/a2g/from a release (the release archive contains only the addon) and copy it into your project. - Enable Project → Project Settings → Plugins → A2G. This adds the
A2Gautoload and thea2g/*settings below. - Put your manifest at
res://a2g_manifest.json, write an adapter and hook your entities (guide).
What it does
Section titled “What it does”- Loads
res://a2g_manifest.jsonand opens a session; keeps the returnedmanifest_hash; reopens after401/409or a service restart and replays earlier context updates. - Every 0.25 s collects tracked entities whose refresh interval has passed or that raised an event and sends up to 16 of them in one decide request, with at most 2 requests in flight. Adds the active scope and its state, each entity’s position, profile, parent and trigger.
- Re-asks every entity (after ≥ 500 ms) when the number of tracked entities changes.
- Drops replies from an old epoch, re-checks that the action was offered and has a
decision_id, and expires decisions afterttl_ms. - Sends a report with the
decision_idwhen a decision ends, with numeric deltas of the observation and world. - Sends telemetry every second (also while paused, without asking for decisions) and checks
/healthevery 5 s. - Stops asking after
403; waits forRetry-Afterafter429. - Starts in native mode; AI mode is switched on explicitly (
set_ai_enabled(true)or the--a2g-aicommand-line flag).
# Setup (usually in your adapter's _ready)A2G.world_provider = func() -> Dictionary: return {...} # shared world stateA2G.scope_provider = func() -> Dictionary: return {"scope": "cave", "state": {...}} # active scope, or {}A2G.register_adapter("bee", adapter) # one adapter per entity typeA2G.update_context({"boss_arena": {...}}, {"old_bat": null}) # add/replace/remove scopes and profilesA2G.scope_ready("boss_arena") # true once the service accepted it
# In each entityA2G.track(self, "bee", {"profile": "queen_bee", "parent": leader}) # in _ready; options are optionalA2G.set_parent(self, squad) # join or leave (null) a group laterif A2G.execute(self, delta): # in _physics_process; true = A2G controls this frame return
# ModeA2G.set_ai_enabled(true) # increments the epoch and clears decisions
# Sampling (optional): draw actions from the provider's probabilities with the game's seeded RNGA2G.sample = A2G.sampler(game_rng)Adapter contract
Section titled “Adapter contract”| Method | Required | Purpose |
|---|---|---|
observe(node) -> Dictionary |
yes | Observation fields declared for the type |
legal_actions(node) -> Array |
yes | Actions allowed now; empty means “do not ask” (observe-only types). For decision slots: {slot: Array} for the slots to ask |
execute(node, action, delta) -> bool |
yes | Perform the action; false = blocked, the adapter did something safe instead. For decision slots action is {slot: action} for the decided slots; run native AI for the rest |
state(node) -> String |
no | Actual executed state for telemetry |
position(node) -> Vector2/Vector3 |
no | Enables nearby and group member ordering |
trigger(node) -> String |
no | Name of a manifest event that just happened, or ""; asks for a decision now |
interval_ms(node) -> int |
no | Refresh interval (default: the type’s refresh_ms, then 3000 ms) |
release(node) |
no | Called when native AI takes control back |
Configuration
Section titled “Configuration”Project Settings under a2g/, read at startup. Defaults apply when a setting is absent.
| Setting | Default | Meaning |
|---|---|---|
a2g/service/url |
http://127.0.0.1:8787 |
Decision service base URL |
a2g/manifest_path |
res://a2g_manifest.json |
The manifest |
a2g/decisions/max_batch |
16 |
Entities per decide request, capped at the protocol maximum of 16 |
a2g/decisions/max_inflight |
2 |
Decide requests in flight at once |
a2g/decisions/batch_interval |
0.25 |
Seconds between batch checks |
a2g/decisions/default_interval_ms |
3000 |
Refresh interval when neither the adapter nor the manifest sets one |
a2g/decisions/min_interval_ms |
500 |
Minimum time between two requests for one entity |
a2g/debug/strict |
false |
Manifest drift checks print an error every time instead of one warning, so headless test runs fail on a mismatch |
Manifest drift checks
Section titled “Manifest drift checks”Before anything is sent, the SDK checks each observation, the world and every legal action against the manifest. A mismatch never reaches the service: the node stays on native AI (decision code mismatch), last_error names the field and value, and push_warning reports each problem once. A2G.validate(node) returns the problems for one node, and a2g/debug/strict turns them into errors for test runs. See Keep it in sync.
Implementation status
Section titled “Implementation status”Session tokens and the server/client security profiles are not supported yet. See the status table.
Planned: local policy
Section titled “Planned: local policy”A2G.set_mode("native" | "local" | "service" | "cascade" | "shadow"), replacingset_ai_enabled; a--a2g-mode=flag for headless runs.- Loads
res://a2g_policy.json, checks itsmanifest_hash, and evaluates it in GDScript per the policy format, passing the conformance vectors. - Cascade threshold per entity type;
shadowpredictions sent in reports. A2G.network_enabled = falsefor release builds that run onlylocal.- Debug overlay: mode switch for all five modes, per-entity source (
native / LOCAL / AI / FALLBACK), policy version, shadow agreement.
Other engines
Section titled “Other engines”Web and Node games use the JS/TS SDK. There is no SDK for Unity, Unreal or other engines yet. Any client that follows the specification works with the service. A Unity SDK with a C# policy evaluator is the planned next engine SDK; it must pass the same conformance vectors, so one policy file behaves the same in Godot and Unity.