Documentation
¶
Overview ¶
Package stiggy deploys multi-agent architectures on NATS. It glues two libraries together: phero (github.com/henomis/phero) provides the agents, and packtrail (github.com/henomis/packtrail) provides durable, event-sourced orchestration on JetStream.
A fleet is described once, either as a YAML file run by the stiggy binary or in Go through this package, and both front ends produce the same model. Flows are packtrail flows with a few agent-specific fields; agents run in-process inside packtrail workers.
stiggy never talks to NATS directly. It only opens a connection and hands it to phero and packtrail constructors; every subject, stream and bucket belongs to those libraries.
Index ¶
- Constants
- Variables
- func ActivityTask(id, activity string, step spec.Step) (flow.Node, error)
- func AgentTask(id, agent string, step spec.Step) (flow.Node, error)
- type App
- type Job
- type Option
- func WithActivity(name string, h worker.Handler) Option
- func WithAgent(name string, a spec.Agent) Option
- func WithCrew(name string, c spec.Crew) Option
- func WithEmbedder(name string, e embedding.Embedder) Option
- func WithEngineOptions(opts ...packtrail.Option) Option
- func WithExpose(e spec.Expose) Option
- func WithFleet(f *spec.Fleet) Option
- func WithFlow(f *flow.Flow) Option
- func WithKnowledge(name string, k spec.Knowledge) Option
- func WithLogger(l *slog.Logger) Option
- func WithModel(name string, l llm.LLM) Option
- func WithModelSpec(name string, m spec.Model) Option
- func WithNamespace(ns string) Option
- func WithOnly(names ...string) Option
- func WithPattern(name string, p spec.Pattern) Option
- func WithRegistry(r *registry.Registry) Option
- func WithRemote(name string, r spec.Remote) Option
- func WithRole(r Role) Option
- func WithSchedule(name string, s spec.Schedule) Option
- func WithTool(name string, tools ...*llm.Tool) Option
- func WithToolSpec(name string, t spec.Tool) Option
- func WithTracing(opts ...trace.Option) Option
- func WithVectorStore(name string, s vectorstore.Store) Option
- func WithWorkerOptions(opts ...worker.Option) Option
- type Role
Constants ¶
const AgentID = "stiggy"
AgentID is the protocol's framework name of everything stiggy serves.
const HeaderExecutionID = "Stiggy-Execution-Id"
HeaderExecutionID is the request header a caller of an exposed flow sets to choose the execution id: retrying the same prompt with the same id joins the execution instead of starting another. An id of another flow's execution is refused with a 409 ("execution_conflict"). The execution outlives the prompt: it is not cancelled when the caller or the server goes away.
Variables ¶
var ( ErrNilConn = errors.New("stiggy: nil NATS connection") ErrAlreadyRun = errors.New("stiggy: Run called twice") ErrNotReady = errors.New("stiggy: stopped before it was ready") ErrWriteClash = errors.New("stiggy: activity writes a channel its step also writes") ErrToolClash = errors.New("stiggy: two tools of an agent have the same name") )
Errors returned by an App.
var ErrNoJobValue = jobctx.ErrNoValue
ErrNoJobValue is returned by [Job.DecodeInput] and [Job.DecodeItem] for an absent value.
var ErrOnlyUnknown = errors.New("stiggy: only names no worker of the fleet")
ErrOnlyUnknown is returned when WithOnly names nothing the fleet runs.
var ErrOption = errors.New("stiggy: invalid option")
ErrOption is returned for an invalid option.
Functions ¶
func ActivityTask ¶
ActivityTask returns a task node that runs a Go activity.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is a deployed fleet: the packtrail engine and the workers that run its agent and activity steps, as selected by its Role.
func New ¶
New validates and compiles the fleet the options describe. It does no I/O: models and tools are built, and NATS is used, only by App.Run.
func (*App) Client ¶
Client returns a packtrail client on the fleet's namespace, to start, signal, inspect, fork or cancel executions. It is usable before Run.
type Job ¶ added in v0.1.0
Job is the flow step an agent runs for: its execution, flow, node, agent, step id and attempt, the flow input and map item, and packtrail's long-term store. A Go tool reads it with JobFromContext to know who calls it, instead of trusting an argument the model passes: a persona's "post" tool posts as that persona.
type Option ¶
type Option func(*options) error
Option configures an App.
func WithActivity ¶
WithActivity adds a Go activity: steps with `activity: name` run h.
func WithEmbedder ¶
WithEmbedder adds a ready embedding client under name.
func WithEngineOptions ¶
WithEngineOptions passes options to packtrail.New, after stiggy's own.
func WithExpose ¶
WithExpose serves agents and flows on the NATS Agent Protocol. Several calls add up; the owner may be set once.
func WithFleet ¶
WithFleet adds everything a fleet defines (typically loaded from YAML with package config). Other options may add to it; a name defined twice is an error.
func WithFlow ¶
WithFlow adds a flow. Build agent and activity nodes with AgentTask, ActivityTask or spec.ApplyStep.
func WithKnowledge ¶
WithKnowledge adds a searchable document collection; agents list its name in Knowledge to get a search tool.
func WithLogger ¶
WithLogger sets the logger (default slog.Default()).
func WithModelSpec ¶
WithModelSpec adds a model built by a registered provider.
func WithNamespace ¶
WithNamespace sets the packtrail namespace (default "stiggy").
func WithOnly ¶
WithOnly limits the workers this process runs to the named agents, activities and remotes (and the exposed agents to the named agents), so a deployment can place, say, GPU-bound or secret-holding agents on their own hosts. Other processes of the deployment run the rest.
func WithPattern ¶
WithPattern adds a multi-agent pattern (supervisor, swarm, evaluator_optimizer, debate, plan_execute); it runs as a flow named name. The patterns package builds the same flows for WithFlow.
func WithRegistry ¶
WithRegistry sets the registry of providers, tool types and activities (default registry.New()). Activities added with WithActivity are registered into it.
func WithRemote ¶
WithRemote adds an agent served by someone else on the NATS Agent Protocol; steps run it with Remote, agents list it in Delegates.
func WithSchedule ¶
WithSchedule adds a cron schedule.
func WithToolSpec ¶
WithToolSpec adds a tool built by a registered tool type.
func WithTracing ¶ added in v0.3.1
WithTracing exports the spans of agent steps and exposed agents through a phero trace provider built from opts, typically an exporter:
exp := pherootel.New(tp) stiggy.WithTracing(trace.WithIDSource(exp.IDSource()), trace.WithProcessor(exp))
The App adds the processor of its debug lines first and shuts the provider down when Run returns; an OTel TracerProvider behind it is the caller's to shut down. It replaces the fleet's `tracing:` section.
func WithVectorStore ¶
func WithVectorStore(name string, s vectorstore.Store) Option
WithVectorStore adds a ready vector store under name.
func WithWorkerOptions ¶
WithWorkerOptions passes options to every worker.New, after stiggy's own.
type Role ¶
type Role string
Role selects which parts of a fleet a process runs. Every process of a deployment uses the same fleet definition.
const ( // RoleAll runs the engine and every worker: one process, typical in // development. RoleAll Role = "all" // RoleEngine runs the packtrail engine: it provisions the namespace, // registers the flows and schedules, and drives executions. A fleet // without flows needs no engine, so none is started. RoleEngine Role = "engine" // RoleWorkers runs the agent and activity workers. Scale it out freely. RoleWorkers Role = "workers" )
Roles.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package agentrun runs a phero agent as a packtrail worker.
|
Package agentrun runs a phero agent as a packtrail worker. |
|
cmd
|
|
|
stiggy
command
Command stiggy validates, compiles and runs a fleet described in YAML, and starts executions of its flows.
|
Command stiggy validates, compiles and runs a fleet described in YAML, and starts executions of its flows. |
|
Package compile validates a spec.Fleet and turns it into a Plan: the validated packtrail flows, the workers that run their steps and the schedules.
|
Package compile validates a spec.Fleet and turns it into a Plan: the validated packtrail flows, the workers that run their steps and the schedules. |
|
Package config loads a fleet from YAML into a spec.Fleet.
|
Package config loads a fleet from YAML into a spec.Fleet. |
|
examples
|
|
|
crew
command
Command crew is a crew in YAML: a researcher and a writer work through tasks, the writer's draft is checked by an editor (guardrail), and the crew is also served on the NATS Agent Protocol, so any v0.3 client can call it as a single agent.
|
Command crew is a crew in YAML: a researcher and a writer work through tasks, the writer's draft is checked by an editor (guardrail), and the crew is also served on the NATS Agent Protocol, so any v0.3 client can call it as a single agent. |
|
hello
command
Command hello is the smallest fleet: one agent, one flow, defined in YAML and run in-process.
|
Command hello is the smallest fleet: one agent, one flow, defined in YAML and run in-process. |
|
hitl
command
Command hitl is human in the loop (ask_human and human_input): the planner may ask a human a question through the human route, and its plan is reviewed before the step completes.
|
Command hitl is human in the loop (ask_human and human_input): the planner may ask a human a question through the human route, and its plan is reviewed before the step completes. |
|
internal/extest
Package extest runs an example's program against the NATS server at $NATS_URL (default nats://127.0.0.1:4222), which must run with JetStream: nats-server -js.
|
Package extest runs an example's program against the NATS server at $NATS_URL (default nats://127.0.0.1:4222), which must run with JetStream: nats-server -js. |
|
mapreduce
command
Command mapreduce is a parallel map-reduce, in YAML: a planner returns structured topics (output_schema), a researcher runs once per topic in parallel (a map node), an append channel gathers the notes, and a writer turns them into a summary.
|
Command mapreduce is a parallel map-reduce, in YAML: a planner returns structured topics (output_schema), a researcher runs once per topic in parallel (a map node), an append channel gathers the notes, and a writer turns them into a summary. |
|
remote
command
Command remote uses an agent another team serves on the NATS Agent Protocol.
|
Command remote uses an agent another team serves on the NATS Agent Protocol. |
|
router
command
Command router is agent-chosen routing, built with the Go API: a triage agent reads a support ticket and routes it to the billing or the tech agent, through the route_to_<node> tools stiggy gives it.
|
Command router is agent-chosen routing, built with the Go API: a triage agent reads a support ticket and routes it to the billing or the tech agent, through the route_to_<node> tools stiggy gives it. |
|
socialsim
command
Command socialsim is a small social simulation, in the spirit of MiroFish: a director casts people from a news item, they react on a tiny social network for a few rounds, and an analyst explains how opinion moved.
|
Command socialsim is a small social simulation, in the spirit of MiroFish: a director casts people from a news item, they react on a tiny social network for a few rounds, and an analyst explains how opinion moved. |
|
tracing
command
Command tracing runs a small newsroom fleet and exports its OpenTelemetry spans to Jaeger.
|
Command tracing runs a small newsroom fleet and exports its OpenTelemetry spans to Jaeger. |
|
translator/newsletter
command
Command newsletter drafts a newsletter blurb, then has the shared translator localize it, with a prompt of its own.
|
Command newsletter drafts a newsletter blurb, then has the shared translator localize it, with a prompt of its own. |
|
translator/support
command
Command support answers a customer question, then has the shared translator translate the answer into the customer's language.
|
Command support answers a customer question, then has the shared translator translate the answer into the customer's language. |
|
translator/translator
command
Command translator serves a translator agent on its own: no workflow, just the agent, exposed on the NATS Agent Protocol as translation/translator.
|
Command translator serves a translator agent on its own: no workflow, just the agent, exposed on the NATS Agent Protocol as translation/translator. |
|
internal
|
|
|
archguard
Package archguard enforces stiggy's central architecture rule: stiggy never touches NATS directly.
|
Package archguard enforces stiggy's central architecture rule: stiggy never touches NATS directly. |
|
design
Package design serves the designer: a browser page where workflows are built from blocks.
|
Package design serves the designer: a browser page where workflows are built from blocks. |
|
design/project
Package project is the designer's document: a project of workflows built from blocks (AI Agent, Condition, Loop, Human approval, Agent team...) that Compile turns into a stiggy fleet in YAML.
|
Package project is the designer's document: a project of workflows built from blocks (AI Agent, Condition, Loop, Human approval, Agent team...) that Compile turns into a stiggy fleet in YAML. |
|
jobctx
Package jobctx carries the flow step an agent runs for in its context, so tools can tell which execution, node and map item call them.
|
Package jobctx carries the flow step an agent runs for in its context, so tools can tell which execution, node and map item call them. |
|
logflags
Package logflags gives the stiggy command its logging flags, the same as packtrail's: -log-level (debug, info, warn, error) and -log-format (text, json), each defaulting to an environment variable, and builds the slog.Logger they ask for.
|
Package logflags gives the stiggy command its logging flags, the same as packtrail's: -log-level (debug, info, warn, error) and -log-format (text, json), each defaulting to an environment variable, and builds the slog.Logger they ask for. |
|
natsconn
Package natsconn opens the NATS connection stiggy hands to phero and packtrail.
|
Package natsconn opens the NATS connection stiggy hands to phero and packtrail. |
|
report
Package report carries what a step's handler learns about one attempt (stop reason, latencies, route, review) to the step's end line, which is written by the wrapper around the handler.
|
Package report carries what a step's handler learns about one attempt (stop reason, latencies, route, review) to the step's end line, which is written by the wrapper around the handler. |
|
stepio
Package stepio is what agent and activity steps share: reading the step from a job, the job context as template data, and the step's writes.
|
Package stepio is what agent and activity steps share: reading the step from a job, the job context as template data, and the step's writes. |
|
tracing
Package tracing builds the trace exporter a fleet's `tracing:` section describes, as options of a phero trace provider.
|
Package tracing builds the trace exporter a fleet's `tracing:` section describes, as options of a phero trace provider. |
|
Package patterns expands multi-agent patterns into ordinary packtrail flows: crews (sequential and hierarchical processes, async tasks, guardrails) and the supervisor, swarm, evaluator-optimizer, debate and plan-execute.
|
Package patterns expands multi-agent patterns into ordinary packtrail flows: crews (sequential and hierarchical processes, async tasks, guardrails) and the supervisor, swarm, evaluator-optimizer, debate and plan-execute. |
|
Package registry maps the names a fleet uses to constructors: LLM providers, tool types and activities.
|
Package registry maps the names a fleet uses to constructors: LLM providers, tool types and activities. |
|
Package spec is stiggy's model of a fleet: the models, tools and agents it runs, and the packtrail flows that orchestrate them.
|
Package spec is stiggy's model of a fleet: the models, tools and agents it runs, and the packtrail flows that orchestrate them. |
|
Package stiggytest runs a whole fleet in a test: an embedded JetStream server (packtrail's packtrailtest), the stiggy app in RoleAll, and fake LLMs scripted in Go, so a flow's routing and data flow can be tested like ordinary code.
|
Package stiggytest runs a whole fleet in a test: an embedded JetStream server (packtrail's packtrailtest), the stiggy app in RoleAll, and fake LLMs scripted in Go, so a flow's routing and data flow can be tested like ordinary code. |