prebuilt

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateReactAgent

func CreateReactAgent(model llms.Model, inputTools []tools.Tool) (*graph.StateRunnable, error)

CreateReactAgent creates a new ReAct agent graph

func CreateSupervisor

func CreateSupervisor(model llms.Model, members map[string]*graph.StateRunnable) (*graph.StateRunnable, error)

CreateSupervisor creates a supervisor graph that orchestrates multiple agents

Types

type ChatMessageHistory

type ChatMessageHistory struct {
	// contains filtered or unexported fields
}

ChatMessageHistory provides direct access to chat message history

func NewChatMessageHistory

func NewChatMessageHistory(options ...memory.ChatMessageHistoryOption) *ChatMessageHistory

NewChatMessageHistory creates a new chat message history

func (*ChatMessageHistory) AddAIMessage

func (h *ChatMessageHistory) AddAIMessage(ctx context.Context, message string) error

AddAIMessage adds an AI message to the history

func (*ChatMessageHistory) AddMessage

func (h *ChatMessageHistory) AddMessage(ctx context.Context, message llms.ChatMessage) error

AddMessage adds a message to the history

func (*ChatMessageHistory) AddUserMessage

func (h *ChatMessageHistory) AddUserMessage(ctx context.Context, message string) error

AddUserMessage adds a user message to the history

func (*ChatMessageHistory) Clear

func (h *ChatMessageHistory) Clear(ctx context.Context) error

Clear clears all messages from the history

func (*ChatMessageHistory) GetHistory

GetHistory returns the underlying langchaingo ChatMessageHistory

func (*ChatMessageHistory) Messages

func (h *ChatMessageHistory) Messages(ctx context.Context) ([]llms.ChatMessage, error)

Messages returns all messages in the history

func (*ChatMessageHistory) SetMessages

func (h *ChatMessageHistory) SetMessages(ctx context.Context, messages []llms.ChatMessage) error

SetMessages sets the messages in the history

type Document

type Document struct {
	PageContent string
	Metadata    map[string]interface{}
}

Document represents a document with content and metadata

type DocumentLoader

type DocumentLoader interface {
	Load(ctx context.Context) ([]Document, error)
}

DocumentLoader loads documents from various sources

type DocumentWithScore

type DocumentWithScore struct {
	Document Document
	Score    float64
}

DocumentWithScore represents a document with its similarity score

type Embedder

type Embedder interface {
	EmbedDocuments(ctx context.Context, texts []string) ([][]float64, error)
	EmbedQuery(ctx context.Context, text string) ([]float64, error)
}

Embedder generates embeddings for text

type InMemoryVectorStore

type InMemoryVectorStore struct {
	// contains filtered or unexported fields
}

InMemoryVectorStore is a simple in-memory vector store implementation

func NewInMemoryVectorStore

func NewInMemoryVectorStore(embedder Embedder) *InMemoryVectorStore

NewInMemoryVectorStore creates a new InMemoryVectorStore

func (*InMemoryVectorStore) AddDocuments

func (s *InMemoryVectorStore) AddDocuments(ctx context.Context, documents []Document, embeddings [][]float64) error

AddDocuments adds documents with their embeddings to the store

func (*InMemoryVectorStore) SimilaritySearch

func (s *InMemoryVectorStore) SimilaritySearch(ctx context.Context, query string, k int) ([]Document, error)

SimilaritySearch performs similarity search and returns top k documents

func (*InMemoryVectorStore) SimilaritySearchWithScore

func (s *InMemoryVectorStore) SimilaritySearchWithScore(ctx context.Context, query string, k int) ([]DocumentWithScore, error)

SimilaritySearchWithScore performs similarity search and returns documents with scores

type LangChainDocumentLoader

type LangChainDocumentLoader struct {
	// contains filtered or unexported fields
}

LangChainDocumentLoader adapts langchaingo's documentloaders.Loader to our DocumentLoader interface

func NewLangChainDocumentLoader

func NewLangChainDocumentLoader(loader documentloaders.Loader) *LangChainDocumentLoader

NewLangChainDocumentLoader creates a new adapter for langchaingo document loaders

func (*LangChainDocumentLoader) Load

Load loads documents using the underlying langchaingo loader

func (*LangChainDocumentLoader) LoadAndSplit

func (l *LangChainDocumentLoader) LoadAndSplit(ctx context.Context, splitter textsplitter.TextSplitter) ([]Document, error)

LoadAndSplit loads and splits documents using langchaingo's text splitter

type LangChainEmbedder

type LangChainEmbedder struct {
	// contains filtered or unexported fields
}

LangChainEmbedder adapts langchaingo's embeddings.Embedder to our Embedder interface

func NewLangChainEmbedder

func NewLangChainEmbedder(embedder embeddings.Embedder) *LangChainEmbedder

NewLangChainEmbedder creates a new adapter for langchaingo embedders

func (*LangChainEmbedder) EmbedDocuments

func (e *LangChainEmbedder) EmbedDocuments(ctx context.Context, texts []string) ([][]float64, error)

EmbedDocuments generates embeddings for multiple documents

func (*LangChainEmbedder) EmbedQuery

func (e *LangChainEmbedder) EmbedQuery(ctx context.Context, text string) ([]float64, error)

EmbedQuery generates an embedding for a single query

type LangChainMemory

type LangChainMemory struct {
	// contains filtered or unexported fields
}

LangChainMemory adapts langchaingo's memory implementations to our Memory interface

func NewConversationBufferMemory

func NewConversationBufferMemory(options ...memory.ConversationBufferOption) *LangChainMemory

NewConversationBufferMemory creates a new conversation buffer memory with default settings

func NewConversationTokenBufferMemory

func NewConversationTokenBufferMemory(llm llms.Model, maxTokenLimit int, options ...memory.ConversationBufferOption) *LangChainMemory

NewConversationTokenBufferMemory creates a new conversation token buffer memory that keeps conversation history within a token limit

func NewConversationWindowBufferMemory

func NewConversationWindowBufferMemory(windowSize int, options ...memory.ConversationBufferOption) *LangChainMemory

NewConversationWindowBufferMemory creates a new conversation window buffer memory that keeps only the last N conversation turns

func NewLangChainMemory

func NewLangChainMemory(buffer schema.Memory) *LangChainMemory

NewLangChainMemory creates a new adapter for langchaingo memory Supports ConversationBuffer, ConversationWindowBuffer, ConversationTokenBuffer, etc.

func (*LangChainMemory) Clear

func (m *LangChainMemory) Clear(ctx context.Context) error

Clear clears memory contents

func (*LangChainMemory) GetMessages

func (m *LangChainMemory) GetMessages(ctx context.Context) ([]llms.ChatMessage, error)

GetMessages returns all messages in memory This is a convenience method that extracts messages from the memory buffer

func (*LangChainMemory) LoadMemoryVariables

func (m *LangChainMemory) LoadMemoryVariables(ctx context.Context, inputs map[string]any) (map[string]any, error)

LoadMemoryVariables loads memory variables

func (*LangChainMemory) SaveContext

func (m *LangChainMemory) SaveContext(ctx context.Context, inputValues map[string]any, outputValues map[string]any) error

SaveContext saves the context from this conversation to buffer

type LangChainTextSplitter

type LangChainTextSplitter struct {
	// contains filtered or unexported fields
}

LangChainTextSplitter adapts langchaingo's textsplitter.TextSplitter to our TextSplitter interface

func NewLangChainTextSplitter

func NewLangChainTextSplitter(splitter textsplitter.TextSplitter) *LangChainTextSplitter

NewLangChainTextSplitter creates a new adapter for langchaingo text splitters

func (*LangChainTextSplitter) SplitDocuments

func (s *LangChainTextSplitter) SplitDocuments(documents []Document) ([]Document, error)

SplitDocuments splits documents using the underlying langchaingo splitter

type LangChainVectorStore

type LangChainVectorStore struct {
	// contains filtered or unexported fields
}

LangChainVectorStore adapts langchaingo's vectorstores.VectorStore to our VectorStore interface

func NewLangChainVectorStore

func NewLangChainVectorStore(store vectorstores.VectorStore) *LangChainVectorStore

NewLangChainVectorStore creates a new adapter for langchaingo vector stores

func (*LangChainVectorStore) AddDocuments

func (s *LangChainVectorStore) AddDocuments(ctx context.Context, documents []Document, embeddings [][]float64) error

AddDocuments adds documents to the vector store

func (*LangChainVectorStore) SimilaritySearch

func (s *LangChainVectorStore) SimilaritySearch(ctx context.Context, query string, k int) ([]Document, error)

SimilaritySearch searches for similar documents

func (*LangChainVectorStore) SimilaritySearchWithScore

func (s *LangChainVectorStore) SimilaritySearchWithScore(ctx context.Context, query string, k int) ([]DocumentWithScore, error)

SimilaritySearchWithScore searches for similar documents and returns them with scores

type Memory

type Memory interface {
	// SaveContext saves the context from this conversation to buffer
	SaveContext(ctx context.Context, inputValues map[string]any, outputValues map[string]any) error
	// LoadMemoryVariables loads memory variables
	LoadMemoryVariables(ctx context.Context, inputs map[string]any) (map[string]any, error)
	// Clear clears memory contents
	Clear(ctx context.Context) error
	// GetMessages returns all messages in memory
	GetMessages(ctx context.Context) ([]llms.ChatMessage, error)
}

Memory is the interface for conversation memory management in langgraphgo

type MockEmbedder

type MockEmbedder struct {
	Dimension int
}

MockEmbedder is a simple mock embedder for testing

func NewMockEmbedder

func NewMockEmbedder(dimension int) *MockEmbedder

NewMockEmbedder creates a new MockEmbedder

func (*MockEmbedder) EmbedDocuments

func (e *MockEmbedder) EmbedDocuments(ctx context.Context, texts []string) ([][]float64, error)

EmbedDocuments generates mock embeddings for documents

func (*MockEmbedder) EmbedQuery

func (e *MockEmbedder) EmbedQuery(ctx context.Context, text string) ([]float64, error)

EmbedQuery generates a mock embedding for a query

type RAGConfig

type RAGConfig struct {
	// Retrieval configuration
	TopK           int     // Number of documents to retrieve
	ScoreThreshold float64 // Minimum relevance score
	UseReranking   bool    // Whether to use reranking
	UseFallback    bool    // Whether to use fallback search

	// Generation configuration
	SystemPrompt     string
	IncludeCitations bool
	MaxTokens        int
	Temperature      float64

	// Components
	Loader      DocumentLoader
	Splitter    TextSplitter
	Embedder    Embedder
	VectorStore VectorStore
	Retriever   Retriever
	Reranker    Reranker
	LLM         llms.Model
}

RAGConfig configures a RAG pipeline

func DefaultRAGConfig

func DefaultRAGConfig() *RAGConfig

DefaultRAGConfig returns a default RAG configuration

type RAGPipeline

type RAGPipeline struct {
	// contains filtered or unexported fields
}

RAGPipeline represents a complete RAG pipeline

func NewRAGPipeline

func NewRAGPipeline(config *RAGConfig) *RAGPipeline

NewRAGPipeline creates a new RAG pipeline with the given configuration

func (*RAGPipeline) BuildAdvancedRAG

func (p *RAGPipeline) BuildAdvancedRAG() error

BuildAdvancedRAG builds an advanced RAG pipeline: Retrieve -> Rerank -> Generate

func (*RAGPipeline) BuildBasicRAG

func (p *RAGPipeline) BuildBasicRAG() error

BuildBasicRAG builds a basic RAG pipeline: Retrieve -> Generate

func (*RAGPipeline) BuildConditionalRAG

func (p *RAGPipeline) BuildConditionalRAG() error

BuildConditionalRAG builds a RAG pipeline with conditional routing based on relevance

func (*RAGPipeline) Compile

func (p *RAGPipeline) Compile() (*graph.Runnable, error)

Compile compiles the RAG pipeline into a runnable graph

func (*RAGPipeline) GetGraph

func (p *RAGPipeline) GetGraph() *graph.MessageGraph

GetGraph returns the underlying graph for visualization

type RAGState

type RAGState struct {
	Query              string
	Documents          []Document
	RetrievedDocuments []Document
	RankedDocuments    []DocumentWithScore
	Context            string
	Answer             string
	Citations          []string
	Metadata           map[string]interface{}
}

RAGState represents the state flowing through a RAG pipeline

type Reranker

type Reranker interface {
	Rerank(ctx context.Context, query string, documents []Document) ([]DocumentWithScore, error)
}

Reranker reranks retrieved documents based on relevance

type Retriever

type Retriever interface {
	GetRelevantDocuments(ctx context.Context, query string) ([]Document, error)
}

Retriever retrieves relevant documents for a query

type SimpleReranker

type SimpleReranker struct {
}

SimpleReranker is a simple reranker that scores documents based on keyword matching

func NewSimpleReranker

func NewSimpleReranker() *SimpleReranker

NewSimpleReranker creates a new SimpleReranker

func (*SimpleReranker) Rerank

func (r *SimpleReranker) Rerank(ctx context.Context, query string, documents []Document) ([]DocumentWithScore, error)

Rerank reranks documents based on query relevance

type SimpleTextSplitter

type SimpleTextSplitter struct {
	ChunkSize    int
	ChunkOverlap int
	Separator    string
}

SimpleTextSplitter splits text into chunks of a given size

func NewSimpleTextSplitter

func NewSimpleTextSplitter(chunkSize, chunkOverlap int) *SimpleTextSplitter

NewSimpleTextSplitter creates a new SimpleTextSplitter

func (*SimpleTextSplitter) SplitDocuments

func (s *SimpleTextSplitter) SplitDocuments(documents []Document) ([]Document, error)

SplitDocuments splits documents into smaller chunks

type StaticDocumentLoader

type StaticDocumentLoader struct {
	Documents []Document
}

StaticDocumentLoader loads documents from a static list

func NewStaticDocumentLoader

func NewStaticDocumentLoader(documents []Document) *StaticDocumentLoader

NewStaticDocumentLoader creates a new StaticDocumentLoader

func (*StaticDocumentLoader) Load

Load returns the static list of documents

type TextSplitter

type TextSplitter interface {
	SplitDocuments(documents []Document) ([]Document, error)
}

TextSplitter splits documents into smaller chunks

type ToolExecutor

type ToolExecutor struct {
	// contains filtered or unexported fields
}

ToolExecutor executes tools based on invocations

func NewToolExecutor

func NewToolExecutor(inputTools []tools.Tool) *ToolExecutor

NewToolExecutor creates a new ToolExecutor with the given tools

func (*ToolExecutor) Execute

func (te *ToolExecutor) Execute(ctx context.Context, invocation ToolInvocation) (string, error)

Execute executes a single tool invocation

func (*ToolExecutor) ExecuteMany

func (te *ToolExecutor) ExecuteMany(ctx context.Context, invocations []ToolInvocation) ([]string, error)

ExecuteMany executes multiple tool invocations in parallel (if needed, but here sequential for simplicity) In a real graph, this might be a ParallelNode, but here we provide a helper.

func (*ToolExecutor) ToolNode

func (te *ToolExecutor) ToolNode(ctx context.Context, state interface{}) (interface{}, error)

ToolNode is a graph node function that executes tools It expects the state to contain a list of ToolInvocation or a single ToolInvocation This is a simplified version. In a real agent, it would parse messages.

type ToolInvocation

type ToolInvocation struct {
	Tool      string `json:"tool"`
	ToolInput string `json:"tool_input"`
}

ToolInvocation represents a request to execute a tool

type ToolNode

type ToolNode struct {
	Executor *ToolExecutor
}

ToolNode is a reusable node that executes tool calls from the last AI message. It expects the state to be a map[string]interface{} with a "messages" key containing []llms.MessageContent.

func NewToolNode

func NewToolNode(inputTools []tools.Tool) *ToolNode

NewToolNode creates a new ToolNode with the given tools.

func (*ToolNode) Invoke

func (tn *ToolNode) Invoke(ctx context.Context, state interface{}) (interface{}, error)

Invoke executes the tool calls found in the last message.

type VectorStore

type VectorStore interface {
	AddDocuments(ctx context.Context, documents []Document, embeddings [][]float64) error
	SimilaritySearch(ctx context.Context, query string, k int) ([]Document, error)
	SimilaritySearchWithScore(ctx context.Context, query string, k int) ([]DocumentWithScore, error)
}

VectorStore stores and retrieves document embeddings

type VectorStoreRetriever

type VectorStoreRetriever struct {
	VectorStore VectorStore
	TopK        int
}

VectorStoreRetriever implements Retriever using a VectorStore

func NewVectorStoreRetriever

func NewVectorStoreRetriever(vectorStore VectorStore, topK int) *VectorStoreRetriever

NewVectorStoreRetriever creates a new VectorStoreRetriever

func (*VectorStoreRetriever) GetRelevantDocuments

func (r *VectorStoreRetriever) GetRelevantDocuments(ctx context.Context, query string) ([]Document, error)

GetRelevantDocuments retrieves relevant documents for a query

Jump to

Keyboard shortcuts

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