agenthost

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package agenthost is the runtime's client/host-role primitive for driving another ACP agent over stdio. The harness is always supplied by the caller.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func McpServerForACP

func McpServerForACP(row *runtimetypes.MCPServer) (libacp.McpServer, error)

McpServerForACP maps a registered MCP server row to its ACP session/new wire shape. Only reachability data is forwarded; credentials reach the agent only via explicit headers.

func ResolveForwardedMcpServers

func ResolveForwardedMcpServers(ctx context.Context, resolver McpServerResolver, names []string) ([]libacp.McpServer, error)

ResolveForwardedMcpServers turns an agent's mcp_servers allowlist into the libacp.McpServer entries to pass in ACP session/new. A name that resolves to nothing is a loud error, not a silent skip.

Types

type Agent

type Agent interface {
	// Connect spawns or attaches to the agent and returns a Handle wired to
	// harness. harness is always supplied by the caller; Connect never
	// builds one itself.
	Connect(ctx context.Context, harness libacp.Client) (*Handle, error)
}

Agent drives another ACP agent: Connect establishes a live connection using the supplied harness and returns a Handle wired to it.

type DenyingHarness

type DenyingHarness struct {
	RecordingHarness
	// contains filtered or unexported fields
}

DenyingHarness is RecordingHarness plus one scripted answer: every permission ask is denied, preferring reject_once, then reject_always, then outcome "cancelled" if neither was offered.

func (*DenyingHarness) Denied

func (h *DenyingHarness) Denied() []string

Denied returns the permission asks denied so far, named by tool-call title (id when untitled).

func (*DenyingHarness) RequestPermission

RequestPermission denies the ask (see the type doc) and records its title.

type ExternalACPAgent

type ExternalACPAgent struct {
	Config runtimetypes.ExternalACPConfig

	// Stderr, if set, receives the spawned subprocess's stderr. Defaults to io.Discard.
	Stderr io.Writer

	// KillGrace, if positive, overrides how long teardown waits after
	// stdin closes before killing the agent (default 5s).
	KillGrace time.Duration

	// Tracker observes the sandbox confining the spawned agent. Optional;
	// nil is treated as libtracker.NoopTracker.
	Tracker libtracker.ActivityTracker

	// SelfSpawn marks this as the runtime re-invoking its own binary: it runs
	// unsandboxed under the runtime's own grants and HITL gate. Never set by
	// config or env.
	SelfSpawn bool
}

ExternalACPAgent is the Agent implementation for runtimetypes.AgentKindExternalACP; endpoint transport is not implemented yet.

func NewExternalACPAgent

func NewExternalACPAgent(cfg runtimetypes.ExternalACPConfig) *ExternalACPAgent

NewExternalACPAgent returns an ExternalACPAgent for cfg.

func (*ExternalACPAgent) Connect

func (a *ExternalACPAgent) Connect(ctx context.Context, harness libacp.Client) (*Handle, error)

Connect validates a.Config and dispatches to the transport-specific path.

type Handle

type Handle struct {
	// Conn is the live ACP client-side connection; callers issue calls
	// (Initialize, NewSession, Prompt) directly against it.
	Conn *libacp.ClientSideConnection
	// contains filtered or unexported fields
}

Handle is a live connection to an agent, returned by Agent.Connect. Close tears down the transport and waits for the read loop to exit, so a caller that has called Close knows the agent is fully torn down.

func (*Handle) Close

func (h *Handle) Close() error

Close tears down the transport and waits for Conn's read loop to return. Idempotent: repeated calls return the same result.

type McpServerResolver

type McpServerResolver interface {
	GetByName(ctx context.Context, name string) (*runtimetypes.MCPServer, error)
}

McpServerResolver is the narrow lookup surface ResolveForwardedMcpServers needs; mcpserverservice.Service satisfies it.

type RecordingHarness

type RecordingHarness struct {
	libacp.UnimplementedClient
	// contains filtered or unexported fields
}

RecordingHarness is the minimal libacp.Client harness for observing a turn: it records every session/update and rejects request-shaped callbacks. Use DenyingHarness when a permission ask must be answered. Safe for concurrent use.

func (*RecordingHarness) AvailableCommands

func (h *RecordingHarness) AvailableCommands() []libacp.AvailableCommand

AvailableCommands returns the most recent available_commands_update recorded; nil means the agent never advertised any.

func (*RecordingHarness) MessageText

func (h *RecordingHarness) MessageText() string

MessageText concatenates every agent_message_chunk's text recorded so far.

func (*RecordingHarness) SessionUpdate

SessionUpdate records n. It never returns an error — observing a turn must not be able to disturb it.

func (*RecordingHarness) Updates

Updates returns a snapshot of every recorded session/update, in arrival order.

type TurnRequest

type TurnRequest struct {
	// Cwd is the session working directory. Required, and expected absolute.
	Cwd string

	// Prompt is the user prompt for the driven turn. Required.
	Prompt []libacp.ContentBlock

	// ClientInfo identifies this host to the agent. Defaults to
	// "contenox-agenthost"; an empty Version is filled with the runtime's own.
	ClientInfo *libacp.Implementation

	// ClientCapabilities advertises what harness can serve; the zero value
	// is the honest match for RecordingHarness.
	ClientCapabilities libacp.ClientCapabilities

	// McpServers are MCP servers passed to the agent in session/new.
	// DriveTurn filters them against the agent's mcpCapabilities;
	// kept/dropped are reported on TurnResult.
	McpServers []libacp.McpServer

	// Stderr, if set, receives the spawned agent's stderr as it is written.
	Stderr io.Writer

	// KillGrace, if positive, bounds teardown's wait after stdin-close
	// before killing the agent (see ExternalACPAgent.KillGrace).
	KillGrace time.Duration
}

TurnRequest describes the one prompt turn DriveTurn drives.

type TurnResult

type TurnResult struct {
	Initialize libacp.InitializeResponse
	SessionID  libacp.SessionID
	StopReason libacp.StopReason

	// ForwardedMcpServers and DroppedMcpServers name which McpServers
	// reached the agent and which were withheld for unsupported capabilities.
	ForwardedMcpServers []string
	DroppedMcpServers   []string
}

TurnResult is what one driven turn produced on the request/response plane; the notification plane (streamed chunks) lives on the harness.

func DriveTurn

func DriveTurn(ctx context.Context, agent *runtimetypes.Agent, harness libacp.Client, req TurnRequest) (*TurnResult, error)

DriveTurn connects to the external ACP agent and drives one initialize, session/new, session/prompt turn with harness, tearing the connection down before returning.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL