Golem agent reflection

From golemcloud/golem · View interactive version

Golem agent reflection is an AI agent skill from the GitHub repository golemcloud/golem. Choosing and composing Golem client approaches across SDKs. Use when caller-defined schemas, runtime discovery, fully dynamic invocation, or connecting to an existing agent by its agent ID is needed.

How to use this skill

Skill file

Agent Reflection

There are four client approaches. Normal RPC is the non-reflective baseline; the other three are

reflection approaches that can be composed:

| Client approach | Choose it when | Identity and lifecycle | Validation |

|---|---|---|---|

| Normal RPC | Producer and caller share a source definition through the SDK's ordinary RPC mechanism | The shared definition owns the upsert, create, and get-by-id factories allowed by its mode (ephemeral types have only upsert) | Its static codecs validate typed inputs and decode declared outputs |

| Caller-defined static clients | The caller owns compile-time schemas and codecs without deployment discovery | Method-only agent clients connect to an existing durable agent by its agent ID; full agent clients own lifecycle factories; typed tool definitions select commands | Local codecs validate calls and outputs; full clients also check the declared type name, constructor shape, and configuration |

| Discovered clients | The deployed agent type, method, tool, or command is selected from the current environment | Discovery returns immutable, snapshot-backed Reflected* clients and factories for the discovered mode | The retained snapshot automatically validates inputs and declared outputs |

| Fully dynamic clients | Infrastructure transports already packed schema-native values without retaining a schema authority | DynamicAgentClient connects to an existing durable agent by its agent ID; DynamicToolClient invokes an explicit tool name and command path | The caller owns packing and validation policy; the host still performs authorization and target-side validation |

Caller-defined static agent clients have two deliberately different options: method-only and full.

Caller-defined static tool clients use caller-owned typed definitions.

An agent ID is a UUID that Golem issues; it carries a tag of the agent's type but not its constructor parameters, so no SDK computes it offline. Agents are stored and addressed per environment and agent ID. Get an ID from a client (agentId / agent_id), from invocation metadata, or from agent metadata. A keyed agent is also reachable by its key, the canonical Type(parameters) text of its constructor parameters; upsert always uses a key. An agent created without a key is reachable only by its ID.

Constructor values contain only caller-supplied fields. The host injects principal fields separately. An ephemeral client is a logical proxy: each invocation runs on a new one-shot instance whose agent ID only the invocation metadata reports, and that ID cannot be used for another call.

Discovery lookups are optional: a name or agent-ID lookup returns no type when the deployment is missing or the caller cannot view it. Parsing an agent ID is strict and reports malformed input. Neither discovery nor connecting by ID ever creates the target agent; an unknown ID, or the ID of an agent of another type, is a typed not-found error. A keyed create of an existing key is a typed conflict error.

Reflected schema graphs and invocation metadata are immutable snapshots. Validate or pack JSON through the reflected constructor or method schema, and treat a missing, extra, graph-incompatible, or malformed declared output as a remote output error. Rediscover explicitly when a fresh deployment snapshot is required; a client never refreshes itself automatically.

Creation-time configuration overrides are optional because component defaults may satisfy required local declarations. Reflected and full clients validate known declaration paths, values, and secret restrictions locally before opening RPC. Method-only clients may carry raw typed entries without claiming declaration-aware validation. The host validates the effective configuration when creating the worker, provisions secrets, authorizes the call, and validates the target-side input. Overrides exist only on create: upsert and connecting by ID take none, and an existing durable agent keeps its persisted initial configuration.

Validation boundaries

Optional values and canonical JSON

Normal RPC and caller-defined static clients use the language's normal optional-field syntax. In reflected JSON, an omitted option<T> record field and an explicit null both decode as absent; re-encoding may include the field with null. Reflection JSON Schema therefore omits optional fields from required. In the canonical JSON input of a reflected tool command, an omitted scalar option, positional with a declared default, or flag takes its declared default (a count flag takes 0); the command input JSON Schema omits these arguments from required and states their default. The tail and repeatable options are not defaulted this way. Tool defaults do not turn Present into a key-existence check; constraints evaluate the effective optional/default carrier, and nested ValueIs comparisons use the declared nested schema.

Canonical invocation JSON uses JSON numbers for integers through 32 bits. Signed and unsigned 64-bit integers are canonical base-10 strings, as are duration nanoseconds and quantity mantissas. A duration is { "nanoseconds": "..." }; a quantity is { "mantissa": "...", "scale": number, "unit": string }. Leading zeroes, +, and -0 are invalid. JSON Schema projections use the same string patterns and carry the exact range as metadata.

Streams, futures, and opaque capabilities have no canonical JSON representation. Their reflection JSON Schema projection is unsatisfiable. Use the schema-native *Value APIs, transfer each owned handle once, consume returned streams, and cancel or close started operations according to the language-specific API.

Mixing client approaches

The approaches are surfaces that compose around schema snapshots and durable agent IDs:

shared source definition ──Normal RPC──────────────┐
full caller-defined client ──factory───────────────┼─> AgentId
environment discovery ──snapshot─> Reflected* ─────┘       │
          │                                                 ├─> method-only get-by-id
          ├─> select schema → pack → Dynamic* → validate ───┼─> reflected get-by-id
          └─> rediscover later from invocation metadata ────└─> dynamic get-by-id

Moving values or schemas obtained from discovery into a fully dynamic client does not transfer the

reflected client's automatic validation policy. Method-only and fully dynamic agent clients expose

no lifecycle factories. The agent ID of an ephemeral one-shot instance cannot be used for another call. Packed streams and owned

handles still follow the SDK's transfer, consumption, cancellation, and cleanup rules.

Load the language-specific reflection skill for concrete SDK APIs and examples.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.