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),
)

Required options

OptionTypeIf missing
WithGatewayURLstringInit returns ErrInvalidGateway
WithAPIKeystringInit returns ErrInvalidAPIKey

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