{"modulePath":"github.com/MiniMax-AI/OpenAgentCore","version":"v0.0.14","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package agent\n\nPackage agent defines the Runtime's native Harness adapter contract. Start with this file when adding a Harness; the onboarding guide is at contracts/agents-api/harness-onboarding.md.\n\nRequired lifecycle: ExecutorFactory prepares a fixed Session-owned Executor; each StartTurn returns a fresh Turn with its own output and settlement. Turn includes the public text DurableSteerer requirement. Keep extension interfaces separate, but implement each explicitly: unsupported operations return ErrUnsupportedOperation before any native effects. Interface presence does not advertise support; the capability declaration controls admission. MCP, images, structured output and Subagent observations use protocol messages rather than additional Go interfaces; declare and advertise them separately.\n\nRegistration: each adapter exports one Declaration, which binds its shared declaration (internal/harnessconfig/\\\u003cpackage\u003e/declaration.go) to Discover. The Runtime discovers the generated declaration list and installs each resulting Runtime through Register. Availability and factory selection belong to the adapter. RegisterKind resets the factories, so Register installs it first. RegisterExecutor derives the Preparation capability.\n\nThe shared declaration is the only authored statement of what a Harness supports; Core admission reads the same value. Discovery may only narrow its capabilities for the installed host, with Narrow. Requests, events and capability descriptors use the existing internal/agentdaemon/proto types. An Environment execution request carries the Runtime's bound workspace directory in LocalEnvironment.WorkspaceRoot; the native Harness runs there.\n\n## Variables\n\n```go\nvar ErrSteeringInactive = errors.New(\"agent: run is no longer active\")\n```\nErrSteeringInactive means no input was sent because the run ended or was cancelled.\n\n```go\nvar ErrSteeringNotReady = errors.New(\"agent: turn is not ready for input\")\n```\nErrSteeringNotReady means no input was sent because the turn is starting.\n\n```go\nvar ErrSteeringRejected = errors.New(\"agent: input rejected\")\n```\nErrSteeringRejected means the engine explicitly rejected the input.\n\n```go\nvar ErrUnknownFunctionCall = errors.New(\"agent: function call is no longer pending\")\n```\nErrUnknownFunctionCall means the function call is no longer pending.\n\n```go\nvar ErrUnsupportedOperation = errors.New(\"agent: unsupported operation\")\n```\nErrUnsupportedOperation marks an intentional absence of optional behavior. Implementations wrap it with a static reason and perform no native effects. It is distinct from unavailable resources, failures and uncertain outcomes.\n\n## Functions\n\n```go\nfunc Narrow(capability *proto.CapabilitySupport, provided bool)\n```\nNarrow withdraws a declared capability the host cannot provide. It never grants one.\n\n```go\nfunc RemoveSessionState(stateRoot, runtimeRoot, keepKey string) error\n```\nRemoveSessionState deletes the state directory of every key but keepKey under both roots, for every agent kind. It lists directories instead of tracking Sessions, so it also covers state left by earlier processes and checkpoints.\n\n```go\nfunc StateDir(root, agentKind, agentStateKey string) (string, error)\n```\nStateDir returns an adapter-owned state directory scoped to one agent state. It never derives runtime state from the subprocess cwd.\n\n```go\nfunc ValidMCPHTTPBearerToken(token string) bool\n```\nValidMCPHTTPBearerToken accepts RFC 6750 b64token bytes without normalization. Credential resource storage has a separate, opaque-string contract.\n\n```go\nfunc Widened(declared, discovered proto.AgentKindCapabilities) []string\n```\nWidened names the capabilities discovery reports supported although the declaration does not.\n\n## Types\n\n```go\ntype Declaration struct {\n\tharnessconfig.Declaration\n\tDiscover func(context.Context, DiscoveryOptions, proto.SupportedAgentKind) *Runtime\n}\n```\nDeclaration binds a Harness's shared declaration to its native discovery. Discover returns nil when the adapter is not configured. An unavailable configured adapter returns a Runtime with Available=false and no factories. Discovery owns runtime-specific configuration and readiness, and narrows the declared capabilities to what the host provides; it never widens them.\n\n```go\ntype DiscoveryOptions struct {\n\t// StateRoot holds private history retained with the Environment filesystem.\n\tStateRoot string\n\t// RuntimeRoot holds instance-private configuration and process files.\n\tRuntimeRoot    string\n\tStdout, Stderr io.Writer\n}\n```\nDiscoveryOptions provides process context without naming an implementation.\n\n```go\ntype DurableSteerer interface {\n\tSteerWithReceipt(context.Context, proto.PromptSteerPayload, func()) error\n}\n```\nDurableSteerer reports one complete write synchronously, then waits for the native receipt. It is mandatory on every public Turn. Required input receipts cannot be implemented by returning Unsupported.\n\n```go\ntype Executor interface {\n\t// A nil Turn guarantees no input was submitted or output retained and leaves\n\t// out with the caller. A non-nil Turn owns out, including on error; input\n\t// may have been submitted and must never be replayed automatically.\n\tStartTurn(ctx context.Context, runID string, turn proto.TurnSettings, input proto.MessageInput, out chan\u003c- proto.Envelope) (Turn, error)\n\t// Success confirms all native work and owned output streams have stopped.\n\t// It does not establish an otherwise unknown Turn result. An error retains\n\t// resource ownership; another caller may await or retry Close.\n\tClose(context.Context) error\n}\n```\nExecutor retains a fixed native configuration across independently owned Turns.\n\n```go\ntype ExecutorFactory func(context.Context, proto.PromptRequestPayload) (Executor, error)\n```\nExecutorFactory prepares without model input. A failed factory retains any unconfirmed cleanup in its non-nil Executor.\n\n```go\ntype FunctionResultSubmitter interface {\n\tSubmitFunctionResult(context.Context, proto.FunctionResultPayload) error\n}\n```\nFunctionResultSubmitter is mandatory on every public Turn; support comes from the declaration. It delivers a result for an outstanding native call. A successful return requires its native application receipt.\n\n```go\ntype Installation struct {\n\tAgentKind   string\n\tVersion     string\n\tSupported   func() bool\n\tEnvironment func(directory, node string) map[string]string\n\tCheck       func(context.Context, string, string, []string) error\n}\n```\nInstallation is an optional adapter-owned native distribution contract. It supplies activation paths and readiness checks, never execution or model configuration. Runtime owns copying, checksums, publication and installation locks.\n\n```go\ntype MCPBinding struct {\n\tServerLabel  string\n\tTransport    string\n\tServerURL    string\n\tAllowedTools *[]string\n\tRequired     bool\n\tBearerToken  *string\n\tHTTPHeaders  map[string]string\n\t// Stdio retains the installed package identity for the fixed Runtime launcher.\n\tStdio *proto.EnvironmentMCP\n\t// Process is a public stdio declaration, started natively by the Harness.\n\tProcess *proto.MCPStdio\n}\n```\nMCPBinding is the Runtime's transient effective declaration. Adapters project it into their native configuration without resolving credentials or packages. Never serialize or log bindings: bearer values are confidential.\n\n```go\nfunc ResolveMCPBindings(req proto.PromptRequestPayload) ([]MCPBinding, error)\n```\nResolveMCPBindings combines public declarations with the frozen installation. Public declarations retain explicit origin and Vault authority; installed MCP retains Environment configuration authority. Neither may relocate implicitly.\n\n```go\ntype Registry struct {\n\t// contains filtered or unexported fields\n}\n```\nRegistry keeps the daemon-advertised capability descriptor and execution factories for each agent\\_kind. Safe for concurrent use.\n\n```go\nfunc NewRegistry() *Registry\n```\n\n```go\nfunc (r *Registry) Register(declaration Declaration, runtime Runtime)\n```\nRegister installs a discovered Runtime with its declaration's configuration.\n\n```go\nfunc (r *Registry) RegisterExecutor(kind string, factory ExecutorFactory)\n```\nRegisterExecutor installs the shared lifecycle after RegisterKind and derives the Preparation capability. It does not enable other public operations.\n\n```go\nfunc (r *Registry) RegisterKind(info proto.SupportedAgentKind, declaration harnessconfig.Declaration)\n```\nRegisterKind installs the heartbeat descriptor and model configuration for an agent\\_kind. Callers may set Available=false when an adapter exists but its underlying CLI is not usable.\n\n```go\nfunc (r *Registry) ResolveExecutor(kind string) (ExecutorFactory, harnessconfig.Declaration, error)\n```\nResolveExecutor returns the factory of a kind and the declaration it was registered with.\n\n```go\nfunc (r *Registry) SupportedAgentKinds() []proto.SupportedAgentKind\n```\nSupportedAgentKinds returns the daemon-advertised capability descriptors sorted by kind so heartbeat payloads are stable.\n\n```go\ntype Runtime struct {\n\tInfo     proto.SupportedAgentKind\n\tExecutor ExecutorFactory\n}\n```\nRuntime binds one discovered descriptor to its native factories.\n\n```go\nfunc Unavailable(info proto.SupportedAgentKind) *Runtime\n```\nUnavailable is the Runtime of a configured adapter the host cannot run. It declares nothing supported and has no factories.\n\n```go\ntype Session interface {\n\t// Cancel signals the session to abort. Idempotent. Actual teardown\n\t// happens asynchronously and is signalled via the out channel close.\n\tCancel(ctx context.Context) error\n\t// CancellationOutcome snapshots observed native identity, usage and output.\n\t// It remains readable after Cancel; missing evidence stays unset. An empty\n\t// result means no observed evidence, not unsupported cancellation or success.\n\t// Reading it does not wait for or establish native settlement.\n\tCancellationOutcome() proto.DonePayload\n}\n```\nSession is the cancellation and outcome surface of a Turn. Every owner exposes observed state. For Executor-owned Turns, AwaitSettlement and Executor.Close define settlement and resource retirement; Cancel alone does not transfer resource ownership.\n\n```go\ntype Turn interface {\n\tSession\n\tDurableSteerer\n\tFunctionResultSubmitter\n\t// Success confirms closed output and settled native input, function and\n\t// child-work obligations. Errors cannot prove cancellation.\n\tAwaitSettlement(context.Context) (TurnSettlement, error)\n}\n```\nTurn owns one output stream and never retargets cancellation to a successor.\n\n```go\ntype TurnSettlement struct {\n\tReusable bool\n\tReason   string\n}\n```\nTurnSettlement describes native readiness after this Turn has fully drained. A false result must carry a reason; it requires confirmed Executor.Close.\n\n","path":"github.com/MiniMax-AI/OpenAgentCore/apps/daemon/internal/agent","name":"agent","synopsis":"Package agent defines the Runtime's native Harness adapter contract.","isRedistributable":true}
