agentclient

package
v1.0.0-alpha.30 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package agentclient is the runtime-side client to the daemon's agent-to-agent linking RPCs. It exposes the four agent-facing calls the LLM tools (agent_list / agent_info / agent_chat / agent_exec) need; the daemon enforces "target ∈ JWT.Links" on every call.

Configuration parallels pkg/jobsclient — OTTERSD_URL + OTTERS_AGENT_TOKEN planted in the spawn env by the executor. Both clients share the underlying gRPC channel topology and auth shape; the package boundary just keeps each client focused on one daemon surface (jobs vs links) for readability.

Index

Constants

View Source
const (
	EnvDaemonURL = "OTTERSD_URL"
	// EnvAgentToken is the spawn-env var that carries the agent's
	// JWT. The string is an env-var NAME, not a credential — the
	// actual token value lives only in process memory.
	EnvAgentToken = "OTTERS_AGENT_TOKEN" //nolint:gosec // G101: env var name, not a literal credential.
)

Env names — same vars jobsclient reads. Re-exported so tests don't pull jobsclient in just for the constant.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentCreateFromSourceInput

type AgentCreateFromSourceInput struct {
	Agentfile   string            `json:"agentfile"`
	Name        string            `json:"name,omitempty"`
	Model       string            `json:"model,omitempty"`
	Envs        map[string]string `json:"envs,omitempty"`
	Links       []string          `json:"links,omitempty"`
	Description string            `json:"description,omitempty"`
}

AgentCreateFromSourceInput carries an inline Agentfile body (utf-8 text) in place of a ref. All other fields mirror AgentCreateInput.

type AgentCreateInput

type AgentCreateInput struct {
	Ref         string            `json:"ref"`
	Name        string            `json:"name,omitempty"`
	Model       string            `json:"model,omitempty"`
	Envs        map[string]string `json:"envs,omitempty"`
	Links       []string          `json:"links,omitempty"`
	Description string            `json:"description,omitempty"`
}

AgentCreateInput mirrors the proto AgentCreateRequest so the tool layer can pass typed values without re-importing daemonv1.

type AgentCreateResult

type AgentCreateResult struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Status string `json:"status"`
}

AgentCreateResult is the trimmed daemon response surfaced to the LLM — id, name, status. Enough for the tool result; the caller follows up with agent_info / agent_exec when it needs more.

type AgentInfoView

type AgentInfoView struct {
	AgentView
	Description  string   `json:"description,omitempty"`
	Capabilities []string `json:"capabilities,omitempty"`
}

AgentInfoView is the richer payload for agent_info. Adds description (the target's `description` label) + the list of capabilities the target exposes so the calling agent can decide whether it's the right delegate.

type AgentView

type AgentView struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Model  string `json:"model"`
	Status string `json:"status"`
}

AgentView is the agent-facing snapshot of one linked agent. Mirrors the proto LinkedAgent with JSON tags so the runtime can return it directly as the tool response payload.

type Client

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

Client wraps daemonv1.RuntimeClient with bearer-token injection and lazy dialing. Safe for concurrent use.

func New

func New(cfg Config) *Client

func (*Client) AgentCreate

func (c *Client) AgentCreate(ctx context.Context, in AgentCreateInput) (AgentCreateResult, error)

AgentCreate spawns a new agent from an existing image ref. Equivalent to the operator's `otters run <ref>` flow but mounts aren't supported — that surface stays operator-only.

func (*Client) AgentCreateFromSource

func (c *Client) AgentCreateFromSource(
	ctx context.Context, in AgentCreateFromSourceInput,
) (AgentCreateResult, error)

AgentCreateFromSource builds a fresh image from the inline Agentfile body and spawns an agent from it. The daemon tags the generated image with a recognizable `from-agent-<creator>:...` prefix so image_list can surface provenance.

func (*Client) AgentDelete

func (c *Client) AgentDelete(ctx context.Context, ref string) error

AgentDelete removes an agent by ref. No creator-scope filter — any authenticated agent caller can delete any target.

func (*Client) AgentExec

func (c *Client) AgentExec(
	ctx context.Context, ref, prompt, sessionID string,
) (string, string, error)

AgentExec sends a prompt to the target and blocks until the target's turn finishes. sessionID is optional; pass an empty string for a fresh session, or thread the returned id through subsequent calls to preserve history on the target. Returns (response, returnedSessionID, err).

(agent_chat existed as a separate threaded variant in alpha.82–.84; folded back into AgentExec in alpha.85 — one shape covers both use cases.)

func (*Client) AgentInfo

func (c *Client) AgentInfo(ctx context.Context, ref string) (AgentInfoView, error)

AgentInfo returns the target's metadata + capabilities. PermissionDenied if the target isn't in the caller's JWT.Links.

func (*Client) AgentList

func (c *Client) AgentList(ctx context.Context) ([]AgentView, error)

AgentList returns every agent the caller is linked to. The daemon resolves the caller from the JWT — the request body has no agent_id field, so this is unspoofable.

func (*Client) BinList

func (c *Client) BinList(ctx context.Context) ([]ImageRowView, error)

BinList returns the BIN-image catalogue.

func (*Client) Close

func (c *Client) Close() error

func (*Client) ImageList

func (c *Client) ImageList(ctx context.Context) ([]ImageRowView, error)

ImageList returns the agent-image catalogue.

func (*Client) SelfReload

func (c *Client) SelfReload(ctx context.Context) (bool, error)

SelfReload re-issues the caller's JWT against the current link table and bounces the runtime. Side effect: kills the current LLM turn — the runtime process restarts, the in-flight RPC connection closes mid-response. Use as the last tool of a turn after agent_create with self-linking.

type Config

type Config struct {
	URL   string
	Token string
}

Config holds the dial inputs.

func FromEnv

func FromEnv() (Config, bool)

FromEnv reads config from the runtime's process env. Returns (zero, false) when either var is missing — the tool builder treats this as "no daemon callback path" and registers no agent_* tools.

type ImageRowView

type ImageRowView struct {
	Ref         string `json:"ref"`
	Digest      string `json:"digest"`
	Description string `json:"description,omitempty"`
	Size        int64  `json:"size"`
}

ImageRowView mirrors the proto ImageRow for image_list / bin_list tool responses.

Jump to

Keyboard shortcuts

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