examples

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2025 License: MIT Imports: 13 Imported by: 0

README ΒΆ

πŸš€ GoLangGraph Examples

This directory contains comprehensive examples showcasing the full functionality of GoLangGraph with different complexity levels. Each example is designed to be runnable locally using Ollama with the Gemma3 1B model.

πŸš€ Quick Start

Each example is completely independent with its own go.mod file and simple structure:

examples/
β”œβ”€β”€ 01-basic-chat/
β”‚   β”œβ”€β”€ main.go          # Complete chat agent implementation
β”‚   β”œβ”€β”€ go.mod           # Independent module
β”‚   └── README.md        # Detailed documentation
β”œβ”€β”€ 02-react-agent/
β”‚   β”œβ”€β”€ main.go          # Entry point and session management
β”‚   β”œβ”€β”€ agent.go         # ReAct agent implementation
β”‚   β”œβ”€β”€ tools.go         # Tool implementations
β”‚   β”œβ”€β”€ go.mod           # Independent module
β”‚   └── README.md
Prerequisites
  1. Install Ollama: Download from ollama.com

  2. Start Ollama: ollama serve

  3. Pull Models:

    ollama pull gemma3:1b                    # For basic examples
    ollama pull orieg/gemma3-tools:1b        # For tool-enabled examples (recommended)
    
Running Examples

Navigate to any example directory and run:

cd examples/01-basic-chat
go run main.go

Or compile and run:

go build -o example-name main.go  # For single-file examples
go build -o example-name *.go     # For multi-file examples
./example-name

🎯 Examples Overview

πŸ€– 01-basic-chat - Basic Chat Agent

Complexity: Beginner | Runtime: ~2 minutes

Learn the fundamentals of creating a simple chat agent.

Features:

  • βœ… Basic agent creation and configuration
  • βœ… Simple conversation handling
  • βœ… Ollama integration
  • βœ… Performance monitoring
  • βœ… Interactive commands

What you'll learn:

  • Agent initialization and configuration
  • LLM provider integration
  • Basic conversation flow
  • Error handling and monitoring
cd examples/01-basic-chat
go run *.go

🧠 02-react-agent - ReAct Agent with Tools

Complexity: Intermediate | Runtime: ~5 minutes

Explore the ReAct (Reasoning and Acting) pattern with tool integration.

Features:

  • βœ… ReAct pattern implementation
  • βœ… Tool integration (calculator, web search, file ops)
  • βœ… Multi-step problem solving
  • βœ… Advanced mathematical functions
  • βœ… Statistical analysis tools

What you'll learn:

  • ReAct reasoning pattern
  • Tool creation and integration
  • Complex problem decomposition
  • Advanced agent capabilities
cd examples/02-react-agent
go run *.go

πŸ‘₯ 03-multi-agent - Multi-Agent System

Complexity: Advanced | Runtime: ~8 minutes

Discover how multiple specialized agents work together.

Features:

  • βœ… Multiple specialized agents
  • βœ… Task coordination and workflow
  • βœ… Agent communication patterns
  • βœ… Parallel and sequential execution
  • βœ… Workflow orchestration

What you'll learn:

  • Multi-agent architecture
  • Task decomposition and delegation
  • Agent coordination strategies
  • Workflow design patterns
cd examples/03-multi-agent
go run *.go

πŸ“š 04-rag-system - RAG Implementation

Complexity: Advanced | Runtime: ~10 minutes

Build a Retrieval-Augmented Generation system.

Features:

  • βœ… Document ingestion and vectorization
  • βœ… Semantic search and retrieval
  • βœ… Context-aware generation
  • βœ… Knowledge base management
  • βœ… Vector database integration

What you'll learn:

  • RAG architecture and implementation
  • Document processing and embedding
  • Vector search and similarity
  • Context management strategies
cd examples/04-rag-system
go run *.go

🌊 05-streaming - Real-time Streaming

Complexity: Intermediate | Runtime: ~5 minutes

Implement real-time streaming responses.

Features:

  • βœ… Real-time response streaming
  • βœ… WebSocket integration
  • βœ… Progressive output display
  • βœ… Cancellation and timeout handling
  • βœ… Performance optimization

What you'll learn:

  • Streaming response implementation
  • Real-time communication patterns
  • Performance optimization techniques
  • User experience enhancement
cd examples/05-streaming
go run *.go

πŸ’Ύ 06-persistence - Data Persistence

Complexity: Advanced | Runtime: ~10 minutes

Explore data persistence and memory management.

Features:

  • βœ… Conversation history storage
  • βœ… Agent memory management
  • βœ… Database integration
  • βœ… Session management
  • βœ… Data retrieval and search

What you'll learn:

  • Persistence strategies
  • Database integration patterns
  • Memory management techniques
  • Session handling
cd examples/06-persistence
# Install SQLite dependency (first time only)
go mod init persistence-example
go get github.com/mattn/go-sqlite3
# Run the example
go run *.go

πŸ”§ 07-tools-integration - Advanced Tools

Complexity: Advanced | Runtime: ~8 minutes

Master advanced tool integration and custom tool development.

Features:

  • βœ… Custom tool development
  • βœ… External API integration
  • βœ… Tool chaining and composition
  • βœ… Security and validation
  • βœ… Performance optimization

What you'll learn:

  • Advanced tool development
  • API integration patterns
  • Security best practices
  • Tool ecosystem design
cd examples/07-tools-integration
go run main.go

🏭 08-production-ready - Production Deployment

Complexity: Expert | Runtime: ~15 minutes

Build production-ready applications with full enterprise features.

Features:

  • βœ… Production configuration
  • βœ… Monitoring and observability
  • βœ… Error handling and recovery
  • βœ… Security and authentication
  • βœ… Scalability patterns
  • βœ… Docker deployment

What you'll learn:

  • Production deployment strategies
  • Monitoring and observability
  • Security implementation
  • Scalability patterns
cd examples/08-production-ready
go run main.go
# Or run with config file:
# GOLANGGRAPH_SERVER_PORT=9090 go run main.go

πŸ”„ 09-workflow-graph - Complex Workflow Graph

Complexity: Expert | Runtime: ~12 minutes

Master advanced workflow orchestration with graph-based architecture, nodes, edges, and ReAct agent integration.

Features:

  • βœ… Graph-based workflow architecture
  • βœ… Multi-node workflows with conditional edges
  • βœ… ReAct agent integration with tools
  • βœ… Dynamic routing and state management
  • βœ… Parallel execution paths
  • βœ… Result aggregation and synthesis

What you'll learn:

  • Graph-based workflow design
  • ReAct pattern implementation
  • Conditional routing and state management
  • Advanced workflow orchestration
  • Tool integration within workflows
cd examples/09-workflow-graph
go run main.go

πŸŽ“ Learning Path

Beginner Path
  1. 01-basic-chat - Start here to understand fundamentals
  2. 05-streaming - Add real-time capabilities
  3. 06-persistence - Learn data management
Intermediate Path
  1. 02-react-agent - Master tool integration
  2. 04-rag-system - Implement knowledge systems
  3. 07-tools-integration - Advanced tool development
Advanced Path
  1. 03-multi-agent - Multi-agent coordination
  2. 09-workflow-graph - Complex workflow orchestration
  3. 08-production-ready - Production deployment
  4. Custom Implementation - Build your own system

πŸ› οΈ Common Configuration

All examples use consistent configuration patterns:

Model Configuration
// Standard configuration
ollamaConfig := &llm.ProviderConfig{
    Type:        "ollama",
    Endpoint:    "http://localhost:11434",
    Model:       "gemma3:1b",
    Temperature: 0.7,
    MaxTokens:   500,
    Timeout:     30 * time.Second,
}

// Tool-enabled configuration (recommended)
ollamaConfig := &llm.ProviderConfig{
    Type:        "ollama",
    Endpoint:    "http://localhost:11434",
    Model:       "orieg/gemma3-tools:1b",  // Better tool integration
    Temperature: 0.7,
    MaxTokens:   500,
    Timeout:     30 * time.Second,
}
Agent Types
  • Chat Agent: Simple conversational agents
  • ReAct Agent: Reasoning and acting with tools
  • Custom Agent: Specialized implementations
Tool Integration

All examples demonstrate different aspects of tool integration:

  • Built-in tools (calculator, file operations, web search)
  • Custom tools (domain-specific functionality)
  • Tool chaining and composition

πŸ”§ Troubleshooting

Common Issues
  1. Ollama not running:

    ollama serve
    
  2. Model not found:

    ollama pull gemma3:1b
    ollama pull orieg/gemma3-tools:1b
    
  3. Port conflicts:

    # Check if Ollama is running on port 11434
    curl http://localhost:11434/api/tags
    
  4. Memory issues:

    • Use smaller models for limited resources
    • Reduce MaxTokens in configuration
    • Implement proper timeout handling
  5. Compilation errors:

    # For basic-chat example with multiple files
    go run *.go
    
    # For persistence example requiring SQLite
    go mod init persistence-example
    go get github.com/mattn/go-sqlite3
    go run *.go
    
  6. Missing dependencies:

    # If you get "no required module provides package" errors
    go mod init example-name
    go get [missing-package]
    
Performance Tips
  • Use orieg/gemma3-tools:1b for better tool integration
  • Set appropriate timeouts for your use case
  • Monitor memory usage with multiple agents
  • Implement proper error handling and retries

πŸ“Š Performance Benchmarks

Example Avg Response Time Memory Usage Complexity
01-basic-chat 2-4s ~100MB ⭐
02-react-agent 3-8s ~150MB ⭐⭐
03-multi-agent 5-15s ~300MB ⭐⭐⭐
04-rag-system 4-12s ~200MB ⭐⭐⭐
05-streaming 1-3s ~120MB ⭐⭐
06-persistence 3-8s ~180MB ⭐⭐⭐
07-tools-integration 4-10s ~160MB ⭐⭐⭐
08-production-ready 3-12s ~250MB ⭐⭐⭐⭐
09-workflow-graph 5-15s ~350MB ⭐⭐⭐⭐

Benchmarks based on Gemma3 1B model on standard hardware

🀝 Contributing

Want to contribute more examples? Please:

  1. Follow the established structure and patterns
  2. Include comprehensive documentation
  3. Ensure examples are runnable with Ollama
  4. Add appropriate error handling
  5. Include performance considerations

πŸ“š Additional Resources

🎯 Next Steps

After completing these examples, you'll be ready to:

  1. Build Custom Applications - Create your own AI agent systems
  2. Integrate with Existing Systems - Add AI capabilities to current projects
  3. Scale to Production - Deploy robust, production-ready solutions
  4. Contribute to GoLangGraph - Help improve the framework

Happy coding! πŸš€

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func AIDevTeamExample ΒΆ

func AIDevTeamExample()

Example: AI-Powered Development Team

func CodeReviewExample ΒΆ

func CodeReviewExample()

Example: Code Review System

func ContentCreationExample ΒΆ

func ContentCreationExample()

Example: Content Creation Workflow

func CreateMultiAgentSystem ΒΆ

func CreateMultiAgentSystem() *agent.MultiAgentCoordinator

Example 3: Multi-Agent System - Just 5 lines!

func CreateProductionPostgresConfig ΒΆ

func CreateProductionPostgresConfig(host, database, username, password string) *persistence.DatabaseConfig

CreateProductionPostgresConfig creates a production-ready PostgreSQL configuration

func CreateRAGPostgresConfig ΒΆ

func CreateRAGPostgresConfig(host, database, username, password string, embeddingDim int) *persistence.DatabaseConfig

CreateRAGPostgresConfig creates a PostgreSQL configuration optimized for RAG

func CreateReActAgent ΒΆ

func CreateReActAgent() *agent.Agent

Example 2: ReAct Agent with Tools - Just 4 lines!

func CreateRedisConfig ΒΆ

func CreateRedisConfig(host, password string, port int) *persistence.DatabaseConfig

CreateRedisConfig creates a Redis configuration for caching

func CreateSimpleChatAgent ΒΆ

func CreateSimpleChatAgent() *agent.Agent

Example 1: Simple Chat Agent - Just 3 lines!

func CustomerSupportExample ΒΆ

func CustomerSupportExample()

Example: Customer Support System

func DataAnalysisExample ΒΆ

func DataAnalysisExample()

Example: Data Analysis Pipeline

func EnterpriseExample ΒΆ

func EnterpriseExample()

Example: Enterprise Multi-Agent System

func ExampleDatabaseSetup ΒΆ

func ExampleDatabaseSetup()

func ProductionDeploymentExample ΒΆ

func ProductionDeploymentExample()

Example: One-Line Production Deployment

func QuickChat ΒΆ

func QuickChat() *agent.Agent

OneLiner: Chat Agent

func QuickReAct ΒΆ

func QuickReAct() *agent.Agent

OneLiner: ReAct Agent

func QuickStartDemo ΒΆ

func QuickStartDemo()

func RunAllExamples ΒΆ

func RunAllExamples()

Run all examples

func RunDatabasePersistenceDemo ΒΆ

func RunDatabasePersistenceDemo()

func RunUltimateMinimalDemo ΒΆ

func RunUltimateMinimalDemo()

func SimpleAgentDemo ΒΆ

func SimpleAgentDemo()

func UltimateMinimalDemo ΒΆ

func UltimateMinimalDemo()

Types ΒΆ

type MockProvider ΒΆ

type MockProvider struct{}

MockProvider for demonstration

func (*MockProvider) Close ΒΆ

func (m *MockProvider) Close() error

func (*MockProvider) Complete ΒΆ

func (*MockProvider) CompleteStream ΒΆ

func (m *MockProvider) CompleteStream(ctx context.Context, req llm.CompletionRequest, callback llm.StreamCallback) error

func (*MockProvider) CompleteStreamWithMode ΒΆ

func (m *MockProvider) CompleteStreamWithMode(ctx context.Context, req llm.CompletionRequest, callback llm.StreamCallback, mode llm.StreamMode) error

func (*MockProvider) CompleteWithMode ΒΆ

func (m *MockProvider) CompleteWithMode(ctx context.Context, req llm.CompletionRequest, mode llm.StreamMode) (*llm.CompletionResponse, error)

func (*MockProvider) GetConfig ΒΆ

func (m *MockProvider) GetConfig() map[string]interface{}

func (*MockProvider) GetModels ΒΆ

func (m *MockProvider) GetModels(ctx context.Context) ([]string, error)

func (*MockProvider) GetName ΒΆ

func (m *MockProvider) GetName() string

func (*MockProvider) GetStreamingConfig ΒΆ

func (m *MockProvider) GetStreamingConfig() *llm.StreamingConfig

func (*MockProvider) IsHealthy ΒΆ

func (m *MockProvider) IsHealthy(ctx context.Context) error

func (*MockProvider) SetConfig ΒΆ

func (m *MockProvider) SetConfig(config map[string]interface{}) error

func (*MockProvider) SetStreamingConfig ΒΆ

func (m *MockProvider) SetStreamingConfig(config *llm.StreamingConfig) error

func (*MockProvider) SupportsStreaming ΒΆ

func (m *MockProvider) SupportsStreaming() bool

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL