Documentation
¶
Overview ¶
Package graphgo is the ergonomic entry point for building durable, stateful, multi-agent LLM workflows in Go. It re-exports the most common types and builders from the pkg/* subpackages so that a typical application only needs to import "github.com/arbazkhan971/graphgo".
A minimal workflow:
type State struct{ Topic, Answer string }
g := graphgo.NewGraph[State]()
g.AddNode("write", graphgo.LLMNode(graphgo.LLMConfig[State]{
Provider: graphgo.NewMock("42"),
Prompt: func(s State) string { return "Answer about " + s.Topic },
Apply: func(s State, r *graphgo.Response) (State, error) { s.Answer = r.Content; return s, nil },
}))
g.SetEntryPoint("write")
g.SetFinishPoint("write")
res, err := g.Run(context.Background(), State{Topic: "Go"})
See the examples directory for complete programs.
Index ¶
- Constants
- func AgentNode[S any](cfg AgentConfig[S]) graph.NodeFunc[S]
- func Anthropic(opts anthropic.Options) llm.Provider
- func Gemini(opts gemini.Options) llm.Provider
- func HumanApprovalNode[S any](cfg HumanApprovalConfig[S]) graph.NodeFunc[S]
- func LLMNode[S any](cfg LLMConfig[S]) graph.NodeFunc[S]
- func LLMRouter[S any](cfg RouterConfig[S]) func(context.Context, S) string
- func NewGraph[S any]() *graph.Graph[S]
- func NewMemoryStore() *checkpoint.MemoryStore
- func NewMock(responses ...string) *llm.Mock
- func NewProvider(cfg ProviderConfig) (llm.Provider, error)
- func Ollama(opts ollama.Options) llm.Provider
- func OpenAI(opts openai.Options) llm.Provider
- func OpenSQLite(path string) (*sqlite.Store, error)
- func ParallelNode[S any](combine func(base S, results []S) S, branches ...graph.NodeFunc[S]) graph.NodeFunc[S]
- func ProviderNames() []string
- func Render(tmpl string, d Dict) string
- func ToolNode[S any](cfg ToolNodeConfig[S]) graph.NodeFunc[S]
- func WithKind[S any](kind string) graph.NodeOption[S]
- func WithListener(l Listener) graph.RunOption
- func WithRetry[S any](p RetryPolicy) graph.NodeOption[S]
- func WithRunID(id string) graph.RunOption
- func WithStore(s Store) graph.RunOption
- type AgentConfig
- type ApprovalRequest
- type Checkpoint
- type Decision
- type Dict
- type Event
- type EventType
- type HumanApprovalConfig
- type LLMConfig
- type Listener
- type Message
- type Provider
- type ProviderConfig
- type Registry
- type Request
- type Response
- type RetryPolicy
- type RouterConfig
- type RunInfo
- type Spec
- type Store
- type Tool
- type ToolNodeConfig
- type ToolSpec
Constants ¶
const ( // Start is the virtual entry node. Start = graph.START // End is the virtual terminal node; route to it to finish a run. End = graph.END )
Virtual endpoints used when wiring edges.
const Version = "0.1.0"
Version is the GraphGo release version.
Variables ¶
This section is empty.
Functions ¶
func AgentNode ¶
func AgentNode[S any](cfg AgentConfig[S]) graph.NodeFunc[S]
AgentNode returns a node that runs a ReAct-style loop: the model may request tool calls, which are executed and fed back until the model returns a final answer (a response with no tool calls) or MaxIterations is reached.
func HumanApprovalNode ¶
func HumanApprovalNode[S any](cfg HumanApprovalConfig[S]) graph.NodeFunc[S]
HumanApprovalNode returns a node that pauses the run for human review.
On first visit it interrupts, checkpointing the run and surfacing an ApprovalRequest. The caller resumes with a Decision (via g.Resume or the CLI). On resume the node applies the decision and continues. When called outside the engine (no Runtime in context) or with AutoApprove set, it approves automatically so unit tests never deadlock.
func LLMNode ¶
LLMNode returns a node that calls a language model and applies the response to state.
func LLMRouter ¶
func LLMRouter[S any](cfg RouterConfig[S]) func(context.Context, S) string
LLMRouter returns a routing function suitable for AddConditionalEdge. It asks the model to pick exactly one of the allowed routes and matches its answer against them (case-insensitive). On any ambiguity it returns Default.
func NewMemoryStore ¶
func NewMemoryStore() *checkpoint.MemoryStore
NewMemoryStore returns an in-memory checkpoint store.
func NewMock ¶
NewMock returns a deterministic, offline provider used by tests, examples and keyless demos.
func NewProvider ¶
func NewProvider(cfg ProviderConfig) (llm.Provider, error)
NewProvider constructs an llm.Provider from a configuration. It is the entry point used by the CLI to turn --provider/--model flags into a live provider.
func Ollama ¶
Ollama returns a local Ollama provider (default endpoint http://localhost:11434).
func OpenAI ¶
OpenAI returns an OpenAI (or OpenAI-compatible) provider. Pass a BaseURL to target local/self-hosted servers such as vLLM, llama.cpp or LM Studio.
func OpenSQLite ¶
OpenSQLite opens (creating if needed) a durable SQLite-backed checkpoint store at path. The returned store persists run history across process restarts, enabling resume, replay and inspection. It uses a pure-Go SQLite driver, so the binary stays statically linkable with no CGO.
func ParallelNode ¶
func ParallelNode[S any](combine func(base S, results []S) S, branches ...graph.NodeFunc[S]) graph.NodeFunc[S]
ParallelNode runs branches concurrently, each on an independent deep copy of the input state, then merges their results with combine. It models concurrency as a single node so the engine keeps a deterministic, one-active-node execution model. combine receives the original input state and the per-branch results in branch order. If any branch errors, the node fails with that error.
func ProviderNames ¶
func ProviderNames() []string
ProviderNames returns the set of provider identifiers accepted by NewProvider.
func ToolNode ¶
func ToolNode[S any](cfg ToolNodeConfig[S]) graph.NodeFunc[S]
ToolNode returns a node that invokes exactly one tool with arguments derived from state and writes the result back into state. Unlike AgentNode there is no model in the loop, making it fully deterministic.
func WithKind ¶
func WithKind[S any](kind string) graph.NodeOption[S]
WithKind sets a node's visualization kind ("llm", "tool", "human", etc.).
func WithListener ¶
WithListener streams execution events to l.
func WithRetry ¶
func WithRetry[S any](p RetryPolicy) graph.NodeOption[S]
WithRetry attaches a retry policy to a node.
Types ¶
type AgentConfig ¶
type AgentConfig[S any] struct { Provider llm.Provider Model string System string Prompt func(S) string Tools *tools.Registry Apply func(S, *llm.Response) (S, error) Temperature float64 MaxTokens int // MaxIterations bounds the tool-use loop (default 6). MaxIterations int // OnToolCall is an optional observability hook fired for each tool call. OnToolCall func(name, args, result string) }
AgentConfig configures an AgentNode: an LLM that can call tools in a loop until it produces a final answer.
type ApprovalRequest ¶
type ApprovalRequest struct {
Kind string `json:"kind"` // always "approval"
Prompt string `json:"prompt"` // human-readable description of what to approve
Node string `json:"node"` // the node awaiting approval
}
ApprovalRequest is the interrupt payload produced by a HumanApprovalNode. It is delivered in Result.Interrupt.Payload and stored in the interrupt checkpoint.
type Decision ¶
type Decision struct {
Approved bool `json:"approved"`
Value any `json:"value,omitempty"`
Feedback string `json:"feedback,omitempty"`
}
Decision is a human-in-the-loop verdict delivered to a HumanApprovalNode via Resume. Value carries any edited payload the reviewer supplied.
type HumanApprovalConfig ¶
type HumanApprovalConfig[S any] struct { // Prompt builds the message shown to the reviewer from the current state. Prompt func(S) string // Apply updates the state given the reviewer's Decision. If nil, the state // is returned unchanged and approval merely gates progression. Apply func(state S, d Decision) (S, error) // AutoApprove skips the pause and approves immediately (handy for CI). AutoApprove bool // NodeName labels the approval request; defaults to "human". NodeName string }
HumanApprovalConfig configures a HumanApprovalNode.
type LLMConfig ¶
type LLMConfig[S any] struct { // Provider is the language model backend (required). Provider llm.Provider // Model overrides the provider's default model. Model string // System is an optional system prompt. System string // Prompt builds the user message from state. Required unless Messages is set. Prompt func(S) string // Messages, when set, builds the entire message list and overrides // System+Prompt. Messages func(S) []llm.Message // Apply writes the model's response back into state (required to persist it). Apply func(S, *llm.Response) (S, error) Temperature float64 MaxTokens int }
LLMConfig configures an LLMNode.
type ProviderConfig ¶
type ProviderConfig struct {
Name string // "mock", "openai", "anthropic", "gemini", "ollama"
Model string
BaseURL string
APIKey string
}
ProviderConfig selects and configures an LLM provider by name. Empty fields fall back to each provider's defaults, including reading API keys from the conventional environment variables (OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY/GOOGLE_API_KEY). The "mock" provider needs no configuration and runs fully offline.
type Registry ¶
Registry is a collection of tools.
func NewRegistry ¶
NewRegistry returns a tool registry preloaded with ts.
type RetryPolicy ¶
type RetryPolicy = graph.RetryPolicy
RetryPolicy configures automatic retries for a node.
type RouterConfig ¶
type RouterConfig[S any] struct { Provider llm.Provider Model string Prompt func(S) string // Routes are the allowed route keys the model must choose among. Routes []string // Default is returned when the model's answer matches no route. Default string }
RouterConfig configures an LLM-based router used with g.AddConditionalEdge.
type ToolNodeConfig ¶
type ToolNodeConfig[S any] struct { Tool tools.Tool Args func(S) (json.RawMessage, error) Apply func(S, string) (S, error) }
ToolNodeConfig configures a deterministic single-tool node.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
graphgo
command
Command graphgo is the command-line interface for GraphGo: run, visualize, replay and inspect durable agent workflows defined in YAML, and scaffold new projects.
|
Command graphgo is the command-line interface for GraphGo: run, visualize, replay and inspect durable agent workflows defined in YAML, and scaffold new projects. |
|
examples
|
|
|
go/chatbot
command
Example: a minimal single-node chatbot using the typed Go SDK.
|
Example: a minimal single-node chatbot using the typed Go SDK. |
|
go/code-review
command
Example: a tool-using code-review agent (ReAct loop).
|
Example: a tool-using code-review agent (ReAct loop). |
|
go/human-approval
command
Example: durable human-in-the-loop with SQLite checkpointing.
|
Example: durable human-in-the-loop with SQLite checkpointing. |
|
go/ollama
command
Example: a fully-local workflow backed by Ollama.
|
Example: a fully-local workflow backed by Ollama. |
|
go/research
command
Example: a research agent with a cycle and a conditional edge.
|
Example: a research agent with a cycle and a conditional edge. |
|
pkg
|
|
|
checkpoint
Package checkpoint defines the durable persistence layer for GraphGo.
|
Package checkpoint defines the durable persistence layer for GraphGo. |
|
checkpoint/sqlite
Package sqlite provides a durable, file-backed implementation of the checkpoint.Store interface built on database/sql and the pure-Go modernc.org/sqlite driver (no cgo required).
|
Package sqlite provides a durable, file-backed implementation of the checkpoint.Store interface built on database/sql and the pure-Go modernc.org/sqlite driver (no cgo required). |
|
llm
Package llm defines a provider-agnostic interface for chat-style language models, plus the message/request/response types shared by all providers.
|
Package llm defines a provider-agnostic interface for chat-style language models, plus the message/request/response types shared by all providers. |
|
llm/anthropic
Package anthropic implements an llm.Provider (and llm.StreamProvider) backed by Anthropic's Claude Messages API (POST /v1/messages).
|
Package anthropic implements an llm.Provider (and llm.StreamProvider) backed by Anthropic's Claude Messages API (POST /v1/messages). |
|
llm/gemini
Package gemini implements an llm.Provider (and llm.StreamProvider) backed by Google's Gemini models via the Generative Language API (https://generativelanguage.googleapis.com).
|
Package gemini implements an llm.Provider (and llm.StreamProvider) backed by Google's Gemini models via the Generative Language API (https://generativelanguage.googleapis.com). |
|
llm/ollama
Package ollama implements the llm.Provider and llm.StreamProvider interfaces on top of a locally running Ollama server, using its native /api/chat endpoint (https://github.com/ollama/ollama/blob/main/docs/api.md).
|
Package ollama implements the llm.Provider and llm.StreamProvider interfaces on top of a locally running Ollama server, using its native /api/chat endpoint (https://github.com/ollama/ollama/blob/main/docs/api.md). |
|
llm/openai
Package openai implements an llm.Provider (and llm.StreamProvider) for the OpenAI Chat Completions API.
|
Package openai implements an llm.Provider (and llm.StreamProvider) for the OpenAI Chat Completions API. |
|
runtime
Package runtime provides presentation and replay helpers built on top of the graph engine's event stream and checkpoint history: a pretty console printer for live runs, a JSON-lines printer for machine consumption, and a replay facility that reconstructs a past run from its checkpoints.
|
Package runtime provides presentation and replay helpers built on top of the graph engine's event stream and checkpoint history: a pretty console printer for live runs, a JSON-lines printer for machine consumption, and a replay facility that reconstructs a past run from its checkpoints. |
|
state
Package state provides the dynamic, JSON-serializable state container used by YAML-defined workflows and by any code that prefers an untyped, map-backed state.
|
Package state provides the dynamic, JSON-serializable state container used by YAML-defined workflows and by any code that prefers an untyped, map-backed state. |
|
tools
Package tools defines the tool-calling abstraction used by agent nodes.
|
Package tools defines the tool-calling abstraction used by agent nodes. |
|
visualize
Package visualize renders a graph.Spec into human- and tool-friendly diagram formats: Mermaid flowcharts, indented JSON, and a self-contained SVG.
|
Package visualize renders a graph.Spec into human- and tool-friendly diagram formats: Mermaid flowcharts, indented JSON, and a self-contained SVG. |
|
workflow
Package workflow parses declarative YAML workflow definitions into runnable GraphGo graphs.
|
Package workflow parses declarative YAML workflow definitions into runnable GraphGo graphs. |