repo stringlengths 6 47 | file_url stringlengths 77 269 | file_path stringlengths 5 186 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-07 08:35:43 2026-01-07 08:55:24 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/callbacks.go | graph/callbacks.go | package graph
import (
"context"
"time"
)
// CallbackHandler defines the interface for handling graph execution callbacks
// This matches Python's LangChain callback pattern
type CallbackHandler interface {
// Chain callbacks (for graph/workflow execution)
OnChainStart(ctx context.Context, serialized map[string]a... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/test_constants_test.go | graph/test_constants_test.go | package graph_test
const (
testNode = "test_node"
testState = "test_state"
testResult = "test_result"
)
| go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/state_graph_tracer_test.go | graph/state_graph_tracer_test.go | package graph
import (
"context"
"testing"
)
func TestStateGraph_WithTracer(t *testing.T) {
// Create a StateGraph
g := NewStateGraph[map[string]any]()
// Add nodes
g.AddNode("node1", "First node", func(ctx context.Context, state map[string]any) (map[string]any, error) {
return map[string]any{"result": "resu... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/tracing.go | graph/tracing.go | package graph
import (
"context"
"time"
)
// TraceEvent represents different types of events in graph execution
type TraceEvent string
const (
// TraceEventGraphStart indicates the start of graph execution
TraceEventGraphStart TraceEvent = "graph_start"
// TraceEventGraphEnd indicates the end of graph executio... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/parallel.go | graph/parallel.go | package graph
import (
"context"
"fmt"
"sync"
)
// ParallelNode represents a set of nodes that can execute in parallel
type ParallelNode[S any] struct {
nodes []TypedNode[S]
name string
}
// NewParallelNode creates a new parallel node
func NewParallelNode[S any](name string, nodes ...TypedNode[S]) *ParallelNod... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/config_test.go | graph/config_test.go | package graph
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRuntimeConfiguration(t *testing.T) {
g := NewStateGraph[map[string]any]()
// Define a node that reads config from context
g.AddNode("reader", "reader", func(ctx context.Context, state map[string]any) (map[string]any, er... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/state_graph_generic_test.go | graph/state_graph_generic_test.go | package graph
import (
"context"
"errors"
"testing"
"time"
)
// TestState is a simple test state
type TestState struct {
Count int `json:"count"`
Name string `json:"name"`
}
// mapSchemaAdapter adapts MapSchema to StateSchema[any]
type mapSchemaAdapter struct {
*MapSchema
}
func (m *mapSchemaAdapter) Ini... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/conditional_edges_test.go | graph/conditional_edges_test.go | package graph_test
import (
"context"
"strings"
"testing"
"github.com/smallnest/langgraphgo/graph"
"github.com/tmc/langchaingo/llms"
)
//nolint:gocognit,dupl,cyclop // This is a comprehensive test that needs to check multiple scenarios with similar setup
func TestConditionalEdges(t *testing.T) {
t.Parallel()
... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/command.go | graph/command.go | package graph
// Command allows a node to dynamically update the state and control the flow.
// It can be returned by a node function instead of a direct state update.
type Command struct {
// Update is the value to update the state with.
// It will be processed by the schema's reducers.
Update any
// Goto specif... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/command_test.go | graph/command_test.go | package graph
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
// mapSchemaAdapterForAny adapts MapSchema for use with StateGraph[any]
type mapSchemaAdapterForAny struct {
*MapSchema
}
func (m *mapSchemaAdapterForAny) Init() any {
return m.MapSchema.Init()
}
func (m *mapSchemaAdapterForAny)... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/retry.go | graph/retry.go | package graph
import (
"context"
"fmt"
"math"
"math/rand"
"time"
)
// RetryConfig configures retry behavior for nodes
type RetryConfig struct {
MaxAttempts int
InitialDelay time.Duration
MaxDelay time.Duration
BackoffFactor float64
RetryableErrors func(error) bool // Determines if an error s... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/state_graph_with_schema_test.go | graph/state_graph_with_schema_test.go | package graph
import (
"context"
"testing"
)
func TestNewMessageGraph(t *testing.T) {
g := NewMessageGraph()
// Verify schema is initialized
if g.Schema == nil {
t.Fatal("Schema should be initialized")
}
// Verify messages reducer is registered
// Schema is now MapSchema directly
mapSchema, ok := g.Schem... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/parallel_execution_test.go | graph/parallel_execution_test.go | package graph
import (
"context"
"maps"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
// appendVisitors is a helper function that appends a node name to the visited list in the state.
func appendVisitors(state map[string]any, node string) []string {
visited, ok := state["visited"].([]string)
if !ok ... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/streaming.go | graph/streaming.go | package graph
import (
"context"
"sync"
"time"
)
// StreamMode defines the mode of streaming
type StreamMode string
const (
// StreamModeValues emits the full state after each step
StreamModeValues StreamMode = "values"
// StreamModeUpdates emits the updates (deltas) from each node
StreamModeUpdates StreamMod... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/builtin_listeners_test.go | graph/builtin_listeners_test.go | package graph_test
import (
"bytes"
"context"
"fmt"
"log"
"strings"
"testing"
"time"
"github.com/smallnest/langgraphgo/graph"
)
const (
step2Result = "step2_result"
)
func TestProgressListener_OnNodeEvent(t *testing.T) {
t.Parallel()
var buf bytes.Buffer
listener := graph.NewProgressListenerWithWriter(... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/state_graph_interrupt_test.go | graph/state_graph_interrupt_test.go | package graph
import (
"context"
"errors"
"testing"
)
func TestStateGraph_Interrupt(t *testing.T) {
// Create a StateGraph
g := NewStateGraph[map[string]any]()
// Add node that uses Interrupt
g.AddNode("node1", "Node with interrupt", func(ctx context.Context, state map[string]any) (map[string]any, error) {
... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/streaming_test.go | graph/streaming_test.go | package graph
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestStreamingModes(t *testing.T) {
g := NewStreamingStateGraph[map[string]any]()
// Setup simple graph using map-based state
g.AddNode("A", "A", func(ctx context.Context, state map[string]any) (map[string]any, error) {
re... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/visualization.go | graph/visualization.go | package graph
import (
"fmt"
"sort"
"strings"
)
// Exporter provides methods to export graphs in different formats
type Exporter[S any] struct {
graph *StateGraph[S]
}
// NewExporter creates a new graph exporter for the given graph
func NewExporter[S any](graph *StateGraph[S]) *Exporter[S] {
return &Exporter[S]... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/interrupt_test.go | graph/interrupt_test.go | package graph
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGraphInterrupt(t *testing.T) {
g := NewStateGraph[map[string]any]()
g.AddNode("A", "A", func(ctx context.Context, state map[string]any) (map[string]any, error) {
state["value"] = state["value"].(string) + "A"
return s... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/graph.go | graph/graph.go | package graph
import (
"context"
"errors"
"fmt"
)
// END is a special constant used to represent the end node in the graph.
const END = "END"
var (
// ErrEntryPointNotSet is returned when the entry point of the graph is not set.
ErrEntryPointNotSet = errors.New("entry point not set")
// ErrNodeNotFound is ret... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/schema_test.go | graph/schema_test.go | package graph
import (
"context"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
// SchemaTestState is used for schema tests
type SchemaTestState struct {
Count int
Name string
Numbers []int
Logs []string
}
// StructSchema Tests
func TestNewStructSchema(t *testing.T) {
t.Run("Create sch... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/listeners_test.go | graph/listeners_test.go | package graph_test
import (
"context"
"fmt"
"sync"
"testing"
"time"
"github.com/smallnest/langgraphgo/graph"
)
const (
resultValue = "result"
)
func TestListenableNode_AddListener(t *testing.T) {
t.Parallel()
node := graph.TypedNode[string]{
Name: testNode,
Function: func(ctx context.Context, state st... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/errors.go | graph/errors.go | package graph
import "fmt"
// NodeInterrupt is returned when a node requests an interrupt (e.g. waiting for human input).
type NodeInterrupt struct {
// Node is the name of the node that triggered the interrupt
Node string
// Value is the data/query provided by the interrupt
Value any
}
func (e *NodeInterrupt) E... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/state_graph.go | graph/state_graph.go | package graph
import (
"context"
"errors"
"fmt"
"slices"
"strings"
"sync"
"time"
)
// StateGraph represents a generic state-based graph with compile-time type safety.
// The type parameter S represents the state type, which is typically a struct.
//
// Example usage:
//
// type MyState struct {
// Count in... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/doc.go | graph/doc.go | // Package graph provides the core graph construction and execution engine for LangGraph Go.
//
// This package implements the fundamental building blocks for creating stateful, multi-agent applications
// using directed graphs. It offers both untyped and typed interfaces for building workflows,
// with support for par... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/utils.go | graph/utils.go | package graph
import (
"context"
"encoding/json"
"fmt"
"sync"
"github.com/google/uuid"
)
// generateRunID generates a unique run ID for callbacks
func generateRunID() string {
return uuid.New().String()
}
// convertStateToMap converts a state to a map for callbacks
func convertStateToMap(state any) map[string... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/schema.go | graph/schema.go | package graph
import (
"fmt"
"maps"
"reflect"
)
// StateSchema defines the structure and update logic for the graph state with type safety.
type StateSchema[S any] interface {
// Init returns the initial state.
Init() S
// Update merges the new state into the current state.
Update(current, new S) (S, error)
}... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/graph_test.go | graph/graph_test.go | package graph_test
import (
"context"
"errors"
"fmt"
"os"
"testing"
"github.com/smallnest/langgraphgo/graph"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/llms/openai"
)
func ExampleStateGraph() {
// Skip if no OpenAI API key is available
if os.Getenv("OPENAI_API_KEY") == "" {
fmt.Println... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/builtin_listeners.go | graph/builtin_listeners.go | package graph
import (
"context"
"fmt"
"io"
"log"
"maps"
"os"
"sync"
"time"
)
// ProgressListener provides progress tracking with customizable output
type ProgressListener struct {
writer io.Writer
nodeSteps map[string]string
mutex sync.RWMutex
showTiming bool
showDetails bool
prefix ... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/subgraph.go | graph/subgraph.go | package graph
import (
"context"
"fmt"
)
// Subgraph represents a nested graph that can be used as a node
type Subgraph[S any] struct {
name string
graph *StateGraph[S]
runnable *StateRunnable[S]
}
// NewSubgraph creates a new generic subgraph
func NewSubgraph[S any](name string, graph *StateGraph[S]) (*... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/parallel_test.go | graph/parallel_test.go | package graph_test
import (
"context"
"fmt"
"sync/atomic"
"testing"
"time"
"github.com/smallnest/langgraphgo/graph"
)
func TestParallelNodes(t *testing.T) {
t.Parallel()
g := graph.NewStateGraph[map[string]any]()
// Track execution order
var counter int32
// Add parallel nodes
parallelFuncs := make(ma... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/tracing_test.go | graph/tracing_test.go | package graph_test
import (
"context"
"errors"
"fmt"
"strings"
"testing"
"github.com/smallnest/langgraphgo/graph"
)
func TestTracer_StartEndSpan(t *testing.T) {
t.Parallel()
tracer := graph.NewTracer()
ctx := context.Background()
// Test starting a span
span := tracer.StartSpan(ctx, graph.TraceEventNode... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/update_state_test.go | graph/update_state_test.go | package graph
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestUpdateState(t *testing.T) {
g := NewCheckpointableStateGraph[map[string]any]()
// Setup schema with reducer
schema := NewMapSchema()
schema.RegisterReducer("count", func(curr, new any) (any, error) {
if curr == nil {... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/context.go | graph/context.go | package graph
import "context"
type resumeValueKey struct{}
// WithResumeValue adds a resume value to the context.
// This value will be returned by Interrupt() when re-executing a node.
func WithResumeValue(ctx context.Context, value any) context.Context {
return context.WithValue(ctx, resumeValueKey{}, value)
}
... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/edge_cases_test.go | graph/edge_cases_test.go | package graph_test
import (
"context"
"errors"
"fmt"
"strings"
"sync"
"sync/atomic"
"testing"
"time"
"github.com/smallnest/langgraphgo/graph"
"github.com/tmc/langchaingo/llms"
)
// TestEmptyGraph tests behavior with empty graphs
func TestEmptyGraph(t *testing.T) {
t.Parallel()
tests := []struct {
name... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/resume_test.go | graph/resume_test.go | package graph
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGraphResume(t *testing.T) {
g := NewStateGraph[map[string]any]()
g.AddNode("A", "A", func(ctx context.Context, state map[string]any) (map[string]any, error) {
state["value"] = state["value"].(string) + "A"
return stat... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/add_messages.go | graph/add_messages.go | package graph
import (
"fmt"
"reflect"
"github.com/tmc/langchaingo/llms"
)
// MessageWithID is an interface that allows messages to have an ID for deduplication/upsert.
// Since langchaingo's MessageContent doesn't have an ID field, we can wrap it or use a custom struct.
// For now, we'll check if the message imp... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/subgraph_test.go | graph/subgraph_test.go | package graph
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSubgraph(t *testing.T) {
// 1. Define Child Graph
child := NewStateGraph[map[string]any]()
child.AddNode("child_A", "child_A", func(ctx context.Context, state map[string]any) (map[string]any, error) {
state["child_visi... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/listeners.go | graph/listeners.go | package graph
import (
"context"
"fmt"
"sync"
"time"
)
// NodeEvent represents different types of node events
type NodeEvent string
const (
// NodeEventStart indicates a node has started execution
NodeEventStart NodeEvent = "start"
// NodeEventProgress indicates progress during node execution
NodeEventProgr... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/checkpointing.go | graph/checkpointing.go | package graph
import (
"context"
"fmt"
"time"
"github.com/google/uuid"
"github.com/smallnest/langgraphgo/store"
"github.com/smallnest/langgraphgo/store/file"
"github.com/smallnest/langgraphgo/store/memory"
)
// Checkpoint is an alias for store.Checkpoint
type Checkpoint = store.Checkpoint
// CheckpointStore ... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/graph/visualization_test.go | graph/visualization_test.go | package graph
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestVisualization(t *testing.T) {
g := NewStateGraph[map[string]any]()
g.AddNode("A", "A", func(ctx context.Context, state map[string]any) (map[string]any, error) { return state, nil })
g.AddNode("B", "B", func(ctx context.C... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/checkpoint.go | store/checkpoint.go | package store
import (
"context"
"time"
)
// Checkpoint represents a saved state at a specific point in execution
type Checkpoint struct {
ID string `json:"id"`
NodeName string `json:"node_name"`
State any `json:"state"`
Metadata map[string]any `json:"metadata"`
Timestam... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/doc.go | store/doc.go | // Package store provides storage implementations for persisting LangGraph checkpoints and state.
//
// Store implementations allow graph executions to be persisted across different runs,
// processes, or even different machines. This enables features like resuming
// interrupted workflows, debugging complex executions... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/type_registry.go | store/type_registry.go | package store
import (
"encoding/json"
"fmt"
"reflect"
"sync"
)
// TypeRegistry manages type information for generic state serialization/deserialization.
// It allows state types to register themselves for proper checkpointing.
type TypeRegistry struct {
mu sync.RWMutex
typeNameToType map[stri... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/type_registry_test.go | store/type_registry_test.go | package store
import (
"encoding/json"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
// Test types for type registry
type TestState struct {
Name string `json:"name"`
Count int `json:"count"`
}
type AnotherState struct {
ID int `json:"id"`
Value string `json:"value"`
}
type PointerSt... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/sqlite/sqlite_test.go | store/sqlite/sqlite_test.go | package sqlite
import (
"context"
"testing"
"time"
"github.com/smallnest/langgraphgo/graph"
"github.com/stretchr/testify/assert"
)
func TestSqliteCheckpointStore(t *testing.T) {
// Use in-memory database
store, err := NewSqliteCheckpointStore(SqliteOptions{
Path: ":memory:",
})
assert.NoError(t, err)
def... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/sqlite/sqlite.go | store/sqlite/sqlite.go | package sqlite
import (
"context"
"database/sql"
"encoding/json"
"fmt"
"sort"
_ "github.com/mattn/go-sqlite3"
"github.com/smallnest/langgraphgo/graph"
"github.com/smallnest/langgraphgo/store"
)
// SqliteCheckpointStore implements graph.CheckpointStore using SQLite
type SqliteCheckpointStore struct {
db ... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/sqlite/doc.go | store/sqlite/doc.go | // Package sqlite provides SQLite-backed storage for LangGraph Go checkpoints and state.
//
// This package implements file-based checkpoint storage using SQLite, perfect for
// applications requiring a lightweight, serverless database solution with ACID
// compliance and zero external dependencies.
//
// # Key Feature... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/memory/doc.go | store/memory/doc.go | // Package memory provides in-memory checkpoint storage implementation.
package memory
| go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/memory/memory.go | store/memory/memory.go | package memory
import (
"context"
"fmt"
"sort"
"sync"
"github.com/smallnest/langgraphgo/store"
)
// MemoryCheckpointStore provides in-memory checkpoint storage
type MemoryCheckpointStore struct {
checkpoints map[string]*store.Checkpoint // id -> checkpoint
threadIndex map[string][]string // thr... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/memory/memory_test.go | store/memory/memory_test.go | package memory
import (
"context"
"fmt"
"testing"
"time"
"github.com/smallnest/langgraphgo/store"
)
func TestMemoryCheckpointStore_New(t *testing.T) {
t.Parallel()
ms := NewMemoryCheckpointStore()
if ms == nil {
t.Fatal("Store should not be nil")
}
// Verify it implements the interface
var _ store.Ch... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/file/file.go | store/file/file.go | package file
import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
"sort"
"sync"
"github.com/smallnest/langgraphgo/store"
)
// FileCheckpointStore provides file-based checkpoint storage
type FileCheckpointStore struct {
path string
mutex sync.RWMutex
}
// threadIndex represents the in-memory inde... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/file/doc.go | store/file/doc.go | // Package file provides file-based checkpoint storage implementation.
package file
| go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/file/file_test.go | store/file/file_test.go | package file
import (
"context"
"fmt"
"os"
"path/filepath"
"testing"
"time"
"github.com/smallnest/langgraphgo/store"
)
func TestFileCheckpointStore_New(t *testing.T) {
t.Parallel()
t.Run("creates directory if missing", func(t *testing.T) {
t.Parallel()
tempDir := t.TempDir()
checkpointPath := filepat... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/postgres/postgres.go | store/postgres/postgres.go | package postgres
import (
"context"
"encoding/json"
"fmt"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/smallnest/langgraphgo/graph"
)
// DBPool defines the interface for database connection pool
type DBPool interface {
Exec(ctx context.Context, sql ... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/postgres/doc.go | store/postgres/doc.go | // Package postgres provides PostgreSQL-backed storage for LangGraph Go checkpoints and state.
//
// This package implements durable checkpoint storage using PostgreSQL, allowing graph
// executions to be persisted and resumed across different runs and processes. It's
// designed for production use with robust error ha... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/postgres/postgres_test.go | store/postgres/postgres_test.go | package postgres
import (
"context"
"encoding/json"
"errors"
"regexp"
"testing"
"time"
"github.com/jackc/pgx/v5"
"github.com/pashagolub/pgxmock/v3"
"github.com/smallnest/langgraphgo/graph"
"github.com/stretchr/testify/assert"
)
func TestPostgresCheckpointStore_Save(t *testing.T) {
mock, err := pgxmock.New... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/redis/redis_test.go | store/redis/redis_test.go | package redis
import (
"context"
"testing"
"time"
"github.com/alicebob/miniredis/v2"
"github.com/smallnest/langgraphgo/graph"
"github.com/stretchr/testify/assert"
)
func TestRedisCheckpointStore(t *testing.T) {
// Start miniredis
mr, err := miniredis.Run()
assert.NoError(t, err)
defer mr.Close()
// Creat... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/redis/doc.go | store/redis/doc.go | // Package redis provides Redis-backed storage for LangGraph Go checkpoints and state.
//
// This package implements fast, in-memory checkpoint storage using Redis, ideal for
// scenarios requiring low-latency access to checkpoints and supporting distributed
// graph executions across multiple processes or servers.
//
... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/store/redis/redis.go | store/redis/redis.go | package redis
import (
"context"
"encoding/json"
"errors"
"fmt"
"time"
"github.com/redis/go-redis/v9"
"github.com/smallnest/langgraphgo/graph"
)
// RedisCheckpointStore implements graph.CheckpointStore using Redis
type RedisCheckpointStore struct {
client *redis.Client
prefix string
ttl time.Duration
}
... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/planning_agent_test.go | prebuilt/planning_agent_test.go | package prebuilt
import (
"context"
"testing"
"github.com/smallnest/langgraphgo/graph"
"github.com/stretchr/testify/assert"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/tools"
)
// MockPlanningLLM is a mock LLM that returns a workflow plan
type MockPlanningLLM struct {
planJSON string
r... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/create_agent_test.go | prebuilt/create_agent_test.go | package prebuilt
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/tools"
)
func TestCreateAgentMap(t *testing.T) {
mockLLM := &MockLLM{}
inputTools := []tools.Tool{}
systemMessage := "You are a helpful assistant."
t.Run("Basic A... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/supervisor.go | prebuilt/supervisor.go | package prebuilt
import (
"context"
"encoding/json"
"fmt"
"strings"
"github.com/smallnest/langgraphgo/graph"
"github.com/tmc/langchaingo/llms"
)
// CreateSupervisorMap creates a supervisor graph with map[string]any state
func CreateSupervisorMap(model llms.Model, members map[string]*graph.StateRunnable[map[str... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/tree_of_thoughts_test.go | prebuilt/tree_of_thoughts_test.go | package prebuilt
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
// Mock implementations for testing
type MockThoughtState struct {
hash string
isValid bool
isGoal bool
desc string
}
func (m *MockThoughtState) IsValid() bool { return m.isValid }
func (m *MockThoughtState)... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/react_agent_test.go | prebuilt/react_agent_test.go | package prebuilt
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/tools"
)
// WeatherTool implements tools.Tool for testing
type WeatherTool struct {
currentTemp int
}
func NewWeatherTool(temp int) *WeatherTool {
return &We... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/pev_agent_test.go | prebuilt/pev_agent_test.go | package prebuilt
import (
"testing"
"github.com/tmc/langchaingo/tools"
)
func TestCreatePEVAgentMap(t *testing.T) {
mockLLM := &PEVMockLLM{
responses: []string{
"1. Step",
`{"is_successful": true, "reasoning": "Ok"}`,
"Final",
},
}
config := PEVAgentConfig{
Model: mockLLM,
Tools: []to... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/generic_agents_test.go | prebuilt/generic_agents_test.go | package prebuilt
import (
"context"
"testing"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/tools"
)
// Mock Reflection LLM
type MockReflectionLLM struct {
responses []string
callCount int
}
func (m *MockReflectionLLM) GenerateContent(ctx context.Context, messages []llms.MessageContent, option... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/tree_of_thoughts.go | prebuilt/tree_of_thoughts.go | package prebuilt
import (
"context"
"fmt"
"github.com/smallnest/langgraphgo/graph"
)
type ThoughtState interface {
IsValid() bool
IsGoal() bool
GetDescription() string
Hash() string
}
type ThoughtGenerator interface {
Generate(ctx context.Context, current ThoughtState) ([]ThoughtState, error)
}
type Though... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/planning_agent.go | prebuilt/planning_agent.go | package prebuilt
import (
"context"
"encoding/json"
"fmt"
"regexp"
"strings"
"github.com/smallnest/langgraphgo/graph"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/tools"
)
// CreatePlanningAgentMap creates a planning agent with map[string]any state
func CreatePlanningAgentMap(model llms.Mode... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/tool_executor_test.go | prebuilt/tool_executor_test.go | package prebuilt
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/tmc/langchaingo/tools"
)
// MockTool implements tools.Tool for testing
type MockTool struct {
name string
}
func (t *MockTool) Name() string {
return t.name
}
func (t *MockTool) Description() string {
return "A mo... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/tool_node_test.go | prebuilt/tool_node_test.go | package prebuilt
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/tools"
)
func TestToolNodeMap(t *testing.T) {
mockTool := &MockTool{name: "test-tool"}
executor := NewToolExecutor([]tools.Tool{mockTool})
node := ToolNodeMap(execu... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/pev_agent.go | prebuilt/pev_agent.go | package prebuilt
import (
"context"
"encoding/json"
"fmt"
"strings"
"github.com/smallnest/langgraphgo/graph"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/tools"
)
// PEVAgentConfig configures the PEV (Plan, Execute, Verify) agent
type PEVAgentConfig struct {
Model llms.Model
To... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/doc.go | prebuilt/doc.go | // Package prebuilt provides ready-to-use agent implementations for common AI patterns.
//
// This package offers a collection of pre-built agents that implement various reasoning
// and execution patterns, from simple tool-using agents to complex multi-agent systems.
// Each agent is implemented using the core graph p... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/chat_agent_test.go | prebuilt/chat_agent_test.go | package prebuilt
import (
"context"
"strings"
"testing"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/tools"
)
// MockModel is a simple mock for llms.Model
type MockModel struct {
responses []string
callCount int
}
func (m *MockModel) GenerateContent(ctx context.Context, messages []llms.Messa... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/planning_agent_example_test.go | prebuilt/planning_agent_example_test.go | package prebuilt_test
import (
"context"
"fmt"
"github.com/smallnest/langgraphgo/graph"
"github.com/tmc/langchaingo/llms"
)
// Example demonstrates how to use CreatePlanningAgentMap to build
// a dynamic workflow based on user requests
func Example_planningAgent() {
// Step 1: Define your custom nodes that can ... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/reflection_agent.go | prebuilt/reflection_agent.go | package prebuilt
import (
"context"
"fmt"
"strings"
"github.com/smallnest/langgraphgo/graph"
"github.com/tmc/langchaingo/llms"
)
// ReflectionAgentConfig configures the reflection agent
type ReflectionAgentConfig struct {
Model llms.Model
ReflectionModel llms.Model
MaxIterations int
SystemMes... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/tool_node.go | prebuilt/tool_node.go | package prebuilt
import (
"context"
"encoding/json"
"fmt"
"github.com/tmc/langchaingo/llms"
)
// ToolNodeMap is a reusable node that executes tool calls from the last AI message
// for map[string]any state.
func ToolNodeMap(executor *ToolExecutor) func(context.Context, map[string]any) (map[string]any, error) {
... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/create_agent.go | prebuilt/create_agent.go | package prebuilt
import (
"context"
"encoding/json"
"fmt"
"strings"
"github.com/smallnest/goskills"
adapter "github.com/smallnest/langgraphgo/adapter/goskills"
"github.com/smallnest/langgraphgo/graph"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/tools"
)
// CreateAgentOptions contains optio... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/react_agent.go | prebuilt/react_agent.go | package prebuilt
import (
"context"
"encoding/json"
"fmt"
"github.com/smallnest/langgraphgo/graph"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/tools"
)
// CreateReactAgentMap creates a new ReAct agent graph with map[string]any state
//
// Deprecated: Use CreateAgentMap instead, which now incl... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/agent_states.go | prebuilt/agent_states.go | package prebuilt
import (
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/tools"
)
// AgentState represents the general agent state.
// This is the default state type for generic agents.
type AgentState struct {
// Messages contains the conversation history
Messages []llms.MessageContent
// ExtraT... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/tool_executor.go | prebuilt/tool_executor.go | package prebuilt
import (
"context"
"fmt"
"github.com/tmc/langchaingo/tools"
)
// ToolWithSchema is an optional interface that tools can implement to provide their parameter schema
type ToolWithSchema interface {
Schema() map[string]any
}
// ToolInvocation represents a request to execute a tool
type ToolInvocat... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/chat_agent.go | prebuilt/chat_agent.go | package prebuilt
import (
"context"
"fmt"
"io"
"github.com/google/uuid"
"github.com/smallnest/langgraphgo/graph"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/tools"
)
// ChatAgent represents a session with a user and can handle multi-turn conversations.
type ChatAgent struct {
// The underly... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/reflection_agent_test.go | prebuilt/reflection_agent_test.go | package prebuilt
import (
"testing"
)
func TestCreateReflectionAgentMap(t *testing.T) {
mockLLM := &MockReflectionLLM{
responses: []string{
"Initial response",
"**Strengths:** Good. **Weaknesses:** None.",
},
}
config := ReflectionAgentConfig{Model: mockLLM, MaxIterations: 2}
agent, err := CreateReflec... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/supervisor_test.go | prebuilt/supervisor_test.go | package prebuilt
import (
"context"
"errors"
"testing"
"github.com/smallnest/langgraphgo/graph"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tmc/langchaingo/llms"
)
// SupervisorMockLLM for supervisor testing
type SupervisorMockLLM struct {
responses []llms.Content... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/chat_agent_example_test.go | prebuilt/chat_agent_example_test.go | package prebuilt_test
import (
"context"
"fmt"
"os"
"github.com/smallnest/langgraphgo/prebuilt"
"github.com/tmc/langchaingo/llms/openai"
)
// Example demonstrating multi-turn conversation with ChatAgent
func ExampleChatAgent() {
// Check if API key is available
apiKey := os.Getenv("OPENAI_API_KEY")
if apiKey... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/reflection_agent_example_test.go | prebuilt/reflection_agent_example_test.go | package prebuilt_test
import (
"context"
"fmt"
"log"
"github.com/smallnest/langgraphgo/prebuilt"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/llms/openai"
)
func ExampleCreateReflectionAgent() {
// Create LLM
model, err := openai.New()
if err != nil {
log.Fatal(err)
}
// Configure refl... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/mock_errors.go | prebuilt/mock_errors.go | package prebuilt
import (
"context"
"fmt"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/tools"
)
// Enforce that MockToolError implements tools.Tool
var _ tools.Tool = (*MockToolError)(nil)
// MockLLMError for testing GenerateContent error
type MockLLMError struct{}
func (m *MockLLMError) Gener... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/prebuilt/mock_errors_test.go | prebuilt/mock_errors_test.go | package prebuilt
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/tmc/langchaingo/llms"
)
func TestMockLLMError(t *testing.T) {
mock := &MockLLMError{}
t.Run("GenerateContent returns error", func(t *testing.T) {
ctx := context.Background()
messages := []llms.MessageContent{
... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/memory/buffer.go | memory/buffer.go | package memory
import (
"context"
"sync"
)
// BufferMemory is a simple buffer-based memory implementation
// Similar to LangChain's ConversationBufferMemory
// Combines sliding window with optional summarization
type BufferMemory struct {
messages []*Message
maxMessages int // 0 = unlimited
maxTokens ... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/memory/hierarchical.go | memory/hierarchical.go | package memory
import (
"context"
"sync"
"time"
)
// HierarchicalMemory organizes messages in layers based on importance and recency
// Pros: Balances recent context with important historical information
// Cons: More complex management, requires importance scoring
type HierarchicalMemory struct {
// Layer 1: Rec... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/memory/langchain_adapter.go | memory/langchain_adapter.go | package memory
import (
"context"
"github.com/tmc/langchaingo/llms"
langchainmemory "github.com/tmc/langchaingo/memory"
"github.com/tmc/langchaingo/schema"
)
// ChatMemory is the interface for conversation memory management in langgraphgo
type ChatMemory interface {
// SaveContext saves the context from this co... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/memory/retrieval.go | memory/retrieval.go | package memory
import (
"context"
"fmt"
"math"
"sort"
"sync"
)
// RetrievalMemory uses vector embeddings to retrieve relevant past messages
// Pros: Only fetches contextually relevant history, efficient token usage
// Cons: Requires embedding model, may miss chronologically important context
type RetrievalMemory... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/memory/os_like.go | memory/os_like.go | package memory
import (
"container/heap"
"context"
"sync"
"time"
)
// OSLikeMemory implements OS-inspired memory management with paging and eviction
// Pros: Sophisticated lifecycle management, optimal memory usage
// Cons: Complex implementation, overhead of management
type OSLikeMemory struct {
// Active memor... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/memory/strategy.go | memory/strategy.go | package memory
import (
"context"
"fmt"
"sync/atomic"
"time"
)
// Message represents a single conversation message
type Message struct {
ID string // Unique identifier
Role string // "user", "assistant", "system"
Content string // Message content
Timestamp time.Time ... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/memory/doc.go | memory/doc.go | // Package memory provides various memory management strategies for conversational AI applications.
//
// This package implements multiple approaches to managing conversation history and context,
// from simple buffers to sophisticated OS-inspired memory management with paging and eviction.
// It's designed to help mai... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/memory/sequential.go | memory/sequential.go | package memory
import (
"context"
"sync"
)
// SequentialMemory implements the "Keep-It-All" strategy
// Stores complete conversation history in chronological order
// Pros: Perfect recall of all interactions
// Cons: Token costs grow unbounded with conversation length
type SequentialMemory struct {
messages []*Mes... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/memory/sliding_window.go | memory/sliding_window.go | package memory
import (
"context"
"sync"
)
// SlidingWindowMemory maintains only the most recent N messages
// Pros: Bounded context size, prevents unbounded token growth
// Cons: Loses older context, may forget important earlier information
type SlidingWindowMemory struct {
messages []*Message
windowSize int /... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/memory/graph_based.go | memory/graph_based.go | package memory
import (
"context"
"fmt"
"sync"
)
// GraphNode represents a node in the conversation graph
type GraphNode struct {
Message *Message
Connections []string // IDs of connected messages
Weight float64 // Importance/relevance weight
}
// GraphBasedMemory models conversations as knowledge gr... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/memory/summarization.go | memory/summarization.go | package memory
import (
"context"
"fmt"
"strings"
"sync"
)
// SummarizationMemory condenses older messages into summaries
// Pros: Maintains historical context while reducing token count
// Cons: May lose specific details in summarization
type SummarizationMemory struct {
recentMessages []*Message // Recent me... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
smallnest/langgraphgo | https://github.com/smallnest/langgraphgo/blob/600df7fe3e6254f2329f606732feaecfbd52d9f2/memory/compression.go | memory/compression.go | package memory
import (
"context"
"fmt"
"sync"
"time"
)
// CompressionMemory periodically compresses and consolidates memory
// Pros: Maintains long-term context efficiently, removes redundancy
// Cons: Compression requires LLM calls, may lose granular details
type CompressionMemory struct {
messages [... | go | MIT | 600df7fe3e6254f2329f606732feaecfbd52d9f2 | 2026-01-07T10:38:05.929544Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.