Core Concepts

Graph

The core of LangGraphGo is the Graph. It defines the application workflow. It consists of Nodes and Edges.

StateGraph is the most common graph type, allowing you to define a state Schema and pass state between nodes.

State

State is the data maintained by the graph during execution. Each node receives the current state as input and returns state updates as output.

LangGraphGo supports custom state Schemas, allowing you to define how to merge updates from different nodes (e.g., overwrite, append, etc.).

Nodes

Nodes are functions that execute specific logic. They can be calling an LLM, executing a tool, or just simple code logic.

func MyNode(ctx context.Context, state MyState) (MyState, error) {
    // Execute logic
    return newState, nil
}

Edges

Edges define the control flow between nodes.

Parallel Execution

When multiple nodes share the same starting node, LangGraphGo automatically executes them in parallel. Results are merged using the graph's state merger or Schema.

g.AddEdge("start", "branch_a")
g.AddEdge("start", "branch_b")
// branch_a and branch_b will run concurrently

Human in the Loop (HITL)

LangGraphGo supports pausing during graph execution, allowing human intervention. This is useful for scenarios requiring human approval or input.

config := &graph.Config{
    InterruptBefore: []string{"human_review"},
}
// Execution stops before "human_review" node

Checkpointers

Checkpointers are used to persist graph state. This allows you to save execution progress and resume later (e.g., for long-running conversations or failure recovery).

Supported backends include Redis, Postgres, SQLite, etc.

import (
    "github.com/smallnest/langgraphgo/checkpoint/sqlite"
    "github.com/smallnest/langgraphgo/graph"
)

// 1. Initialize SQLite Checkpoint Store
store, err := sqlite.NewSqliteCheckpointStore(sqlite.SqliteOptions{
    Path:      "./checkpoints.db",
    TableName: "checkpoints",
})
if err != nil {
    panic(err)
}
defer store.Close()

// 2. Configure Checkpoint Options
config := graph.CheckpointConfig{
    Store:          store,
    AutoSave:       true,
    SaveInterval:   2 * time.Second,
    MaxCheckpoints: 5,
}

// 3. Apply configuration to the graph
g := graph.NewCheckpointableMessageGraph()
g.SetCheckpointConfig(config)