agent

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package agent implements the per-aspect runtime. Long-running process that connects to its upstream (Nexus directly OR a local Outpost) via a persistent WebSocket. Handles register/turn frames over that WS, writes session entries to a local tree, invokes the configured provider for each turn.

v1 scope: register + deregister + turn dispatch over WS. Hand dispatch, knowledge frames, session projection land in subsequent parts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

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

Agent is the running runtime instance.

func New

func New(cfg Config) (*Agent, error)

New constructs an Agent. Does no I/O — call Start() to dial and register.

func (*Agent) SessionID

func (a *Agent) SessionID() string

SessionID returns the unique id for this agent-process lifetime.

func (*Agent) Start

func (a *Agent) Start(ctx context.Context) error

Start brings the agent up: drives the wsclient Run loop (which dials upstream and reconnects on drop), registers on each new connection. Blocks until ctx is cancelled or FailFirstConnect trips. Deregisters on clean shutdown (while the connection is still live — we watch ctx separately so deregister lands before Run tears the socket down).

func (*Agent) Tree

func (a *Agent) Tree() *tree.Tree

Tree returns the session tree — useful for tests.

type Config

type Config struct {
	// Home is the absolute path to the aspect home folder.
	Home string

	// Aspect is the parsed aspect.json.
	Aspect schemas.AspectConfig

	// Provider is the chat provider adapter (e.g. claude-api).
	Provider providers.Provider

	// UpstreamURL is the WS URL to dial. For aspects running on a
	// direct-to-Nexus host this is the Nexus's /connect endpoint;
	// on hosts with a local Outpost, it's the Outpost's listener.
	// Resolution rule: NEXUS_OUTPOST overrides NEXUS_UPSTREAM per
	// transport spec §3.1. The caller (main.go) resolves it and
	// passes the resulting URL here.
	UpstreamURL string

	// UpstreamIsExplicitOutpost is true when the URL was resolved
	// from NEXUS_OUTPOST (not NEXUS_UPSTREAM). Triggers fail-loudly
	// on initial connect failure per transport spec §3.5.
	UpstreamIsExplicitOutpost bool

	// AuthToken is the bearer token sent on the WS upgrade.
	AuthToken string

	// Logger is optional; nil falls back to slog.Default().
	Logger *slog.Logger
}

Config bundles the runtime dependencies. All fields except Logger are required.

Jump to

Keyboard shortcuts

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