Documentation
¶
Overview ¶
Package arcp implements the ARCP wire protocol: a transport-agnostic envelope for submitting, observing, and controlling long-running AI agent jobs.
The root package exposes the on-the-wire envelope, sentinel error values, identifier helpers, and protocol-version constants. Higher level code lives in the sibling packages:
- github.com/agentruntimecontrolprotocol/go-sdk/transport — pluggable bidirectional envelope channels (memory, WebSocket, stdio).
- github.com/agentruntimecontrolprotocol/go-sdk/messages — typed payload structs registered against the envelope.
- github.com/agentruntimecontrolprotocol/go-sdk/client — a client that talks to a runtime.
- github.com/agentruntimecontrolprotocol/go-sdk/server — a runtime that hosts agents.
- github.com/agentruntimecontrolprotocol/go-sdk/auth — bearer verifier interface.
- github.com/agentruntimecontrolprotocol/go-sdk/middleware — host-adapter sub-packages for net/http, chi, and OTel.
The wire format is JSON; envelopes carry an [Envelope.Payload] as raw bytes so the read loop can hand off without parsing twice.
Index ¶
- Constants
- Variables
- func HasFeature(features []string, name string) bool
- func IntersectFeatures(a, b []string) []string
- func IsRetryable(err error) bool
- func MarshalPayload(payload any) (json.RawMessage, error)
- func NewCallID() string
- func NewEnvelopeID() string
- func NewJobID() string
- func NewPayloadForType(typ string) any
- func NewPingNonce() string
- func NewResultID() string
- func NewSessionID() string
- func NewTraceID() string
- func NewULID() string
- func RegisterMessageType(m MessageType)
- func RegisteredTypes() []string
- type BudgetAmount
- type Capability
- type Currency
- type Envelope
- type Error
- type ErrorCode
- type Lease
- type MessageType
Constants ¶
const ProtocolVersion = "1.1"
ProtocolVersion is the literal value carried in every envelope's "arcp" field.
const SDKVersion = "1.1.0"
SDKVersion is the version of this Go SDK.
Variables ¶
var ( ErrPermissionDenied = &Error{Code: CodePermissionDenied, Message: "permission denied", Retryable: false} ErrLeaseSubsetViolation = &Error{Code: CodeLeaseSubsetViolation, Message: "lease subset violation", Retryable: false} ErrJobNotFound = &Error{Code: CodeJobNotFound, Message: "job not found", Retryable: false} ErrDuplicateKey = &Error{Code: CodeDuplicateKey, Message: "duplicate idempotency key", Retryable: false} ErrAgentNotAvailable = &Error{Code: CodeAgentNotAvailable, Message: "agent not available", Retryable: false} ErrAgentVersionNotAvailable = &Error{Code: CodeAgentVersionNotAvailable, Message: "agent version not available", Retryable: false} ErrCancelled = &Error{Code: CodeCancelled, Message: "cancelled", Retryable: false} ErrTimeout = &Error{Code: CodeTimeout, Message: "timeout", Retryable: false} ErrResumeWindowExpired = &Error{Code: CodeResumeWindowExpired, Message: "resume window expired", Retryable: false} ErrHeartbeatLost = &Error{Code: CodeHeartbeatLost, Message: "heartbeat lost", Retryable: true} ErrLeaseExpired = &Error{Code: CodeLeaseExpired, Message: "lease expired", Retryable: false} ErrBudgetExhausted = &Error{Code: CodeBudgetExhausted, Message: "budget exhausted", Retryable: false} ErrInvalidRequest = &Error{Code: CodeInvalidRequest, Message: "invalid request", Retryable: false} ErrUnauthenticated = &Error{Code: CodeUnauthenticated, Message: "unauthenticated", Retryable: false} ErrInternalError = &Error{Code: CodeInternalError, Message: "internal error", Retryable: true} )
Sentinel error values. Each maps to one ErrorCode. Use errors.Is against these to test for a particular code.
var Features = []string{
"heartbeat",
"ack",
"list_jobs",
"subscribe",
"agent_versions",
"lease_expires_at",
"cost.budget",
"model.use",
"provisioned_credentials",
"progress",
"result_chunk",
}
Features is the canonical list of negotiable feature flags advertised in session.hello and session.welcome capabilities.
Functions ¶
func HasFeature ¶
HasFeature reports whether name appears in features.
func IntersectFeatures ¶
IntersectFeatures returns the set of feature flags present in both a and b, in the order they appear in a. Used at handshake to compute the effective negotiated feature set.
func IsRetryable ¶
IsRetryable reports whether err is structurally marked retryable. Non-arcp errors are conservatively reported as retryable so generic transport-level failures do not become fatal.
func MarshalPayload ¶
func MarshalPayload(payload any) (json.RawMessage, error)
MarshalPayload encodes any value to json.RawMessage. nil and already-raw values pass through.
func NewCallID ¶
func NewCallID() string
NewCallID returns a ULID prefixed with "c_" for tool_call.call_id.
func NewEnvelopeID ¶
func NewEnvelopeID() string
NewEnvelopeID returns a UUIDv7. UUIDv7 carries a millisecond timestamp prefix and is suitable for the envelope id field.
func NewPayloadForType ¶
NewPayloadForType returns a zero value of the registered type for typ suitable for json.Unmarshal. It returns nil if typ is not registered.
func NewPingNonce ¶
func NewPingNonce() string
NewPingNonce returns a ULID prefixed with "p_". The nonce is matched on session.pong; ULIDs are short and time-ordered.
func NewTraceID ¶
func NewTraceID() string
NewTraceID returns a 32-character lowercase hex string suitable for the envelope trace_id field (matches W3C trace-context).
func NewULID ¶
func NewULID() string
NewULID returns a Crockford-base32 ULID with the current wall-clock timestamp. ULIDs sort lexicographically; we use them for session/job/result/nonce identifiers so log scans stay ordered.
func RegisterMessageType ¶
func RegisterMessageType(m MessageType)
RegisterMessageType associates the concrete struct behind m with its wire-type string. Each wire-type string may only be registered once; duplicate registration panics. Call from init() in messages/*.go.
func RegisteredTypes ¶
func RegisteredTypes() []string
RegisteredTypes returns the names of every registered MessageType, useful for diagnostics.
Types ¶
type BudgetAmount ¶
BudgetAmount is one entry in a cost.budget pattern list, of the form "USD:5.00".
func ParseBudgetAmount ¶
func ParseBudgetAmount(s string) (BudgetAmount, error)
ParseBudgetAmount parses a cost.budget pattern entry per the spec grammar: amount ::= currency ":" decimal. Negative values are rejected.
func (BudgetAmount) String ¶
func (b BudgetAmount) String() string
String returns the canonical "CUR:value" representation.
type Capability ¶
type Capability string
Capability is the lease namespace identifier. The constants below enumerate spec-reserved namespaces; vendors may add their own string-valued capabilities.
const ( CapFSRead Capability = "fs.read" CapFSWrite Capability = "fs.write" CapNetFetch Capability = "net.fetch" CapToolCall Capability = "tool.call" CapAgentDelegate Capability = "agent.delegate" CapModelUse Capability = "model.use" CapCostBudget Capability = "cost.budget" )
Reserved capability namespaces.
type Currency ¶
type Currency string
Currency is an ISO 4217 currency code, or the protocol-reserved "credits" string, or a runtime-defined identifier.
type Envelope ¶
type Envelope struct {
// ARCP is the protocol version literal. Always "1.1" on the wire.
ARCP string `json:"arcp"`
// ID is a unique message identifier (UUIDv7 recommended).
ID string `json:"id"`
// Type is the wire-type token, for example "job.submit".
Type string `json:"type"`
// SessionID identifies the owning session; empty on session.hello.
SessionID string `json:"session_id,omitempty"`
// JobID is set on job-scoped envelopes (job.*).
JobID string `json:"job_id,omitempty"`
// TraceID is a 32-hex-char W3C trace identifier when present.
TraceID string `json:"trace_id,omitempty"`
// EventSeq is the session-scoped monotonic sequence for
// job.event / job.result / job.error. Zero on every other type.
EventSeq uint64 `json:"event_seq,omitempty"`
// Payload is the typed payload, kept raw so the dispatch loop can
// hand it off to a registered MessageType without parsing twice.
Payload json.RawMessage `json:"payload,omitempty"`
// Extensions carries x-vendor.* namespaced opaque fields per the
// spec extensions namespace.
Extensions map[string]json.RawMessage `json:"extensions,omitempty"`
}
Envelope is the wire-level frame for every ARCP message. Field names map exactly onto the JSON object documented in the spec.
func NewEnvelope ¶
NewEnvelope returns an Envelope with arcp/id pre-populated.
func (*Envelope) DecodePayload ¶
DecodePayload unmarshals e.Payload into v.
type Error ¶
type Error struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
Retryable bool `json:"retryable"`
Details map[string]any `json:"details,omitempty"`
// contains filtered or unexported fields
}
Error is the structured ARCP error. It carries a code, a human message, a retry hint, optional structured details, and an optional wrapped cause.
func (*Error) WithDetails ¶
WithDetails returns a copy of e with details merged into Details.
func (*Error) WithMessage ¶
WithMessage returns a copy of e with msg as the human message.
type ErrorCode ¶
type ErrorCode string
ErrorCode is the canonical string code for the protocol's error taxonomy. The fifteen codes below cover every spec-mandated rejection point.
const ( CodePermissionDenied ErrorCode = "PERMISSION_DENIED" CodeLeaseSubsetViolation ErrorCode = "LEASE_SUBSET_VIOLATION" CodeJobNotFound ErrorCode = "JOB_NOT_FOUND" CodeDuplicateKey ErrorCode = "DUPLICATE_KEY" CodeAgentNotAvailable ErrorCode = "AGENT_NOT_AVAILABLE" CodeAgentVersionNotAvailable ErrorCode = "AGENT_VERSION_NOT_AVAILABLE" CodeCancelled ErrorCode = "CANCELLED" CodeTimeout ErrorCode = "TIMEOUT" CodeResumeWindowExpired ErrorCode = "RESUME_WINDOW_EXPIRED" CodeHeartbeatLost ErrorCode = "HEARTBEAT_LOST" CodeLeaseExpired ErrorCode = "LEASE_EXPIRED" CodeBudgetExhausted ErrorCode = "BUDGET_EXHAUSTED" CodeInvalidRequest ErrorCode = "INVALID_REQUEST" CodeUnauthenticated ErrorCode = "UNAUTHENTICATED" CodeInternalError ErrorCode = "INTERNAL_ERROR" )
The full set of canonical error codes.
type Lease ¶
type Lease map[Capability][]string
Lease maps capability namespaces to pattern lists. The lease is immutable for a job's lifetime; budget counters are runtime state derived from the lease, not part of it.
func (Lease) MarshalJSON ¶
MarshalJSON encodes l as a JSON object with string-typed keys.
func (*Lease) UnmarshalJSON ¶
UnmarshalJSON decodes a JSON object into l.
type MessageType ¶
type MessageType interface {
ARCPType() string
}
MessageType is implemented by every typed payload struct registered against the envelope dispatch table.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package auth defines the Verifier interface used by the server to validate bearer tokens at the session.hello handshake.
|
Package auth defines the Verifier interface used by the server to validate bearer tokens at the session.hello handshake. |
|
Package client implements the ARCP client surface: dial, submit, observe, cancel, subscribe.
|
Package client implements the ARCP client surface: dial, submit, observe, cancel, subscribe. |
|
Package credentials defines the provisioner surface used by runtimes to mint lease-bound credentials for accepted jobs.
|
Package credentials defines the provisioner surface used by runtimes to mint lease-bound credentials for accepted jobs. |
|
examples
|
|
|
ack-backpressure/client
command
|
|
|
ack-backpressure/server
command
|
|
|
agent-versions/client
command
|
|
|
agent-versions/server
command
|
|
|
cancel/client
command
|
|
|
cancel/server
command
|
|
|
chi-routes/client
command
|
|
|
chi-routes/server
command
|
|
|
cost-budget/client
command
|
|
|
cost-budget/server
command
|
|
|
custom-auth/client
command
|
|
|
custom-auth/server
command
|
|
|
heartbeat/client
command
|
|
|
heartbeat/server
command
|
|
|
idempotent-retry/client
command
|
|
|
idempotent-retry/server
command
|
|
|
internal/demo
Package demo provides shared helpers for the examples — addr resolution and a tiny "log fatal on error" idiom.
|
Package demo provides shared helpers for the examples — addr resolution and a tiny "log fatal on error" idiom. |
|
lease-expires-at/client
command
|
|
|
lease-expires-at/server
command
|
|
|
lease-violation/client
command
|
|
|
lease-violation/server
command
|
|
|
list-jobs/client
command
|
|
|
list-jobs/server
command
|
|
|
nethttp-routes/client
command
|
|
|
nethttp-routes/server
command
|
|
|
progress/client
command
|
|
|
progress/server
command
|
|
|
provisioned-credentials/client
command
|
|
|
provisioned-credentials/server
command
|
|
|
result-chunk/client
command
|
|
|
result-chunk/server
command
|
|
|
stdio/agent
command
|
|
|
stdio/client
command
|
|
|
submit-and-stream/client
command
|
|
|
submit-and-stream/server
command
|
|
|
subscribe/client
command
|
|
|
subscribe/server
command
|
|
|
tracing/client
command
|
|
|
tracing/server
command
|
|
|
vendor-extensions/client
command
|
|
|
vendor-extensions/server
command
|
|
|
internal
|
|
|
clock
Package clock defines the small Clock interface used by the runtime for testable time.
|
Package clock defines the small Clock interface used by the runtime for testable time. |
|
eventlog
Package eventlog persists session-scoped envelopes for resume and subscription replay.
|
Package eventlog persists session-scoped envelopes for resume and subscription replay. |
|
glob
Package glob implements the lease pattern matcher.
|
Package glob implements the lease pattern matcher. |
|
idstore
Package idstore implements the (principal, idempotency_key) → job_id dedupe map.
|
Package idstore implements the (principal, idempotency_key) → job_id dedupe map. |
|
lease
Package lease implements the lease enforcement primitives: glob match, target canonicalization, expires_at and budget checks.
|
Package lease implements the lease enforcement primitives: glob match, target canonicalization, expires_at and budget checks. |
|
Package messages defines the typed payload structs for every ARCP wire type.
|
Package messages defines the typed payload structs for every ARCP wire type. |
|
middleware
|
|
|
chi
Package chi mounts an ARCP server on a chi.Router.
|
Package chi mounts an ARCP server on a chi.Router. |
|
nethttp
Package nethttp exposes a net/http handler that upgrades incoming requests to WebSocket and hands the resulting connection to a server.Server.
|
Package nethttp exposes a net/http handler that upgrades incoming requests to WebSocket and hands the resulting connection to a server.Server. |
|
otel
Package otel wires ARCP transports to OpenTelemetry trace context.
|
Package otel wires ARCP transports to OpenTelemetry trace context. |
|
recipes
|
|
|
email-vendor-leases/client
command
|
|
|
email-vendor-leases/server
command
|
|
|
mcp-skill/server
command
|
|
|
multi-agent-budget/client
command
|
|
|
multi-agent-budget/server
command
|
|
|
stream-resume/client
command
|
|
|
stream-resume/server
command
|
|
|
Package server hosts ARCP agents.
|
Package server hosts ARCP agents. |
|
Package transport defines the Transport interface and ships three concrete implementations: an in-memory pair (for tests and same- process embedders), a WebSocket transport, and an NDJSON-over-stdio transport.
|
Package transport defines the Transport interface and ships three concrete implementations: an in-memory pair (for tests and same- process embedders), a WebSocket transport, and an NDJSON-over-stdio transport. |