Getting Started
LangGraphGo is a Go library for building stateful, multi-actor LLM applications, built on LangChainGo. It aims to align with the functionality of the Python LangGraph library.
Installation
Install the library using go get:
go get github.com/smallnest/langgraphgo
Basic Example
Here is a simple example showing how to create a basic chat graph:
package main
import (
"context"
"fmt"
"log"
"github.com/smallnest/langgraphgo/graph"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/llms/openai"
)
func main() {
ctx := context.Background()
model, _ := openai.New()
// 1. Create graph
g := graph.NewStateGraph()
// 2. Add node
g.AddNode("generate", func(ctx context.Context, state interface{}) (interface{}, error) {
messages := state.([]llms.MessageContent)
response, _ := model.GenerateContent(ctx, messages)
return append(messages, llms.TextParts("ai", response.Choices[0].Content)), nil
})
// 3. Define edges
g.AddEdge("generate", graph.END)
g.SetEntryPoint("generate")
// 4. Compile
runnable, _ := g.Compile()
// 5. Invoke
initialState := []llms.MessageContent{
llms.TextParts("human", "Hello, LangGraphGo!"),
}
result, _ := runnable.Invoke(ctx, initialState)
fmt.Println(result)
}
Features Overview
- Core Runtime: Supports parallel execution, runtime configuration, and seamless compatibility with langchaingo.
- Persistence: Provides Checkpointers like Redis, Postgres, SQLite, supporting state saving and restoration.
- Advanced Capabilities: State Schema, smart message merging, subgraphs, streaming, etc.
- Developer Experience: Graph visualization, Human in the Loop (HITL) support, observability.