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