Skip to content

Configuration

Configuration

assembly.Init takes a context.Context and a variadic list of functional options. New configuration is always added as a WithXxx(value) option, so call sites never break when an option is introduced.

a, err := assembly.Init(ctx,
    assembly.WithGatewayURL("https://gateway.example.com"),
    assembly.WithAPIKey("..."),
    assembly.WithFailClosed(true),
    assembly.WithTimeout(750*time.Millisecond),
    assembly.WithEnforcementMode(assembly.EnforcementModeObserve),
)

Gateway and credential resolution

The gateway URL and API key are not ordinary options — Init resolves each one through a fixed precedence chain, so you can pass them explicitly in production and omit them entirely for local development.

The gateway URL is resolved from, highest priority first:

  1. WithGatewayURL("…") — the explicit option.
  2. The AAASM_GATEWAY_URL environment variable.
  3. The agent.gateway_url key in ~/.aasm/config.yaml.
  4. The local default http://localhost:7391Init probes it and, if no gateway answers, auto-starts a local one (aasm start --mode local --foreground).

The aasm CLI and the gateway it manages are documented in the core agent-assembly docs — see there for running a gateway, authoring policy, and the full aasm command set.

If every source yields an empty URL, Init returns ErrInvalidGateway.

The API key follows the same chain — WithAPIKeyAAASM_API_KEYagent.api_key in the config file — but an empty API key is allowed: local mode accepts unauthenticated calls, so no error is raised when the key is unset. WithAPIKey is therefore optional; supply it only when your gateway requires authentication.

# ~/.aasm/config.yaml
agent:
  gateway_url: https://gateway.example.com
  api_key: your-operator-issued-key

Optional options

OptionTypeDefaultPurpose
WithFailClosedboolfalseWhen true, a gateway failure blocks the action (fail-closed). When false, the action is allowed if the gateway is unreachable (fail-open).
WithTimeouttime.Duration500msGateway check timeout applied when the call ctx carries no deadline.
WithEnforcementModeEnforcementModeenforcePer-agent governance posture sent to the gateway at registration.
WithSelfAgentIDstring(unset)Records this agent’s own ID for lineage tracking.
WithParentAgentIDstring(unset)Parent agent ID for topology tracking.
WithTeamIDstring(unset)Team ID for budget and policy scoping.
WithDelegationReasonstring(unset)Human-readable reason this agent was delegated work.
WithSpawnedByToolstring(unset)Name of the tool that spawned this agent.
WithSidecarBinarystring(unset)Path to a sidecar binary for managed-lifecycle (sidecar) mode.

Enforcement modes

WithEnforcementMode accepts the values mirrored from aa_core::EnforcementMode on the wire:

ConstantTokenBehavior
EnforcementModeEnforceenforceDefault. A deny blocks the action; redact strips secrets.
EnforcementModeObserveobserveDry-run. The gateway records what would have happened but does not block.
EnforcementModeDisableddisabledPolicy evaluation is skipped entirely.

Per-call identity (context helpers)

Identity that varies per request is carried on context.Context, not on Init. The SDK forwards these to the gateway on every Check and RecordResult:

HelperReaderNotes
WithAgentIDAgentIDFromContextThe calling agent’s identity.
WithTraceIDTraceIDFromContextFalls back to the OpenTelemetry span-context trace ID when unset.
WithRunIDRunIDFromContextRun identity for a single agent run.
EnsureRunIDGuarantees a stable run ID within the same context tree.
ctx = assembly.WithAgentID(ctx, "my-agent")
ctx = assembly.EnsureRunID(ctx)

Where to next

Last updated on • Chisanan232