examples/

directory
v0.3.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0

README

Examples

Each example is a single main.go that connects to a JetStream-enabled NATS server ($NATS_URL, default nats://localhost:4222), starts an engine and its workers, and prints what happens:

docker run --rm -p 4222:4222 nats:2.14.2 -js
go run ./examples/hello
make examples          # run them all
Example Shows
hello The smallest program: a two-step flow, a worker, start and wait; reading a previous node's output
approval Human in the loop: a task that interrupts with a question and is resumed with the answer; an await node with a timeout route; a choice on the signal
research Parallel branches (fanout + quorum join) writing to shared state through reducer channels (append, merge, sum); a budget on a counter
mapreduce A dynamic map over a list computed at run time, bounded parallelism, ordered results, reducers as the reduce step
resilience Retries with backoff, per-attempt timeouts (the late result is ignored), output JSON Schema, permanent errors
timetravel History, state at any sequence, rerun of a failed node after a fix, fork from the past
agentloop A tool-using loop: a planner routing with dynamic edges, a message channel, a recursion limit and a call budget — no LLM required
subflow A flow calling another flow; child output and counters flow back; cancelling the parent cancels the child
events Executions started by a cron schedule and by messages on a subject (deduplicated by Nats-Msg-Id)

Each example uses its own namespace (example-<name>), so they do not interfere. While an example runs you can inspect it with the CLI and the UI:

go run ./cmd/packtrail -ns example-timetravel list
go run ./cmd/packtrail-ui -namespace example-timetravel

Directories

Path Synopsis
Example agentloop: the shape of a tool-using agent, built from generic parts — packtrail knows nothing about LLMs.
Example agentloop: the shape of a tool-using agent, built from generic parts — packtrail knows nothing about LLMs.
Example approval: human in the loop, two ways.
Example approval: human in the loop, two ways.
Example events: executions started by time and by messages.
Example events: executions started by time and by messages.
Example hello: the smallest packtrail program.
Example hello: the smallest packtrail program.
internal
devserver
Package devserver gives the examples a NATS connection to the server named by $NATS_URL (default nats://127.0.0.1:4222), which must have JetStream enabled.
Package devserver gives the examples a NATS connection to the server named by $NATS_URL (default nats://127.0.0.1:4222), which must have JetStream enabled.
exutil
Package exutil holds the few lines every example repeats.
Package exutil holds the few lines every example repeats.
Example mapreduce: a dynamic fan-out over a list computed at run time.
Example mapreduce: a dynamic fan-out over a list computed at run time.
Example research: parallel branches writing to shared state.
Example research: parallel branches writing to shared state.
Example resilience: what happens when workers misbehave.
Example resilience: what happens when workers misbehave.
Example subflow: composing flows.
Example subflow: composing flows.
Example timetravel: the event log as a debugging tool.
Example timetravel: the event log as a debugging tool.

Jump to

Keyboard shortcuts

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