LangGraphGo

repository·master·Indexed 43 days ago

https://github.com/smallnest/langgraphgo

A Go implementation of the LangGraph library for building complex, stateful, multi-agent workflows. It supports parallel execution, human-in-the-loop capabilities, advanced persistence via checkpointing, and programmatic tool calling. Includes an MCP Adapter for integrating Model Context Protocol tools and support for streaming LLM outputs.

Tokens
179.1K
Snippets
564
Records
777
Agent score
54%

What's inside LangGraphGo

  1. Overview of Memory Management Strategies

    master
    The memory package provides various strategies for managing AI agent memory, allowing developers to balance context retention with token efficiency. Strategies range from simple sequential storage to complex OS-like lifecycle management, enabling optimization for different use cases like short chats, long-term knowledge retrieval, or multi-topic conversations.
  2. Overview of Memory Management Strategies in LangGraphGo

    master

    LangGraphGo provides 9 distinct memory management strategies to optimize conversation context. Choosing the right strategy helps control LLM costs, maintain coherent context, scale to long conversations, and optimize performance for real-time applications.

    The strategies range from simple Sequential memory (keeping everything) to advanced OS-Like memory (using paging and LRU replacement).

  3. Compare RAG reranking strategies in LangGraphGo

    master

    LangGraphGo provides several reranking implementations to improve retrieval quality by re-scoring documents based on query relevance. You can choose between keyword-based, LLM-based, or third-party API-based rerankers depending on your needs for speed, cost, and accuracy.

    Reranker Options

    RerankerDescriptionProsCons
    SimpleRerankerKeyword-based rerankingFast, no API calls, always availableLimited accuracy, keyword-only
    LLMRerankerUses LLM to score documentsGood semantic understanding, no new dependenciesSlower, higher API costs
    CohereRerankerUses Cohere's Rerank APIHigh quality results, fastAPI costs, requires API key
    JinaRerankerUses Jina AI's Rerank APIHigh quality, multilingual supportAPI costs, requires API key
    CrossEncoderLocal service (via Python server)High quality, privacy-preservingRequires local server setup

    When to use which

    • SimpleReranker: Quick prototyping, no external dependencies.
    • LLMReranker: When you already have an LLM and want semantic understanding without new services.
    • CohereReranker: Production use, English-focused applications.
    • JinaReranker: Production use, multilingual applications.
    • CrossEncoder: Privacy-sensitive or cost-sensitive deployments where you can run a local service.
  4. Use the baoyu-image-gen skill for AI image generation

    master

    baoyu-image-gen is an AI SDK-based skill that enables image generation using official OpenAI (DALL-E, GPT Image) and Google (Imagen, Gemini multimodal) APIs. It supports text-to-image, reference images for editing, aspect ratio control, and quality presets.

    Core Capabilities:

    • Text-to-Image: Generate images from a text prompt.
    • Reference Images: Use existing images as a basis for new generations (supported via Google multimodal models).
    • Aspect Ratio & Size: Control dimensions using ratios (e.g., 16:9) or exact pixel sizes (e.g., 1024x1024).
    • Quality Presets: Choose between normal and 2k resolution.
    • Prompt Files: Generate images using content concatenated from multiple files.

    Execution Note: All scripts are located in the scripts/ subdirectory of the skill. The main entry point is scripts/main.ts. When running via CLI, replace ${SKILL_DIR} with the actual directory path of the skill.

    # Basic generation (auto-detect provider)
    npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "A cat" --image cat.png
  5. Explore LangGraphGo example categories

    master

    The repository contains over 85 examples categorized by functional area to help you implement specific patterns:

    • Basic Concepts: Simple graphs and LLM integrations.
    • State Management: Using Schema, Reducers, and the Command API for dynamic control flow.
    • Graph Structure & Routing: Conditional edges, subgraphs, and generic state graphs.
    • Parallel Execution: Fan-out/Fan-in patterns.
    • Streaming & Events: Real-time updates, listeners, and LLM streaming.
    • Persistence (Checkpointing): In-memory, file-based, and durable execution.
    • Human-in-the-Loop: Interrupts, time travel, and manual approval workflows.
    • Pre-built Agents: ReAct agents, Planning agents, Multi-agent systems (Supervisor/Swarm), and Chat agents.
    • Programmatic Tool Calling (PTC): Reducing latency by having LLMs generate code.
    • Memory: Conversation memory strategies and LangChain integration.
    • RAG (Retrieval Augmented Generation): Basic RAG, Advanced RAG, Vector Stores (Chroma, Milvus, etc.), and GraphRAG (FalkorDB).
    • Tools & Integrations: Search tools (Tavily, Exa, Brave) and MCP (Model Context Protocol).
    • Advanced Patterns: Graph visualization using Mermaid diagrams.
  6. Key features of LangChain and LangGraphGo integration

    master

    The integration between LangChain Go and LangGraphGo provides the following capabilities:

    • LLM Integration: Seamlessly use LangChain Go models within LangGraphGo graph nodes.
    • Context Management: Maintain and manage conversation state throughout the workflow.
    • Error Handling: Robust handling of LLM-specific errors.
    • Flexible Models: Support for multiple LLM providers via LangChain Go.
  7. Compare RAG Reranking Strategies

    master

    This example demonstrates different reranking strategies available in the LangGraphGo RAG system. Reranking optimizes retrieval quality by re-scoring documents based on their relevance to a query.

    Available Rerankers

    RerankerDescriptionProsCons
    SimpleRerankerKeyword-basedFast, no API calls, always availableLimited accuracy, keyword only
    LLMRerankerUses LLM for scoringGood semantic understanding, no new dependenciesSlower, higher API cost
    CohereRerankerUses Cohere Rerank APIHigh quality, fastRequires API key and fees
    JinaRerankerUses Jina AI Rerank APIHigh quality, multilingual supportRequires API key and fees
    CrossEncoderLocal service (via Python)Privacy-focused, free (local)Requires local server setup
  8. Explore LangGraphGo Examples

    master

    The examples/ directory contains a comprehensive collection of demonstrations showcasing the capabilities of LangGraphGo. These examples are categorized into several functional areas to help you understand how to build complex agentic workflows:

    Core Concepts

    • Basic Graphs: Simple graphs with hardcoded steps and LLM integration.
    • Routing: Dynamic routing using conditional edges based on state.
    • Arithmetic: Using LLMs to solve mathematical expressions.

    Advanced Features

    • Parallelism: Fan-out/Fan-in execution patterns and complex parallel branches with state merging.
    • State Management: Using State Schema, custom reducers, and subgraphs to manage complex data.
    • Control Flow: Using the Command API for node-level dynamic control and Listeners for event monitoring.
    • Streaming: Advanced streaming modes including updates, values, and messages.

    Persistence & Human-in-the-loop

    • Checkpointing: Persistent state storage using Memory, PostgreSQL, SQLite, Redis, or File systems.
    • Durable Execution: Recovering execution from checkpoints after crashes.
    • Human Interaction: Workflows with manual approval steps, dynamic interrupts via graph.Interrupt, and 'Time Travel' (inspecting/modifying state history via UpdateState).

    Agent Patterns

    • Pre-built Agents: ReAct, Planning, PEV (Plan-Execute-Verify), Reflection, and Supervisor agents.
    • Specialized Reasoning: Tree of Thoughts, Mental Loop (simulator-in-the-loop), and Reflexive Metacognitive agents.
    • Multi-Agent: Orchestration via Supervisor or collaborative Swarm patterns.

    Specialized Implementations

    • RAG (Retrieval Augmented Generation): Basic to advanced pipelines, including query rewriting and Knowledge Graph RAG (using FalkorDB).
    • PTC (Programmatic Tool Calling): Low-latency, token-efficient tool calling patterns.
    • Memory: Integration with LangChain Memory adapters and various memory management strategies.
  9. Visualize LangGraphGo workflows

    master

    The visualization capabilities in LangGraphGo allow you to represent workflow topology and connections through several formats:

    • Mermaid Diagrams: Generates flowchart diagrams compatible with Mermaid.js for web-based or markdown-based rendering.
    • ASCII Trees: Provides text-based graph visualizations directly in the terminal.
    • Graph Export: Allows exporting the underlying graph structure data.
    • Documentation: Supports auto-generating workflow documentation based on the graph structure.
  10. What is the Tree of Thoughts (ToT) pattern?

    master

    Tree of Thoughts (ToT) is a search-based reasoning framework that models problem-solving as a search process through a tree structure. Unlike linear Chain-of-Thought (CoT) reasoning, ToT explores multiple reasoning paths simultaneously. It works through five key stages:

    1. Decomposition: Breaking the problem into steps or 'thoughts'.
    2. Thought Generation: Creating multiple potential next steps to branch the search tree.
    3. State Evaluation: Assessing each thought for validity (follows rules), progress (closer to goal), and heuristics (promise of the path).
    4. Pruning & Expansion: Removing invalid or low-promise branches and continuing from the most promising active branches.
    5. Solution: Continuing until a goal state is reached, where the solution is the path from the root to the goal.

    ToT is best suited for logical puzzles with clear rules, complex planning problems, and constraint satisfaction problems. It is less ideal for simple tasks or subjective/vague tasks where evaluation is difficult.

  11. What is the PEV (Plan, Execute, Verify) agent pattern?

    master

    The PEV (Plan, Execute, Verify) pattern is a robust agent architecture designed for reliable task execution through a three-stage workflow with built-in error detection and recovery. It is particularly useful for high-stakes automation or when using unreliable external tools.

    The PEV Workflow

    1. Plan: Decomposes the user request into specific, executable steps.
    2. Execute: Runs each step using available tools.
    3. Verify: Checks if the execution was successful.

    If verification fails, the agent triggers a re-planning loop, creating an improved plan based on the failure context. This cycle continues until success or the maximum retry limit is reached.

    Comparison with other patterns

    PatternSelf-CorrectionVerificationBest Use Case
    ReActNoNoFast, simple tasks
    ReflectionYesAfter generationContent quality improvement
    PEVYesPer stepReliable tool execution
  12. Overview of LangGraphGo memory management strategies

    master

    LangGraphGo supports several memory strategies, each with different behaviors and use cases:

    1. Sequential Memory (Keep All): Stores all messages without limit. Best for short conversations where cost is not a concern.
    2. Sliding Window Memory: Keeps only the most recent $N$ messages. Ideal for bounded chat histories.
    3. Buffer Memory: Limits memory based on either message count or token count. A flexible middle-ground option.
    4. Summarization Memory: Automatically creates summaries of old messages while keeping recent messages intact. Best for long conversations requiring context compression.
    5. Retrieval Memory: Uses similarity retrieval to access the most relevant messages from a large knowledge base.
    6. Hierarchical Memory: Separates important messages from recent ones. Useful for complex dialogues with different importance levels.
    7. Graph-Based Memory: Builds a knowledge graph of connections between messages/topics. Best when tracking relationships between themes is critical.
    8. Compression Memory: Aggressively compresses messages into blocks and integrates them. Offers maximum space efficiency for cost-sensitive long dialogues.
    9. OS-Like Memory: Manages complex memory lifecycles using multiple layers (Active/Cache/Archive) and LRU (Least Recently Used) eviction. Designed for complex access patterns.