stiggy

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 34 Imported by: 1 module, 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.

README

stiggy

Build Status GoDoc Go Report Card GitHub release

stiggy deploys multi-agent architectures on NATS. It glues phero, which provides the agents, to packtrail, which provides durable, event-sourced orchestration on JetStream. It adds crews, supervisors, swarms, human review and replay on a substrate that survives crashes and scales out.

You describe a fleet once, either as a YAML file run by the stiggy binary or in Go through the github.com/henomis/stiggy library. Both build the same model:

  • models, tools, knowledge: any LLM provider, tool, memory backend or vector store phero offers, plus MCP servers;
  • agents: a model, a role/goal/backstory, tools, memory, knowledge and delegates;
  • flows: packtrail flows whose steps run agents. Every packtrail feature is available: choices, fan-out/join, maps, subflows, waits, retries, budgets, fork, rerun and time travel;
  • crews and patterns: task crews and the supervisor, swarm, evaluator-optimizer, debate and plan-execute, expanded into flows.

Quick start

nats-server -js &
go install github.com/henomis/stiggy/cmd/stiggy@latest
# fleet.yaml
namespace: newsroom
models:
  fast: {provider: ollama, model: llama3.2-eco}
agents:
  researcher: {model: fast, role: Researcher, goal: "Find accurate, recent facts."}
  writer: {model: fast, role: Writer, goal: "Write short, clear articles."}
crews:
  article:
    tasks:
      - {id: research, agent: researcher, description: "Research {{.input.topic}}."}
      - {id: write, agent: writer, description: Write a 200-word article from the research.}
stiggy validate fleet.yaml        # every problem, with its line
stiggy compile fleet.yaml         # the packtrail flows it becomes
stiggy run fleet.yaml &           # serve it
stiggy start -ns newsroom article -input '{"topic": "NATS"}' -wait

The same in Go:

nc, _ := nats.Connect(nats.DefaultURL)

app, _ := stiggy.New(nc,
    stiggy.WithNamespace("newsroom"),
    stiggy.WithModel("fast", openai.New("ollama",
        openai.WithBaseURL(openai.OllamaBaseURL), openai.WithModel("llama3.2-eco"))),
    stiggy.WithAgent("researcher", spec.Agent{Model: "fast", Role: "Researcher"}),
    stiggy.WithAgent("writer", spec.Agent{Model: "fast", Role: "Writer"}),
    stiggy.WithCrew("article", spec.Crew{Tasks: []spec.Task{
        {ID: "research", Agent: "researcher", Description: "Research {{.input.topic}}."},
        {ID: "write", Agent: "writer", Description: "Write a 200-word article from the research."},
    }}),
)

go app.Run(ctx)
<-app.Ready()

id, _ := app.Client().Start(ctx, "article", map[string]any{"topic": "NATS"})
st, _ := app.Client().Wait(ctx, id)

app.Client() is a packtrail client: signal, resume, update, fork, rerun, watch and stream progress from it.

How it works

 fleet.yaml ─┐                         ┌─ packtrail engine (event log, timers, budgets)
             ├─► spec.Fleet ─► compile ─┤
 Go options ─┘   (validate)            └─ workers: one per agent / activity / remote
                                            └─ fresh phero agent per job
  • A flow step that runs an agent is a packtrail task whose meta holds the step (prompt, writes, routes, ...). It is versioned with the flow, so a running execution keeps the configuration it started with.
  • Each agent is a packtrail worker kind. Every job builds a fresh phero agent, runs it, and returns its output, channel writes and usage.
  • Agent-chosen routing, ask_human, structured output and execution memory live in packtrail state, so they are durable and correct under fork, rerun and time travel.
  • stiggy never touches NATS directly. It opens one connection and hands it to phero and packtrail, and internal/archguard enforces this in the test suite.

Documentation

Examples

Example Shows
hello The smallest YAML fleet
router Agent-chosen routing, built with the Go API
mapreduce Structured output, a parallel map, an append channel
hitl ask_human and human review, resumed with Client.Resume
crew A crew with a guardrail, also served as a protocol agent
remote Another team's phero agent as a step and as a delegate
socialsim A small social simulation: one persona agent per map item through templated system prompts and memory sessions, Go tools that know their caller (JobFromContext), rounds in a loop, and a what-if fork with breaking news

Each runs against $NATS_URL, with a real model when OLLAMA_MODEL, OPENAI_API_KEY or ANTHROPIC_API_KEY is set (in that order), and a scripted one otherwise:

go run ./examples/router
OLLAMA_MODEL=llama3.2-eco go run ./examples/mapreduce

The examples are tests too. make examples runs them with the scripted models on an embedded server. make examples-live runs them against a real model, by default OLLAMA_MODEL=llama3.2-eco.

Deployment

Every process of a deployment runs the same fleet file and picks its part:

stiggy run fleet.yaml -role engine -http :8080                 # one or more engines
stiggy run fleet.yaml -role workers -http :8080                # scale out
stiggy run fleet.yaml -role workers -only researcher,writer    # dedicated hosts

/healthz and /readyz serve health checks. deploy/ has a Dockerfile and a docker-compose setup. To operate executions, use stiggy get | history | progress | signal | resume | update | cancel | fork | rerun, or packtrail's CLI and packtrail-ui on the fleet's namespace.

Development

make test           # tests with -race
make check          # test + examples + lint + vet
make examples       # the examples, scripted
make examples-live  # the examples, against a real model
make e2e            # end-to-end scenarios against a real model and Qdrant

e2e/ runs whole fleets against a real model through Ollama (gemma4:cloud by default, STIGGY_E2E_MODEL to change it): map-reduce research, plan-and-execute across three processes, RAG on Qdrant, a supervisor with file tools, human review with fork, execution and long-term memory, cross-team remote agents and delegates, a crew over the NATS Agent Protocol, and the evaluator and debate patterns. make e2e starts Qdrant with Docker (make e2e-down stops it) and needs Ollama with nomic-embed-text for embeddings; E2E_RUN=TestName runs one scenario.

License

Apache 2.0. See LICENSE.

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

View Source
const AgentID = "stiggy"

AgentID is the protocol's framework name of everything stiggy serves.

View Source
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

View Source
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.

View Source
var ErrNoJobValue = jobctx.ErrNoValue

ErrNoJobValue is returned by [Job.DecodeInput] and [Job.DecodeItem] for an absent value.

View Source
var ErrOnlyUnknown = errors.New("stiggy: only names no worker of the fleet")

ErrOnlyUnknown is returned when WithOnly names nothing the fleet runs.

View Source
var ErrOption = errors.New("stiggy: invalid option")

ErrOption is returned for an invalid option.

Functions

func ActivityTask

func ActivityTask(id, activity string, step spec.Step) (flow.Node, error)

ActivityTask returns a task node that runs a Go activity.

func AgentTask

func AgentTask(id, agent string, step spec.Step) (flow.Node, error)

AgentTask returns a task node that runs agent with step's other settings (prompt, writes, routes); set the node's other fields (next, retry, timeout, ...) on the result.

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

func New(nc *nats.Conn, opts ...Option) (*App, error)

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

func (a *App) Client() *packtrail.Client

Client returns a packtrail client on the fleet's namespace, to start, signal, inspect, fork or cancel executions. It is usable before Run.

func (*App) Plan

func (a *App) Plan() *compile.Plan

Plan returns the compiled fleet.

func (*App) Ready

func (a *App) Ready() <-chan struct{}

Ready is closed once everything the role runs is serving: the engine is provisioned and every worker is pulling jobs.

func (*App) Run

func (a *App) Run(ctx context.Context) error

Run serves the fleet until ctx is done, then shuts down in order: workers drain their in-flight jobs first, then the engine stops. It returns nil on a clean shutdown, or the first error that stopped a component.

type Job added in v0.1.0

type Job = jobctx.Job

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.

func JobFromContext added in v0.1.0

func JobFromContext(ctx context.Context) (Job, bool)

JobFromContext returns the job of a tool call's context. It reports false outside a flow step, as for an exposed agent answering a prompt.

type Option

type Option func(*options) error

Option configures an App.

func WithActivity

func WithActivity(name string, h worker.Handler) Option

WithActivity adds a Go activity: steps with `activity: name` run h.

func WithAgent

func WithAgent(name string, a spec.Agent) Option

WithAgent adds an agent.

func WithCrew

func WithCrew(name string, c spec.Crew) Option

WithCrew adds a crew; it runs as a flow named name.

func WithEmbedder

func WithEmbedder(name string, e embedding.Embedder) Option

WithEmbedder adds a ready embedding client under name.

func WithEngineOptions

func WithEngineOptions(opts ...packtrail.Option) Option

WithEngineOptions passes options to packtrail.New, after stiggy's own.

func WithExpose

func WithExpose(e spec.Expose) Option

WithExpose serves agents and flows on the NATS Agent Protocol. Several calls add up; the owner may be set once.

func WithFleet

func WithFleet(f *spec.Fleet) Option

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

func WithFlow(f *flow.Flow) Option

WithFlow adds a flow. Build agent and activity nodes with AgentTask, ActivityTask or spec.ApplyStep.

func WithKnowledge

func WithKnowledge(name string, k spec.Knowledge) Option

WithKnowledge adds a searchable document collection; agents list its name in Knowledge to get a search tool.

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger sets the logger (default slog.Default()).

func WithModel

func WithModel(name string, l llm.LLM) Option

WithModel adds a ready LLM client under name.

func WithModelSpec

func WithModelSpec(name string, m spec.Model) Option

WithModelSpec adds a model built by a registered provider.

func WithNamespace

func WithNamespace(ns string) Option

WithNamespace sets the packtrail namespace (default "stiggy").

func WithOnly

func WithOnly(names ...string) Option

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

func WithPattern(name string, p spec.Pattern) Option

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

func WithRegistry(r *registry.Registry) Option

WithRegistry sets the registry of providers, tool types and activities (default registry.New()). Activities added with WithActivity are registered into it.

func WithRemote

func WithRemote(name string, r spec.Remote) Option

WithRemote adds an agent served by someone else on the NATS Agent Protocol; steps run it with Remote, agents list it in Delegates.

func WithRole

func WithRole(r Role) Option

WithRole sets which parts of the fleet this process runs (default RoleAll).

func WithSchedule

func WithSchedule(name string, s spec.Schedule) Option

WithSchedule adds a cron schedule.

func WithTool

func WithTool(name string, tools ...*llm.Tool) Option

WithTool adds ready tools under one name; agents list the name to get all of them.

func WithToolSpec

func WithToolSpec(name string, t spec.Tool) Option

WithToolSpec adds a tool built by a registered tool type.

func WithVectorStore

func WithVectorStore(name string, s vectorstore.Store) Option

WithVectorStore adds a ready vector store under name.

func WithWorkerOptions

func WithWorkerOptions(opts ...worker.Option) Option

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.
	RoleEngine Role = "engine"
	// RoleWorkers runs the agent and activity workers. Scale it out freely.
	RoleWorkers Role = "workers"
)

Roles.

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 against an embedded NATS server, so the examples are tested like the rest of the code.
Package extest runs an example against an embedded NATS server, so the examples are tested like the rest of the code.
internal/exutil
Package exutil is what the examples share: the NATS connection, the model (a real one when an API key is set, a scripted one otherwise), and running an app for the length of an example.
Package exutil is what the examples share: the NATS connection, the model (a real one when an API key is set, a scripted one otherwise), and running an app for the length of an example.
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.
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.
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.
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.
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.
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.

Jump to

Keyboard shortcuts

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