agent

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package agent is the external control-plane layer that composes the gateway's LLM, MCP, ACP, and metrics surfaces around an operator-facing agent identity.

It depends on the lower-level protocol managers and query services; the protocol packages must not depend on pkg/agent. See docs/design/agents-control-plane.md for the full direction.

Index

Constants

View Source
const (
	// RuntimeTypeACP: the gateway owns the lifecycle (process pool, sessions,
	// permission flow, transcript) through an ACP service.
	RuntimeTypeACP = "acp"
	// RuntimeTypeHTTP: the agent service owns its own lifecycle; the gateway is
	// only a client. P0 defines the shape but does not dispatch to it yet.
	RuntimeTypeHTTP = "http"
)

Runtime backend types, split by who owns the agent's process lifecycle.

Variables

View Source
var ErrAgentNotConfigured = fmt.Errorf("agent is not configured")

Functions

func DecodeStoredAgentConfig

func DecodeStoredAgentConfig(data []byte) (any, error)

Types

type ACPRouteServiceLookup

type ACPRouteServiceLookup interface {
	ACPRouteServiceID(ctx context.Context, routeID string) (string, error)
}

ACPRouteServiceLookup resolves an ACP route id to its backing service id. The agent manager uses it to enforce that an agent's acp_route_ids all point at the agent's runtime service. It is optional; when nil the consistency check is skipped (the manager still enforces service_id uniqueness).

type ACPRuntime

type ACPRuntime struct {
	ServiceID string `json:"service_id"`
}

ACPRuntime holds only the binding to an ACP service. ACP operational config (permission_mode, allowed_roots, default_cwd) is owned by the ACP service under /admin/acp/services, not duplicated here.

type Agent

type Agent struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Description string    `json:"description,omitempty"`
	Runtime     Runtime   `json:"runtime"`
	Routes      Routes    `json:"routes"`
	Resources   Resources `json:"resources"`
	Policy      Policy    `json:"policy"`
	Disabled    bool      `json:"disabled"`
	// OwnsService records that this agent auto-created its backing ACP service
	// (provenance). It distinguishes "agent owns this service" from "agent
	// references a pre-existing shared service" for deletion/cascade decisions.
	OwnsService bool      `json:"owns_service,omitempty"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

Agent is a first-class management object representing an operator-facing agent identity, not a protocol-specific service.

func (Agent) ACPServiceID

func (a Agent) ACPServiceID() string

ACPServiceID returns the bound ACP service id, or "" when the agent is not ACP-backed.

func (*Agent) Normalize

func (a *Agent) Normalize()

func (*Agent) NormalizeTimestamps

func (a *Agent) NormalizeTimestamps(now time.Time)

func (Agent) Validate

func (a Agent) Validate() error

type Budget

type Budget struct {
	MaxTurnsPerDay  int `json:"max_turns_per_day,omitempty"`
	MaxTokensPerDay int `json:"max_tokens_per_day,omitempty"`
}

type HTTPRuntime

type HTTPRuntime struct {
	Endpoint string `json:"endpoint"`
	AuthRef  string `json:"auth_ref,omitempty"`
}

HTTPRuntime carries the agent-level endpoint and callback auth for an agent that owns its own lifecycle.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager owns agent CRUD plus the in-memory route/service -> agent index used for write-time attribution. The index is rebuilt on every mutation and never read from the config store on the hot path.

func NewManager

func NewManager(store configstore.ConfigStore) *Manager

func (*Manager) Create

func (m *Manager) Create(ctx context.Context, a Agent) error

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, id string) error

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, id string) (Agent, error)

func (*Manager) List

func (m *Manager) List(ctx context.Context) ([]Agent, error)

func (*Manager) Refresh

func (m *Manager) Refresh(ctx context.Context) error

Refresh rebuilds the in-memory route/service -> agent index from the store.

func (*Manager) ResolveAgentID

func (m *Manager) ResolveAgentID(routeID, serviceID, sessionID string) (string, bool)

ResolveAgentID maps an originating route/service back to a single agent for write-time usage attribution. It implements usage.AgentAttributor. It returns ok=false when the mapping is empty (the caller then leaves agent_id empty).

func (*Manager) SetRouteLookup

func (m *Manager) SetRouteLookup(lookup ACPRouteServiceLookup)

SetRouteLookup wires the optional ACP route -> service resolver used for the acp_route_ids consistency check.

func (*Manager) Update

func (m *Manager) Update(ctx context.Context, id string, a Agent) error

type Policy

type Policy struct {
	MaxAgentDepth int     `json:"max_agent_depth,omitempty"`
	Budget        *Budget `json:"budget,omitempty"`
}

Policy holds runtime-agnostic governance only. Runtime-specific config belongs under runtime.<type> or on the backing service.

type Resources

type Resources struct {
	ProviderIDs   []string `json:"provider_ids,omitempty"`
	MCPServiceIDs []string `json:"mcp_service_ids,omitempty"`
	VirtualKeyIDs []string `json:"virtual_key_ids,omitempty"`
}

Resources is a management view of what the agent is allowed to use. It is not enforced inline on the data-plane request path in P0/P1.

type Routes

type Routes struct {
	ACPRouteIDs []string `json:"acp_route_ids,omitempty"`
	LLMRouteIDs []string `json:"llm_route_ids,omitempty"`
	MCPRouteIDs []string `json:"mcp_route_ids,omitempty"`
}

Routes are management/display references used to surface matching ingress routes and to drive attribution; they do not select the execution backend.

type Runtime

type Runtime struct {
	Type string       `json:"type"`
	ACP  *ACPRuntime  `json:"acp,omitempty"`
	HTTP *HTTPRuntime `json:"http,omitempty"`
}

Runtime is authoritative for execution. It binds the agent to exactly one runtime backend instance, selected by Type.

Jump to

Keyboard shortcuts

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