agent

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 14 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 the declaration layer for autonomous assistants: the Agent type, discovery of agent.md files into an immutable Set, and a cron Scheduler. It depends on nothing from the composition layer (no runtime, gate, or chat) — execution (FireAgent) lives in the workspace, which injects a fire callback into the Scheduler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NextRun added in v0.5.0

func NextRun(spec string, after time.Time) (time.Time, bool)

NextRun is when an agent scheduled by spec fires after t, in t's own location. ok is false for a spec that is empty (manual only), malformed, or never occurs within a few years.

func StartedBy added in v0.5.0

func StartedBy(trigger string) string

StartedBy is the line a run's first message stands as on a surface, its task being the model's context and not anyone's words: what set it going, "by you" or "schedule 07:00".

Types

type Agent

type Agent struct {
	Name         string
	Description  string          // one-line summary for listing/selection
	Instructions string          // the markdown body: the agent's system prompt / task framing
	Tools        []string        // the tools it asks for, as a name filter; empty = a pure reasoner
	When         string          // cron schedule; "" = manual only
	Model        string          // the model preset its runs ask for (internal/models); "" = the default
	Effort       agentkit.Effort // reasoning effort for the agent's runs; "" = the model's default
	Budget       time.Duration   // per-run wall-clock; 0 = the workspace default
	Park         Parking         // what its asks do: wait for the owner, or park as a draft
}

Agent is a declared assistant: a scoped persona that runs on a schedule or on demand. Its Tools are a request: what it may do is its column of the workspace's permission tree, which holds nothing until the owner accepts the request.

func (Agent) Matches

func (a Agent) Matches(toolName string) bool

Matches reports whether the agent's tools: asks for toolName. A bare group name ("http") also matches its members under any of the separators tool names use: "http_read" (underscore, the agentkit convention), "http.read", or "http/get".

func (Agent) Parks added in v0.5.0

func (a Agent) Parks() bool

Parks reports whether the agent's asks are parked.

type Parking added in v0.5.0

type Parking int

Parking is whether an agent's ask waits for an answer in memory, as a chat's does, or is parked: the call is kept as a draft work item, the run goes on, and the owner's answer comes as a message later.

const (
	// ParkScheduled parks the asks of an agent that runs on a schedule (nobody watches it) and lets a
	// manual one wait: the default.
	ParkScheduled Parking = iota
	// ParkAlways parks every ask.
	ParkAlways
	// ParkNever lets every ask wait.
	ParkNever
)

type Scheduler

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

Scheduler fires agents on their cron schedule. It holds each agent's next due time, computed from the WALL clock, and sleeps until the earliest — it does not poll. agentkit has no notion of time, so scheduling lives here; execution is the caller's, injected as fire.

func NewScheduler

func NewScheduler(agents Set, log *slog.Logger, fire func(ctx context.Context, a Agent)) *Scheduler

NewScheduler builds a Scheduler over a Set, calling fire for each agent whose schedule matches.

func (*Scheduler) Start

func (s *Scheduler) Start(ctx context.Context)

Start schedules until ctx is cancelled. It computes each agent's next due time and sleeps until the earliest one, rather than waking every minute to test every schedule: a sampling loop misses everything between samples, and the samples stop entirely while the machine sleeps.

Every due time is derived from the wall clock, so a sleep or clock jump is absorbed — on wake the overdue agents are simply due, and catchUpGrace decides whether each still runs. An agent that missed several firings in one gap fires once, not once per missed slot.

Startup does not catch up: due times are computed forward from now, so a schedule missed while the daemon was down does not fire at boot (that would need a persisted last-run record).

Schedules are local wall-clock times, so daylight-saving transitions are visible. A fall-back repeats an hour: firing the same wall-clock minute twice is suppressed (see fireDue), so a daily agent still runs once. A spring-forward skips an hour outright: an agent scheduled inside the skipped hour has no wall-clock minute to run at that day and does not run. Removing the second case would mean scheduling in UTC, which changes what every existing cron spec means.

type Set

type Set map[string]Agent

Set is a read-only-by-convention collection of declared agents, keyed by name (mirrors agentkit's ToolSet / SkillSet). Build one with Discover; read it with Get and All.

func Discover

func Discover(dir string, diag *agentkit.Diagnostics) Set

Discover reads dir/<name>/agent.md for every subdirectory into a Set. A missing dir yields an empty Set. A malformed agent.md is SKIPPED with a diagnostic rather than aborting the scan — a broken agent's authority is then simply absent (fail-closed), and the other agents still load. A duplicate name keeps the first (shadowing). An autonomy: line is reported and otherwise ignored: what an agent may ask is its column of the permission tree, where the line was carried over to.

func (Set) All

func (s Set) All() []Agent

All returns the agents sorted by name.

func (Set) Get

func (s Set) Get(name string) (Agent, bool)

Get returns the named agent.

Jump to

Keyboard shortcuts

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