agent

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package agent is SSHYard's built-in assistant: one host, one tool loop, every call checked by a policy.Gate. A Session is not safe for concurrent Turn and Continue; cancel with the context instead.

Index

Constants

View Source
const DevicePrompt = "You are SSHYard's built-in assistant for exactly one network device or console, reached over Telnet or a serial port. " +
	"You help the user operate that device and no other. It has no shell and no file access for you: only its own command line." +
	terminalRules +
	"Find the vendor and mode from the prompt in pane_output, or with show version or display version, and use that vendor's syntax. " +
	"\"--More--\" pages are turned for you; for long output you may first turn paging off for this session only " +
	"(terminal length 0, screen-length 0 temporary, or set cli screen-length 0). " +
	"Do not save the configuration unless the user asked. " + rules

DevicePrompt is the instruction for a network device or console reached over Telnet or a serial port.

View Source
const MaxPartBytes = 30 << 20

MaxPartBytes is the most the files attached to a conversation weigh together in one request; older ones give way to newer ones.

View Source
const MaxToolCalls = 25

MaxToolCalls is how many tool calls one turn runs before it pauses, for a Config that names none.

View Source
const ShellPrompt = "You are SSHYard's built-in assistant for exactly one terminal: a shell on the user's own computer. " +
	"You help the user with that terminal and no other; commands run in the user's shell, with its environment and working directory." +
	terminalRules +
	"Prefer commands that finish by themselves and print plain text: avoid pagers and full-screen programs (use --no-pager or | cat). " + rules

ShellPrompt is the instruction for a terminal on the user's own computer.

View Source
const SystemPrompt = "You are SSHYard's built-in assistant for exactly one SSH host. " +
	"You help the user operate that host and no other. " + rules

SystemPrompt is the built-in assistant's instruction. It names one host and tells the model that marked data is not the user's intent.

Variables

View Source
var ErrPaused = errors.New("agent: paused at the tool call limit")

ErrPaused is returned when a turn stops after its tool-call limit. Continue resumes it.

Functions

func OnlyChanges

func OnlyChanges(diff string) string

OnlyChanges drops the unchanged context lines of a unified diff.

func ToolDefs

func ToolDefs() []llm.Tool

ToolDefs is the built-in assistant function set. Host metadata is already attached to the session; the remaining names match sshyard-remote MCP tools.

func ToolDefsFor added in v0.0.26

func ToolDefsFor(t Target) []llm.Tool

ToolDefsFor is the function set of target t. The terminal targets type into the linked terminal: they have no files and no command channel.

func Unified

func Unified(path, oldText, newText string) string

Unified is a unified diff of oldText and newText for path. A new file (oldText empty) is the full new text. Identical text is empty. Unchanged runs are collapsed to diffContext lines around each change.

func WrapUntrusted

func WrapUntrusted(source, body string) string

WrapUntrusted marks body as data from source. A closing marker inside the body is escaped so the boundary stays intact.

Types

type Config

type Config struct {
	Model    Streamer
	Gate     policy.Gate
	Tools    Tools
	Redact   bool
	MaxChars int
	// Target is what the tools reach; zero is an SSH host.
	Target Target
	// MaxToolCalls caps the tool calls one turn runs before it pauses.
	// Nil keeps MaxToolCalls; a pointer to 0 runs without a limit.
	MaxToolCalls *int
}

Config builds a Session. A nil Tools uses Unavailable.

type Event

type Event struct {
	Kind  Kind
	Text  string
	Tool  *ToolCard
	Calls int
}

Event is one thing the UI timeline shows. Tool is set for EventTool; Calls, for EventPause, is the tool calls the turn has run.

type HostMeta

type HostMeta struct {
	Name    string
	Address string
	User    string
	Uname   string
	Distro  string
	Cwd     string
	// Protocol says how a terminal target is reached, as "Telnet", "serial
	// port COM3" or "local shell zsh"; unused for SSH.
	Protocol string
	// Provider, Renewal and Note are what the user keeps of the host:
	// who rents it out, its subscription as a line ("renews every 1
	// months since 2026-10-01; next renewal 2026-11-01, in 3 days") and
	// their note, which is sent as untrusted data.
	Provider string
	Renewal  string
	Note     string
}

HostMeta is the host context attached once per session.

type Kind

type Kind string

Kind is one timeline event.

const (
	EventText     Kind = "text"
	EventThinking Kind = "thinking"
	EventTool     Kind = "tool"
	EventPause    Kind = "pause"
	EventDone     Kind = "done"
	// EventNotice is a failure the user must see while the turn goes on.
	// Text is a code, such as policy.AuditNotice's.
	EventNotice Kind = "notice"
)

type Session

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

Session is one built-in agent conversation. History lives in memory.

func New

func New(cfg Config) *Session

New starts a session with the system prompt. The host context is added on the first Turn.

func Restore

func Restore(cfg Config, msgs []llm.Message) *Session

Restore is a session that carries on msgs, as History gave them. A tool call left without its result, as at a pause, is answered "cancelled"; a result without its call is dropped. The host context is sent again with the next Turn.

func (*Session) Configure

func (s *Session) Configure(gate policy.Gate, redact bool, maxToolCalls *int)

Configure updates an idle session after its previous turn has stopped: the gate it asks, whether it redacts, and the tool calls its next turn runs before pausing. A nil maxToolCalls keeps MaxToolCalls.

func (*Session) Continue

func (s *Session) Continue(ctx context.Context, emit func(Event)) error

Continue runs the tool calls that were held at the pause, then keeps going. It grants another stretch of tool calls. It does nothing when the session is not paused.

func (*Session) History

func (s *Session) History() []llm.Message

History is the conversation so far without its system messages, to be kept and given back to Restore. Attached files keep only their names.

func (*Session) Paused

func (s *Session) Paused() bool

Paused reports whether the session is waiting for Continue.

func (*Session) Turn

func (s *Session) Turn(ctx context.Context, user string, meta HostMeta, terminal string, emit func(Event)) error

Turn sends one user message. terminal, when set, is attached as untrusted data. A paused session refuses until Continue.

func (*Session) TurnWith

func (s *Session) TurnWith(ctx context.Context, user string, parts []llm.Part, meta HostMeta, terminal string, emit func(Event)) error

TurnWith is Turn with files attached to the message: images and documents the model reads.

type Streamer

type Streamer interface {
	Stream(ctx context.Context, req llm.Request, emit func(llm.Event)) (llm.Message, error)
}

Streamer is the model client: one streamed completion in any of its formats.

type Target added in v0.0.26

type Target int

Target is what a session's tools reach.

const (
	// TargetSSH is an SSH host: its files, and commands on their own
	// channels.
	TargetSSH Target = iota
	// TargetDevice is a Telnet or serial terminal: a device's command line.
	TargetDevice
	// TargetShell is a terminal on this computer: the user's shell.
	TargetShell
)

type ToolCard

type ToolCard struct {
	Phase    string // "open" while it runs, "done" when it has a result
	Status   string // "cancel" or "timeout" overrides execution status; Verdict retains the approval source
	ID       string
	Name     string
	Category string
	Risk     string
	Where    string
	Command  string
	Path     string
	Dir      string
	Verdict  string // full, auto, reviewer, user, reject, timeout, cancel
	Review   string // the review model's note, when one was asked
	Refusal  string
	Output   string
	Diff     string
	Exit     int
	DurMS    int64
	Run      bool
}

ToolCard is one tool call on the timeline. Output is truncated to 1 MB. Exit is -1 when no exit code is available.

type Tools

type Tools interface {
	Call(ctx context.Context, name string, args json.RawMessage) (output string, exit int, err error)
	// ReadFile reads a remote file so write_file can build a diff.
	// ok is false when the file does not exist.
	ReadFile(ctx context.Context, path string) (text string, ok bool, err error)
}

Tools is the remote tool layer. Call's output is the tool result the model sees.

type Unavailable

type Unavailable struct{}

Unavailable is the tool layer before it is connected.

func (Unavailable) Call

Call reports that remote tools are not connected yet.

func (Unavailable) ReadFile

ReadFile reports no file.

Jump to

Keyboard shortcuts

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