Documentation
¶
Overview ¶
Package builder provides fluent builder APIs for programmatic agent construction.
This package provides an ergonomic, chainable API for building agents, LLMs, memory strategies, tools, RAG systems, and other components programmatically. The builders wrap the underlying Config structs, providing the best of both worlds:
- Fluent, discoverable API for programmatic use
- Config structs remain available for direct use (ADK-Go aligned)
Quick Start ¶
Build a complete agent with LLM, reasoning, and tools:
agent, err := builder.NewAgent("assistant").
WithName("Assistant").
WithDescription("A helpful AI assistant").
WithLLM(
builder.NewLLM("openai").
Model("gpt-4o-mini").
APIKeyFromEnv("OPENAI_API_KEY").
Temperature(0.7).
MustBuild(),
).
WithReasoning(
builder.NewReasoning().
MaxIterations(100).
EnableExitTool(true).
Build(),
).
WithTools(weatherTool, searchTool).
Build()
Architecture ¶
The builder package is a convenience layer over the core packages:
┌─────────────────────────────────────────────────────────────────┐ │ Builder Package (Convenience Layer) │ │ Fluent API for ergonomic programmatic construction │ │ │ │ Agents: │ │ AgentBuilder → llmagent.Config → llmagent.New() │ │ ReasoningBuilder → llmagent.ReasoningConfig │ │ │ │ LLMs & Embeddings: │ │ LLMBuilder → model.LLM (OpenAI, Anthropic, Gemini, Ollama) │ │ EmbedderBuilder → embedder.Embedder │ │ │ │ Tools: │ │ MCPBuilder → mcptoolset.Toolset (MCP servers) │ │ ToolsetBuilder → tool.Toolset (wrap tools) │ │ FunctionTool → tool.CallableTool (from Go functions) │ │ │ │ Memory: │ │ WorkingMemoryBuilder → memory.WorkingMemoryStrategy │ │ │ │ RAG (Retrieval-Augmented Generation): │ │ DocumentStoreBuilder → rag.DocumentStore │ │ VectorProviderBuilder → vector.Provider │ │ │ │ Runtime: │ │ RunnerBuilder → runner.Runner │ │ ServerBuilder → A2A HTTP server │ └─────────────────────────────────────────────────────────────────┘
Available Builders ¶
Core:
- AgentBuilder: Build LLM agents with fluent API
- LLMBuilder: Build LLM providers (OpenAI, Anthropic, Gemini, Ollama)
- ReasoningBuilder: Configure chain-of-thought reasoning
- WorkingMemoryBuilder: Configure working memory strategies
Tools:
- MCPBuilder: Connect to MCP (Model Context Protocol) servers
- ToolsetBuilder: Wrap tools into a toolset
- FunctionTool: Create tools from typed Go functions
RAG:
- DocumentStoreBuilder: Build document stores for RAG
- EmbedderBuilder: Build embedding providers
- VectorProviderBuilder: Build vector database providers
Runtime:
- RunnerBuilder: Build agent runners
- ServerBuilder: Build A2A HTTP servers
Example: Multi-Agent System ¶
// Build LLM
llm := builder.NewLLM("openai").
Model("gpt-4o").
APIKeyFromEnv("OPENAI_API_KEY").
MustBuild()
// Build specialized agents
researcher, _ := builder.NewAgent("researcher").
WithDescription("Researches topics in depth").
WithLLM(llm).
Build()
writer, _ := builder.NewAgent("writer").
WithDescription("Writes content based on research").
WithLLM(llm).
Build()
// Build parent agent with sub-agents
parent, _ := builder.NewAgent("coordinator").
WithDescription("Coordinates research and writing").
WithLLM(llm).
WithSubAgents(researcher, writer).
Build()
Example: RAG with Document Store ¶
// Build embedder
emb := builder.NewEmbedder("openai").
Model("text-embedding-3-small").
MustBuild()
// Build vector store
vecStore := builder.NewVectorProvider("chromem").
PersistPath(".hector/vectors").
MustBuild()
// Build document store
docStore, _ := builder.NewDocumentStore("docs").
FromDirectory("./documents").
WithVectorProvider(vecStore).
WithEmbedder(emb).
EnableWatching(true).
Build()
Example: Custom Function Tool ¶
type WeatherArgs struct {
City string `json:"city" jsonschema:"required,description=City name"`
}
weatherTool, _ := builder.FunctionTool(
"get_weather",
"Get current weather for a city",
func(ctx tool.Context, args WeatherArgs) (map[string]any, error) {
return map[string]any{"temp": 22, "city": args.City}, nil
},
)
Example: MCP Tool Integration ¶
// SSE transport
mcpTools, _ := builder.NewMCP("weather").
URL("http://localhost:9000").
Build()
// Stdio transport
fsTool, _ := builder.NewMCP("filesystem").
Command("npx", "-y", "@modelcontextprotocol/server-filesystem", "/tmp").
Build()
Index ¶
- func FunctionTool[Args any](name string, description string, ...) (tool.CallableTool, error)
- func MustFunctionTool[Args any](name string, description string, ...) tool.CallableTool
- type AgentBuilder
- func (b *AgentBuilder) Build() (agent.Agent, error)
- func (b *AgentBuilder) DisallowTransferToParent(disallow bool) *AgentBuilder
- func (b *AgentBuilder) DisallowTransferToPeers(disallow bool) *AgentBuilder
- func (b *AgentBuilder) EnableStreaming(enable bool) *AgentBuilder
- func (b *AgentBuilder) MustBuild() agent.Agent
- func (b *AgentBuilder) WithAfterAgentCallback(cb agent.AfterAgentCallback) *AgentBuilder
- func (b *AgentBuilder) WithAfterModelCallback(cb llmagent.AfterModelCallback) *AgentBuilder
- func (b *AgentBuilder) WithAfterToolCallback(cb llmagent.AfterToolCallback) *AgentBuilder
- func (b *AgentBuilder) WithBeforeAgentCallback(cb agent.BeforeAgentCallback) *AgentBuilder
- func (b *AgentBuilder) WithBeforeModelCallback(cb llmagent.BeforeModelCallback) *AgentBuilder
- func (b *AgentBuilder) WithBeforeToolCallback(cb llmagent.BeforeToolCallback) *AgentBuilder
- func (b *AgentBuilder) WithDescription(desc string) *AgentBuilder
- func (b *AgentBuilder) WithInputSchema(schema map[string]any) *AgentBuilder
- func (b *AgentBuilder) WithInstruction(instruction string) *AgentBuilder
- func (b *AgentBuilder) WithLLM(llm model.LLM) *AgentBuilder
- func (b *AgentBuilder) WithName(name string) *AgentBuilder
- func (b *AgentBuilder) WithOutputKey(key string) *AgentBuilder
- func (b *AgentBuilder) WithOutputSchema(schema map[string]any) *AgentBuilder
- func (b *AgentBuilder) WithReasoning(reasoning *llmagent.ReasoningConfig) *AgentBuilder
- func (b *AgentBuilder) WithReasoningBuilder(rb *ReasoningBuilder) *AgentBuilder
- func (b *AgentBuilder) WithSubAgent(ag agent.Agent) *AgentBuilder
- func (b *AgentBuilder) WithSubAgents(agents ...agent.Agent) *AgentBuilder
- func (b *AgentBuilder) WithTool(t tool.Tool) *AgentBuilder
- func (b *AgentBuilder) WithTools(tools ...tool.Tool) *AgentBuilder
- func (b *AgentBuilder) WithToolset(ts tool.Toolset) *AgentBuilder
- func (b *AgentBuilder) WithToolsets(toolsets ...tool.Toolset) *AgentBuilder
- func (b *AgentBuilder) WithWorkingMemory(strategy memory.WorkingMemoryStrategy) *AgentBuilder
- type AuthBuilder
- func (b *AuthBuilder) AddExcludedPath(path string) *AuthBuilder
- func (b *AuthBuilder) Audience(audience string) *AuthBuilder
- func (b *AuthBuilder) Build() *config.AuthConfig
- func (b *AuthBuilder) Enabled(enabled bool) *AuthBuilder
- func (b *AuthBuilder) ExcludedPaths(paths ...string) *AuthBuilder
- func (b *AuthBuilder) Issuer(issuer string) *AuthBuilder
- func (b *AuthBuilder) JWKSURL(url string) *AuthBuilder
- func (b *AuthBuilder) RefreshInterval(interval time.Duration) *AuthBuilder
- func (b *AuthBuilder) RequireAuth(require bool) *AuthBuilder
- type CredentialsBuilder
- func (b *CredentialsBuilder) APIKey(key string) *CredentialsBuilder
- func (b *CredentialsBuilder) APIKeyHeader(header string) *CredentialsBuilder
- func (b *CredentialsBuilder) Build() *config.CredentialsConfig
- func (b *CredentialsBuilder) Password(pass string) *CredentialsBuilder
- func (b *CredentialsBuilder) Token(token string) *CredentialsBuilder
- func (b *CredentialsBuilder) Type(typ string) *CredentialsBuilder
- func (b *CredentialsBuilder) Username(user string) *CredentialsBuilder
- type DocumentStoreBuilder
- func (b *DocumentStoreBuilder) Build() (*rag.DocumentStore, error)
- func (b *DocumentStoreBuilder) ChunkOverlap(overlap int) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) ChunkSize(size int) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) Collection(collection string) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) DefaultThreshold(score float32) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) DefaultTopK(k int) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) Description(desc string) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) EnableCheckpoints(enabled bool) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) EnableHyDE(enabled bool) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) EnableIncremental(enabled bool) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) EnableMultiQuery(enabled bool) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) EnableProgress(enabled bool) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) EnableRerank(enabled bool) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) EnableWatching(enabled bool) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) ExcludePatterns(patterns ...string) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) FromDirectory(path string) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) IncludePatterns(patterns ...string) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) MaxConcurrent(max int) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) MaxFileSize(size int64) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) MustBuild() *rag.DocumentStore
- func (b *DocumentStoreBuilder) WithEmbedder(emb embedder.Embedder) *DocumentStoreBuilder
- func (b *DocumentStoreBuilder) WithVectorProvider(provider vector.Provider) *DocumentStoreBuilder
- type EmbedderBuilder
- func (b *EmbedderBuilder) APIKey(key string) *EmbedderBuilder
- func (b *EmbedderBuilder) APIKeyFromEnv(envVar string) *EmbedderBuilder
- func (b *EmbedderBuilder) BaseURL(url string) *EmbedderBuilder
- func (b *EmbedderBuilder) BatchSize(size int) *EmbedderBuilder
- func (b *EmbedderBuilder) Build() (embedder.Embedder, error)
- func (b *EmbedderBuilder) Dimension(dim int) *EmbedderBuilder
- func (b *EmbedderBuilder) EncodingFormat(format string) *EmbedderBuilder
- func (b *EmbedderBuilder) InputType(inputType string) *EmbedderBuilder
- func (b *EmbedderBuilder) Model(model string) *EmbedderBuilder
- func (b *EmbedderBuilder) MustBuild() embedder.Embedder
- func (b *EmbedderBuilder) OutputDimension(dim int) *EmbedderBuilder
- func (b *EmbedderBuilder) Timeout(seconds int) *EmbedderBuilder
- func (b *EmbedderBuilder) Truncate(truncate string) *EmbedderBuilder
- func (b *EmbedderBuilder) User(user string) *EmbedderBuilder
- type LLMBuilder
- func (b *LLMBuilder) APIKey(key string) *LLMBuilder
- func (b *LLMBuilder) APIKeyFromEnv(envVar string) *LLMBuilder
- func (b *LLMBuilder) BaseURL(url string) *LLMBuilder
- func (b *LLMBuilder) Build() (model.LLM, error)
- func (b *LLMBuilder) EnableThinking(enable bool) *LLMBuilder
- func (b *LLMBuilder) MaxRetries(max int) *LLMBuilder
- func (b *LLMBuilder) MaxTokens(max int) *LLMBuilder
- func (b *LLMBuilder) MaxToolOutputLength(max int) *LLMBuilder
- func (b *LLMBuilder) Model(model string) *LLMBuilder
- func (b *LLMBuilder) MustBuild() model.LLM
- func (b *LLMBuilder) Temperature(temp float64) *LLMBuilder
- func (b *LLMBuilder) ThinkingBudget(budget int) *LLMBuilder
- func (b *LLMBuilder) Timeout(timeout time.Duration) *LLMBuilder
- type MCPBuilder
- func (b *MCPBuilder) Build() (*mcptoolset.Toolset, error)
- func (b *MCPBuilder) Command(cmd string, args ...string) *MCPBuilder
- func (b *MCPBuilder) Env(env map[string]string) *MCPBuilder
- func (b *MCPBuilder) Filter(tools ...string) *MCPBuilder
- func (b *MCPBuilder) MustBuild() *mcptoolset.Toolset
- func (b *MCPBuilder) Transport(transport string) *MCPBuilder
- func (b *MCPBuilder) URL(url string) *MCPBuilder
- type ReasoningBuilder
- func (b *ReasoningBuilder) Build() *llmagent.ReasoningConfig
- func (b *ReasoningBuilder) CompletionInstruction(instruction string) *ReasoningBuilder
- func (b *ReasoningBuilder) EnableEscalateTool(enable bool) *ReasoningBuilder
- func (b *ReasoningBuilder) EnableExitTool(enable bool) *ReasoningBuilder
- func (b *ReasoningBuilder) MaxIterations(max int) *ReasoningBuilder
- type RunnerBuilder
- func (b *RunnerBuilder) Build() (*runner.Runner, error)
- func (b *RunnerBuilder) MustBuild() *runner.Runner
- func (b *RunnerBuilder) WithAgent(ag agent.Agent) *RunnerBuilder
- func (b *RunnerBuilder) WithCheckpointManager(mgr runner.CheckpointManager) *RunnerBuilder
- func (b *RunnerBuilder) WithIndexService(svc runner.IndexService) *RunnerBuilder
- func (b *RunnerBuilder) WithMemoryIndex(idx memory.IndexService) *RunnerBuilder
- func (b *RunnerBuilder) WithSessionService(svc session.Service) *RunnerBuilder
- type Server
- type ServerBuilder
- func (b *ServerBuilder) Address(addr string) *ServerBuilder
- func (b *ServerBuilder) Build() (http.Handler, error)
- func (b *ServerBuilder) BuildServer() (*Server, error)
- func (b *ServerBuilder) EnableStreaming(enabled bool) *ServerBuilder
- func (b *ServerBuilder) EnableUI(enabled bool) *ServerBuilder
- func (b *ServerBuilder) MustBuildServer() *Server
- func (b *ServerBuilder) WithRunner(r *runner.Runner) *ServerBuilder
- type ToolsetBuilder
- type VectorProviderBuilder
- func (b *VectorProviderBuilder) APIKey(key string) *VectorProviderBuilder
- func (b *VectorProviderBuilder) Build() (vector.Provider, error)
- func (b *VectorProviderBuilder) Compress(compress bool) *VectorProviderBuilder
- func (b *VectorProviderBuilder) Host(host string) *VectorProviderBuilder
- func (b *VectorProviderBuilder) IndexName(name string) *VectorProviderBuilder
- func (b *VectorProviderBuilder) MustBuild() vector.Provider
- func (b *VectorProviderBuilder) PersistPath(path string) *VectorProviderBuilder
- func (b *VectorProviderBuilder) Port(port int) *VectorProviderBuilder
- func (b *VectorProviderBuilder) UseTLS(useTLS bool) *VectorProviderBuilder
- type WorkingMemoryBuilder
- func (b *WorkingMemoryBuilder) Budget(budget int) *WorkingMemoryBuilder
- func (b *WorkingMemoryBuilder) Build() (memory.WorkingMemoryStrategy, error)
- func (b *WorkingMemoryBuilder) ModelName(name string) *WorkingMemoryBuilder
- func (b *WorkingMemoryBuilder) MustBuild() memory.WorkingMemoryStrategy
- func (b *WorkingMemoryBuilder) PreserveRecent(count int) *WorkingMemoryBuilder
- func (b *WorkingMemoryBuilder) Target(target float64) *WorkingMemoryBuilder
- func (b *WorkingMemoryBuilder) Threshold(threshold float64) *WorkingMemoryBuilder
- func (b *WorkingMemoryBuilder) WindowSize(size int) *WorkingMemoryBuilder
- func (b *WorkingMemoryBuilder) WithLLM(llm model.LLM) *WorkingMemoryBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FunctionTool ¶
func FunctionTool[Args any]( name string, description string, fn func(tool.Context, Args) (map[string]any, error), ) (tool.CallableTool, error)
FunctionTool creates a callable tool from a typed Go function.
This is a convenience wrapper around functiontool.New for ergonomic use. The function signature must be:
func(tool.Context, Args) (map[string]any, error)
Where Args is a struct with json and jsonschema tags defining the parameters.
Example:
type GetWeatherArgs struct {
City string `json:"city" jsonschema:"required,description=City name"`
}
tool, err := builder.FunctionTool(
"get_weather",
"Get current weather for a city",
func(ctx tool.Context, args GetWeatherArgs) (map[string]any, error) {
return map[string]any{"temp": 22}, nil
},
)
Types ¶
type AgentBuilder ¶
type AgentBuilder struct {
// contains filtered or unexported fields
}
AgentBuilder provides a fluent API for building LLM agents.
Example:
agent, err := builder.NewAgent("assistant").
WithName("Assistant").
WithDescription("A helpful AI assistant").
WithLLM(llm).
WithInstruction("You are a helpful assistant.").
WithTools(tool1, tool2).
Build()
func NewAgent ¶
func NewAgent(id string) *AgentBuilder
NewAgent creates a new agent builder.
The id must be unique within the agent tree.
Example:
agent, err := builder.NewAgent("my-agent").
WithLLM(llm).
Build()
func (*AgentBuilder) Build ¶
func (b *AgentBuilder) Build() (agent.Agent, error)
Build creates the agent.
Returns an error if required parameters are missing.
func (*AgentBuilder) DisallowTransferToParent ¶
func (b *AgentBuilder) DisallowTransferToParent(disallow bool) *AgentBuilder
DisallowTransferToParent prevents delegation to parent agent.
Example:
builder.NewAgent("my-agent").DisallowTransferToParent(true)
func (*AgentBuilder) DisallowTransferToPeers ¶
func (b *AgentBuilder) DisallowTransferToPeers(disallow bool) *AgentBuilder
DisallowTransferToPeers prevents delegation to sibling agents.
Example:
builder.NewAgent("my-agent").DisallowTransferToPeers(true)
func (*AgentBuilder) EnableStreaming ¶
func (b *AgentBuilder) EnableStreaming(enable bool) *AgentBuilder
EnableStreaming enables token-by-token streaming.
Example:
builder.NewAgent("my-agent").EnableStreaming(true)
func (*AgentBuilder) MustBuild ¶
func (b *AgentBuilder) MustBuild() agent.Agent
MustBuild creates the agent or panics on error.
Use this only when you're certain the configuration is valid.
func (*AgentBuilder) WithAfterAgentCallback ¶
func (b *AgentBuilder) WithAfterAgentCallback(cb agent.AfterAgentCallback) *AgentBuilder
WithAfterAgentCallback adds a callback that runs after the agent completes.
Example:
builder.NewAgent("my-agent").WithAfterAgentCallback(func(ctx agent.CallbackContext) (*a2a.Content, error) {
// Post-processing logic
return nil, nil
})
func (*AgentBuilder) WithAfterModelCallback ¶
func (b *AgentBuilder) WithAfterModelCallback(cb llmagent.AfterModelCallback) *AgentBuilder
WithAfterModelCallback adds a callback that runs after each LLM call.
Example:
builder.NewAgent("my-agent").WithAfterModelCallback(func(ctx agent.CallbackContext, resp *model.Response, err error) (*model.Response, error) {
// Modify response or handle error
return resp, err
})
func (*AgentBuilder) WithAfterToolCallback ¶
func (b *AgentBuilder) WithAfterToolCallback(cb llmagent.AfterToolCallback) *AgentBuilder
WithAfterToolCallback adds a callback that runs after tool execution.
Example:
builder.NewAgent("my-agent").WithAfterToolCallback(func(ctx tool.Context, t tool.Tool, args, result map[string]any, err error) (map[string]any, error) {
// Modify result or handle error
return result, err
})
func (*AgentBuilder) WithBeforeAgentCallback ¶
func (b *AgentBuilder) WithBeforeAgentCallback(cb agent.BeforeAgentCallback) *AgentBuilder
WithBeforeAgentCallback adds a callback that runs before the agent starts.
Example:
builder.NewAgent("my-agent").WithBeforeAgentCallback(func(ctx agent.CallbackContext) (*a2a.Content, error) {
// Pre-processing logic
return nil, nil
})
func (*AgentBuilder) WithBeforeModelCallback ¶
func (b *AgentBuilder) WithBeforeModelCallback(cb llmagent.BeforeModelCallback) *AgentBuilder
WithBeforeModelCallback adds a callback that runs before each LLM call.
Example:
builder.NewAgent("my-agent").WithBeforeModelCallback(func(ctx agent.CallbackContext, req *model.Request) (*model.Response, error) {
// Modify request or short-circuit
return nil, nil
})
func (*AgentBuilder) WithBeforeToolCallback ¶
func (b *AgentBuilder) WithBeforeToolCallback(cb llmagent.BeforeToolCallback) *AgentBuilder
WithBeforeToolCallback adds a callback that runs before tool execution.
Example:
builder.NewAgent("my-agent").WithBeforeToolCallback(func(ctx tool.Context, t tool.Tool, args map[string]any) (map[string]any, error) {
// Modify args or short-circuit
return nil, nil
})
func (*AgentBuilder) WithDescription ¶
func (b *AgentBuilder) WithDescription(desc string) *AgentBuilder
WithDescription sets the agent's description. The description helps LLMs decide when to delegate to this agent.
Example:
builder.NewAgent("researcher").WithDescription("Researches topics in depth")
func (*AgentBuilder) WithInputSchema ¶
func (b *AgentBuilder) WithInputSchema(schema map[string]any) *AgentBuilder
WithInputSchema validates input when agent is used as a tool.
Example:
builder.NewAgent("my-agent").WithInputSchema(map[string]any{
"type": "object",
"properties": map[string]any{
"query": map[string]any{"type": "string"},
},
})
func (*AgentBuilder) WithInstruction ¶
func (b *AgentBuilder) WithInstruction(instruction string) *AgentBuilder
WithInstruction sets the system instruction for the agent. Supports template placeholders like {variable} resolved from state.
Example:
builder.NewAgent("my-agent").WithInstruction("You are a helpful assistant.")
func (*AgentBuilder) WithLLM ¶
func (b *AgentBuilder) WithLLM(llm model.LLM) *AgentBuilder
WithLLM sets the LLM provider for the agent.
Example:
llm, _ := builder.NewLLM("openai").Model("gpt-4o").Build()
builder.NewAgent("my-agent").WithLLM(llm)
func (*AgentBuilder) WithName ¶
func (b *AgentBuilder) WithName(name string) *AgentBuilder
WithName sets the agent's display name.
Example:
builder.NewAgent("my-agent").WithName("My Assistant")
func (*AgentBuilder) WithOutputKey ¶
func (b *AgentBuilder) WithOutputKey(key string) *AgentBuilder
WithOutputKey saves agent output to session state under this key.
Example:
builder.NewAgent("researcher").WithOutputKey("research_results")
func (*AgentBuilder) WithOutputSchema ¶
func (b *AgentBuilder) WithOutputSchema(schema map[string]any) *AgentBuilder
WithOutputSchema enforces structured output format.
Example:
builder.NewAgent("my-agent").WithOutputSchema(map[string]any{
"type": "object",
"properties": map[string]any{
"answer": map[string]any{"type": "string"},
},
})
func (*AgentBuilder) WithReasoning ¶
func (b *AgentBuilder) WithReasoning(reasoning *llmagent.ReasoningConfig) *AgentBuilder
WithReasoning sets the reasoning configuration.
Example:
reasoning := builder.NewReasoning().MaxIterations(50).Build()
builder.NewAgent("my-agent").WithReasoning(reasoning)
func (*AgentBuilder) WithReasoningBuilder ¶
func (b *AgentBuilder) WithReasoningBuilder(rb *ReasoningBuilder) *AgentBuilder
WithReasoningBuilder sets reasoning from a builder (convenience method).
Example:
builder.NewAgent("my-agent").WithReasoningBuilder(
builder.NewReasoning().MaxIterations(50),
)
func (*AgentBuilder) WithSubAgent ¶
func (b *AgentBuilder) WithSubAgent(ag agent.Agent) *AgentBuilder
WithSubAgent adds a sub-agent for task delegation (Pattern 1: Transfer). Transfer tools are automatically created for each sub-agent.
Example:
builder.NewAgent("coordinator").WithSubAgent(researcher)
func (*AgentBuilder) WithSubAgents ¶
func (b *AgentBuilder) WithSubAgents(agents ...agent.Agent) *AgentBuilder
WithSubAgents adds multiple sub-agents.
Example:
builder.NewAgent("coordinator").WithSubAgents(researcher, writer)
func (*AgentBuilder) WithTool ¶
func (b *AgentBuilder) WithTool(t tool.Tool) *AgentBuilder
WithTool adds a single tool to the agent.
Example:
builder.NewAgent("my-agent").WithTool(myTool)
func (*AgentBuilder) WithTools ¶
func (b *AgentBuilder) WithTools(tools ...tool.Tool) *AgentBuilder
WithTools adds multiple tools to the agent.
Example:
builder.NewAgent("my-agent").WithTools(tool1, tool2, tool3)
func (*AgentBuilder) WithToolset ¶
func (b *AgentBuilder) WithToolset(ts tool.Toolset) *AgentBuilder
WithToolset adds a toolset to the agent.
Example:
builder.NewAgent("my-agent").WithToolset(myToolset)
func (*AgentBuilder) WithToolsets ¶
func (b *AgentBuilder) WithToolsets(toolsets ...tool.Toolset) *AgentBuilder
WithToolsets adds multiple toolsets to the agent.
Example:
builder.NewAgent("my-agent").WithToolsets(toolset1, toolset2)
func (*AgentBuilder) WithWorkingMemory ¶
func (b *AgentBuilder) WithWorkingMemory(strategy memory.WorkingMemoryStrategy) *AgentBuilder
WithWorkingMemory sets the working memory strategy.
Example:
strategy, _ := builder.NewWorkingMemory("summary_buffer").WithLLM(llm).Build()
builder.NewAgent("my-agent").WithWorkingMemory(strategy)
type AuthBuilder ¶
type AuthBuilder struct {
// contains filtered or unexported fields
}
AuthBuilder provides a fluent API for building authentication configuration.
Example:
auth := builder.NewAuth().
JWKSURL("https://auth.example.com/.well-known/jwks.json").
Issuer("https://auth.example.com").
Audience("hector-api").
Build()
func NewAuth ¶
func NewAuth() *AuthBuilder
NewAuth creates a new authentication configuration builder.
Example:
auth := builder.NewAuth().
JWKSURL("https://auth.example.com/.well-known/jwks.json").
Issuer("https://auth.example.com").
Audience("hector-api").
Build()
func (*AuthBuilder) AddExcludedPath ¶
func (b *AuthBuilder) AddExcludedPath(path string) *AuthBuilder
AddExcludedPath adds a path to the excluded paths list.
Example:
builder.NewAuth().AddExcludedPath("/public")
func (*AuthBuilder) Audience ¶
func (b *AuthBuilder) Audience(audience string) *AuthBuilder
Audience sets the expected JWT audience (aud claim).
Example:
builder.NewAuth().Audience("hector-api")
func (*AuthBuilder) Build ¶
func (b *AuthBuilder) Build() *config.AuthConfig
Build creates the authentication configuration.
func (*AuthBuilder) Enabled ¶
func (b *AuthBuilder) Enabled(enabled bool) *AuthBuilder
Enabled enables or disables authentication.
Example:
builder.NewAuth().Enabled(true)
func (*AuthBuilder) ExcludedPaths ¶
func (b *AuthBuilder) ExcludedPaths(paths ...string) *AuthBuilder
ExcludedPaths sets paths excluded from authentication.
Example:
builder.NewAuth().ExcludedPaths("/health", "/ready")
func (*AuthBuilder) Issuer ¶
func (b *AuthBuilder) Issuer(issuer string) *AuthBuilder
Issuer sets the expected JWT issuer (iss claim).
Example:
builder.NewAuth().Issuer("https://auth.example.com")
func (*AuthBuilder) JWKSURL ¶
func (b *AuthBuilder) JWKSURL(url string) *AuthBuilder
JWKSURL sets the JSON Web Key Set URL for token validation.
Example:
builder.NewAuth().JWKSURL("https://auth.example.com/.well-known/jwks.json")
func (*AuthBuilder) RefreshInterval ¶
func (b *AuthBuilder) RefreshInterval(interval time.Duration) *AuthBuilder
RefreshInterval sets how often to refresh the JWKS.
Example:
builder.NewAuth().RefreshInterval(10 * time.Minute)
func (*AuthBuilder) RequireAuth ¶
func (b *AuthBuilder) RequireAuth(require bool) *AuthBuilder
RequireAuth sets whether authentication is mandatory. When false, unauthenticated requests proceed with nil user.
Example:
builder.NewAuth().RequireAuth(true)
type CredentialsBuilder ¶
type CredentialsBuilder struct {
// contains filtered or unexported fields
}
CredentialsBuilder provides a fluent API for building credentials configuration.
Example:
creds := builder.NewCredentials().
Type("bearer").
Token("my-token").
Build()
func NewCredentials ¶
func NewCredentials() *CredentialsBuilder
NewCredentials creates a new credentials builder.
Example:
creds := builder.NewCredentials().Type("bearer").Token("token").Build()
func (*CredentialsBuilder) APIKey ¶
func (b *CredentialsBuilder) APIKey(key string) *CredentialsBuilder
APIKey sets the API key (for type: api_key).
Example:
builder.NewCredentials().Type("api_key").APIKey("my-key")
func (*CredentialsBuilder) APIKeyHeader ¶
func (b *CredentialsBuilder) APIKeyHeader(header string) *CredentialsBuilder
APIKeyHeader sets the header name for API key (default: X-API-Key).
Example:
builder.NewCredentials().Type("api_key").APIKeyHeader("Authorization")
func (*CredentialsBuilder) Build ¶
func (b *CredentialsBuilder) Build() *config.CredentialsConfig
Build creates the credentials configuration.
func (*CredentialsBuilder) Password ¶
func (b *CredentialsBuilder) Password(pass string) *CredentialsBuilder
Password sets the password (for type: basic).
Example:
builder.NewCredentials().Type("basic").Password("pass")
func (*CredentialsBuilder) Token ¶
func (b *CredentialsBuilder) Token(token string) *CredentialsBuilder
Token sets the bearer token (for type: bearer).
Example:
builder.NewCredentials().Type("bearer").Token("my-token")
func (*CredentialsBuilder) Type ¶
func (b *CredentialsBuilder) Type(typ string) *CredentialsBuilder
Type sets the credential type: "bearer", "api_key", or "basic".
Example:
builder.NewCredentials().Type("api_key")
func (*CredentialsBuilder) Username ¶
func (b *CredentialsBuilder) Username(user string) *CredentialsBuilder
Username sets the username (for type: basic).
Example:
builder.NewCredentials().Type("basic").Username("user")
type DocumentStoreBuilder ¶
type DocumentStoreBuilder struct {
// contains filtered or unexported fields
}
DocumentStoreBuilder provides a fluent API for building RAG document stores.
Document stores index documents from various sources for semantic search. They combine:
- Data source: Where documents come from
- Search engine: How to index and search (embeddings + vector store)
- Chunking: How to split documents
Example:
store, err := builder.NewDocumentStore("docs").
FromDirectory("./documents").
WithVectorProvider(vectorProvider).
WithEmbedder(embedder).
EnableWatching(true).
Build()
func NewDocumentStore ¶
func NewDocumentStore(name string) *DocumentStoreBuilder
NewDocumentStore creates a new document store builder.
Example:
store, err := builder.NewDocumentStore("my-docs").
FromDirectory("./docs").
WithVectorProvider(provider).
WithEmbedder(emb).
Build()
func (*DocumentStoreBuilder) Build ¶
func (b *DocumentStoreBuilder) Build() (*rag.DocumentStore, error)
Build creates the document store.
Returns an error if required parameters are missing.
func (*DocumentStoreBuilder) ChunkOverlap ¶
func (b *DocumentStoreBuilder) ChunkOverlap(overlap int) *DocumentStoreBuilder
ChunkOverlap sets the overlap between chunks.
Example:
builder.NewDocumentStore("docs").ChunkOverlap(100)
func (*DocumentStoreBuilder) ChunkSize ¶
func (b *DocumentStoreBuilder) ChunkSize(size int) *DocumentStoreBuilder
ChunkSize sets the size of document chunks.
Example:
builder.NewDocumentStore("docs").ChunkSize(1000)
func (*DocumentStoreBuilder) Collection ¶
func (b *DocumentStoreBuilder) Collection(collection string) *DocumentStoreBuilder
Collection sets the vector collection name.
Example:
builder.NewDocumentStore("docs").Collection("documents")
func (*DocumentStoreBuilder) DefaultThreshold ¶
func (b *DocumentStoreBuilder) DefaultThreshold(score float32) *DocumentStoreBuilder
DefaultThreshold sets the minimum similarity score for search results.
Example:
builder.NewDocumentStore("docs").DefaultThreshold(0.5)
func (*DocumentStoreBuilder) DefaultTopK ¶
func (b *DocumentStoreBuilder) DefaultTopK(k int) *DocumentStoreBuilder
DefaultTopK sets the default number of results to return in searches.
Example:
builder.NewDocumentStore("docs").DefaultTopK(10)
func (*DocumentStoreBuilder) Description ¶
func (b *DocumentStoreBuilder) Description(desc string) *DocumentStoreBuilder
Description sets the store description.
Example:
builder.NewDocumentStore("docs").Description("Product documentation")
func (*DocumentStoreBuilder) EnableCheckpoints ¶
func (b *DocumentStoreBuilder) EnableCheckpoints(enabled bool) *DocumentStoreBuilder
EnableCheckpoints enables checkpoint/resume for interrupted indexing.
Example:
builder.NewDocumentStore("docs").EnableCheckpoints(true)
func (*DocumentStoreBuilder) EnableHyDE ¶
func (b *DocumentStoreBuilder) EnableHyDE(enabled bool) *DocumentStoreBuilder
EnableHyDE enables Hypothetical Document Embeddings for better search.
Example:
builder.NewDocumentStore("docs").EnableHyDE(true)
func (*DocumentStoreBuilder) EnableIncremental ¶
func (b *DocumentStoreBuilder) EnableIncremental(enabled bool) *DocumentStoreBuilder
EnableIncremental enables incremental indexing (only changed files).
Example:
builder.NewDocumentStore("docs").EnableIncremental(true)
func (*DocumentStoreBuilder) EnableMultiQuery ¶
func (b *DocumentStoreBuilder) EnableMultiQuery(enabled bool) *DocumentStoreBuilder
EnableMultiQuery enables query expansion for better recall.
Example:
builder.NewDocumentStore("docs").EnableMultiQuery(true)
func (*DocumentStoreBuilder) EnableProgress ¶
func (b *DocumentStoreBuilder) EnableProgress(enabled bool) *DocumentStoreBuilder
EnableProgress enables progress display during indexing.
Example:
builder.NewDocumentStore("docs").EnableProgress(true)
func (*DocumentStoreBuilder) EnableRerank ¶
func (b *DocumentStoreBuilder) EnableRerank(enabled bool) *DocumentStoreBuilder
EnableRerank enables LLM-based result reranking.
Example:
builder.NewDocumentStore("docs").EnableRerank(true)
func (*DocumentStoreBuilder) EnableWatching ¶
func (b *DocumentStoreBuilder) EnableWatching(enabled bool) *DocumentStoreBuilder
EnableWatching enables file watching for automatic re-indexing.
Example:
builder.NewDocumentStore("docs").EnableWatching(true)
func (*DocumentStoreBuilder) ExcludePatterns ¶
func (b *DocumentStoreBuilder) ExcludePatterns(patterns ...string) *DocumentStoreBuilder
ExcludePatterns sets glob patterns for file exclusion.
Example:
builder.NewDocumentStore("docs").ExcludePatterns("*.tmp", "node_modules/**")
func (*DocumentStoreBuilder) FromDirectory ¶
func (b *DocumentStoreBuilder) FromDirectory(path string) *DocumentStoreBuilder
FromDirectory configures a directory source.
Example:
builder.NewDocumentStore("docs").FromDirectory("./documents")
func (*DocumentStoreBuilder) IncludePatterns ¶
func (b *DocumentStoreBuilder) IncludePatterns(patterns ...string) *DocumentStoreBuilder
IncludePatterns sets glob patterns for file inclusion.
Example:
builder.NewDocumentStore("docs").IncludePatterns("*.md", "*.txt")
func (*DocumentStoreBuilder) MaxConcurrent ¶
func (b *DocumentStoreBuilder) MaxConcurrent(max int) *DocumentStoreBuilder
MaxConcurrent sets the maximum concurrent indexing workers. Default is NumCPU.
Example:
builder.NewDocumentStore("docs").MaxConcurrent(4)
func (*DocumentStoreBuilder) MaxFileSize ¶
func (b *DocumentStoreBuilder) MaxFileSize(size int64) *DocumentStoreBuilder
MaxFileSize sets the maximum file size to process (in bytes). Files larger than this will be skipped. 0 means no limit.
Example:
builder.NewDocumentStore("docs").MaxFileSize(10 * 1024 * 1024) // 10MB
func (*DocumentStoreBuilder) MustBuild ¶
func (b *DocumentStoreBuilder) MustBuild() *rag.DocumentStore
MustBuild creates the document store or panics on error.
Use this only when you're certain the configuration is valid.
func (*DocumentStoreBuilder) WithEmbedder ¶
func (b *DocumentStoreBuilder) WithEmbedder(emb embedder.Embedder) *DocumentStoreBuilder
WithEmbedder sets the embedding provider.
Example:
emb, _ := builder.NewEmbedder("openai").Build()
builder.NewDocumentStore("docs").WithEmbedder(emb)
func (*DocumentStoreBuilder) WithVectorProvider ¶
func (b *DocumentStoreBuilder) WithVectorProvider(provider vector.Provider) *DocumentStoreBuilder
WithVectorProvider sets the vector database provider.
Example:
provider, _ := builder.NewVectorProvider("chromem").Build()
builder.NewDocumentStore("docs").WithVectorProvider(provider)
type EmbedderBuilder ¶
type EmbedderBuilder struct {
// contains filtered or unexported fields
}
EmbedderBuilder provides a fluent API for building embedders.
Embedders convert text to vector embeddings for semantic search. They're used by memory systems and RAG components.
Example:
emb, err := builder.NewEmbedder("openai").
Model("text-embedding-3-small").
APIKeyFromEnv("OPENAI_API_KEY").
Build()
func EmbedderFromConfig ¶
func EmbedderFromConfig(cfg *config.EmbedderConfig) *EmbedderBuilder
EmbedderFromConfig creates an EmbedderBuilder from a config.EmbedderConfig. This allows the configuration system to use the builder as its foundation.
Example:
cfg := &config.EmbedderConfig{Provider: "openai", Model: "text-embedding-3-small"}
emb, err := builder.EmbedderFromConfig(cfg).Build()
func NewEmbedder ¶
func NewEmbedder(providerType string) *EmbedderBuilder
NewEmbedder creates a new embedder builder.
Supported providers: "openai", "ollama", "cohere"
Example:
emb, err := builder.NewEmbedder("openai").
Model("text-embedding-3-small").
APIKeyFromEnv("OPENAI_API_KEY").
Build()
func (*EmbedderBuilder) APIKey ¶
func (b *EmbedderBuilder) APIKey(key string) *EmbedderBuilder
APIKey sets the API key directly.
Example:
builder.NewEmbedder("openai").APIKey("sk-...")
func (*EmbedderBuilder) APIKeyFromEnv ¶
func (b *EmbedderBuilder) APIKeyFromEnv(envVar string) *EmbedderBuilder
APIKeyFromEnv sets the API key from an environment variable.
Example:
builder.NewEmbedder("openai").APIKeyFromEnv("OPENAI_API_KEY")
func (*EmbedderBuilder) BaseURL ¶
func (b *EmbedderBuilder) BaseURL(url string) *EmbedderBuilder
BaseURL sets the API base URL.
Example:
builder.NewEmbedder("openai").BaseURL("https://api.custom.com/v1")
func (*EmbedderBuilder) BatchSize ¶
func (b *EmbedderBuilder) BatchSize(size int) *EmbedderBuilder
BatchSize sets the batch size for embedding requests.
Example:
builder.NewEmbedder("openai").BatchSize(50)
func (*EmbedderBuilder) Build ¶
func (b *EmbedderBuilder) Build() (embedder.Embedder, error)
Build creates the embedder.
Returns an error if required parameters are missing or invalid.
func (*EmbedderBuilder) Dimension ¶
func (b *EmbedderBuilder) Dimension(dim int) *EmbedderBuilder
Dimension sets the expected embedding dimension. This is usually auto-detected but can be overridden.
Example:
builder.NewEmbedder("openai").Dimension(3072)
func (*EmbedderBuilder) EncodingFormat ¶
func (b *EmbedderBuilder) EncodingFormat(format string) *EmbedderBuilder
EncodingFormat sets the encoding format for OpenAI API. Values: "float" (default), "base64"
Example:
builder.NewEmbedder("openai").EncodingFormat("float")
func (*EmbedderBuilder) InputType ¶
func (b *EmbedderBuilder) InputType(inputType string) *EmbedderBuilder
InputType sets the input type for Cohere v3+ models. Values: "search_document", "search_query", "classification", "clustering"
Example:
builder.NewEmbedder("cohere").InputType("search_document")
func (*EmbedderBuilder) Model ¶
func (b *EmbedderBuilder) Model(model string) *EmbedderBuilder
Model sets the embedding model name.
Example:
builder.NewEmbedder("openai").Model("text-embedding-3-large")
func (*EmbedderBuilder) MustBuild ¶
func (b *EmbedderBuilder) MustBuild() embedder.Embedder
MustBuild creates the embedder or panics on error.
Use this only when you're certain the configuration is valid.
func (*EmbedderBuilder) OutputDimension ¶
func (b *EmbedderBuilder) OutputDimension(dim int) *EmbedderBuilder
OutputDimension sets the output dimension for Cohere v4+ models. Values: 256, 512, 1024, 1536
Example:
builder.NewEmbedder("cohere").OutputDimension(1024)
func (*EmbedderBuilder) Timeout ¶
func (b *EmbedderBuilder) Timeout(seconds int) *EmbedderBuilder
Timeout sets the API request timeout in seconds.
Example:
builder.NewEmbedder("openai").Timeout(60)
func (*EmbedderBuilder) Truncate ¶
func (b *EmbedderBuilder) Truncate(truncate string) *EmbedderBuilder
Truncate sets the truncation strategy for Cohere API. Values: "NONE", "START", "END" (default: "END")
Example:
builder.NewEmbedder("cohere").Truncate("END")
func (*EmbedderBuilder) User ¶
func (b *EmbedderBuilder) User(user string) *EmbedderBuilder
User sets the end-user identifier for OpenAI API.
Example:
builder.NewEmbedder("openai").User("user-123")
type LLMBuilder ¶
type LLMBuilder struct {
// contains filtered or unexported fields
}
LLMBuilder provides a fluent API for building LLM providers.
Example:
llm, err := builder.NewLLM("openai").
Model("gpt-4o-mini").
APIKeyFromEnv("OPENAI_API_KEY").
Temperature(0.7).
MaxTokens(4000).
Build()
func LLMFromConfig ¶
func LLMFromConfig(cfg *config.LLMConfig) *LLMBuilder
LLMFromConfig creates an LLMBuilder from a config.LLMConfig. This allows the configuration system to use the builder as its foundation.
Example:
cfg := &config.LLMConfig{Provider: "openai", Model: "gpt-4o", APIKey: "sk-..."}
llm, err := builder.LLMFromConfig(cfg).Build()
func NewLLM ¶
func NewLLM(providerType string) *LLMBuilder
NewLLM creates a new LLM builder.
Supported providers: "openai", "anthropic", "gemini", "ollama"
Example:
llm, err := builder.NewLLM("anthropic").
Model("claude-sonnet-4-20250514").
APIKeyFromEnv("ANTHROPIC_API_KEY").
Build()
func (*LLMBuilder) APIKey ¶
func (b *LLMBuilder) APIKey(key string) *LLMBuilder
APIKey sets the API key directly.
Example:
builder.NewLLM("openai").APIKey("sk-...")
func (*LLMBuilder) APIKeyFromEnv ¶
func (b *LLMBuilder) APIKeyFromEnv(envVar string) *LLMBuilder
APIKeyFromEnv sets the API key from an environment variable.
Example:
builder.NewLLM("openai").APIKeyFromEnv("OPENAI_API_KEY")
func (*LLMBuilder) BaseURL ¶
func (b *LLMBuilder) BaseURL(url string) *LLMBuilder
BaseURL sets the API base URL.
Example:
builder.NewLLM("openai").BaseURL("https://api.custom.com/v1")
func (*LLMBuilder) Build ¶
func (b *LLMBuilder) Build() (model.LLM, error)
Build creates the LLM provider.
Returns an error if required parameters are missing or invalid.
func (*LLMBuilder) EnableThinking ¶
func (b *LLMBuilder) EnableThinking(enable bool) *LLMBuilder
EnableThinking enables thinking/reasoning mode. Supported by Anthropic (extended thinking) and OpenAI (o-series reasoning).
Example:
builder.NewLLM("anthropic").
Model("claude-sonnet-4-20250514").
EnableThinking(true).
ThinkingBudget(10000)
func (*LLMBuilder) MaxRetries ¶
func (b *LLMBuilder) MaxRetries(max int) *LLMBuilder
MaxRetries sets the maximum number of retries.
Example:
builder.NewLLM("openai").MaxRetries(5)
func (*LLMBuilder) MaxTokens ¶
func (b *LLMBuilder) MaxTokens(max int) *LLMBuilder
MaxTokens sets the maximum output tokens.
Example:
builder.NewLLM("openai").MaxTokens(4000)
func (*LLMBuilder) MaxToolOutputLength ¶
func (b *LLMBuilder) MaxToolOutputLength(max int) *LLMBuilder
MaxToolOutputLength sets the maximum length for tool outputs.
Example:
builder.NewLLM("openai").MaxToolOutputLength(50000)
func (*LLMBuilder) Model ¶
func (b *LLMBuilder) Model(model string) *LLMBuilder
Model sets the model name.
Example:
builder.NewLLM("openai").Model("gpt-4o")
func (*LLMBuilder) MustBuild ¶
func (b *LLMBuilder) MustBuild() model.LLM
MustBuild creates the LLM provider or panics on error.
Use this only when you're certain the configuration is valid.
func (*LLMBuilder) Temperature ¶
func (b *LLMBuilder) Temperature(temp float64) *LLMBuilder
Temperature sets the sampling temperature (0.0 to 2.0).
Example:
builder.NewLLM("openai").Temperature(0.7)
func (*LLMBuilder) ThinkingBudget ¶
func (b *LLMBuilder) ThinkingBudget(budget int) *LLMBuilder
ThinkingBudget sets the token budget for thinking.
Example:
builder.NewLLM("anthropic").ThinkingBudget(10000)
func (*LLMBuilder) Timeout ¶
func (b *LLMBuilder) Timeout(timeout time.Duration) *LLMBuilder
Timeout sets the request timeout.
Example:
builder.NewLLM("openai").Timeout(2 * time.Minute)
type MCPBuilder ¶
type MCPBuilder struct {
// contains filtered or unexported fields
}
MCPBuilder provides a fluent API for building MCP toolsets.
MCP (Model Context Protocol) toolsets connect to external MCP servers to provide tools dynamically.
Example:
toolset, err := builder.NewMCP("weather").
URL("http://localhost:9000").
Transport("sse").
Build()
func MCPFromConfig ¶
func MCPFromConfig(name string, cfg *config.ToolConfig) *MCPBuilder
MCPFromConfig creates an MCPBuilder from a config.ToolConfig. This allows the configuration system to use the builder as its foundation.
Example:
cfg := &config.ToolConfig{Type: "mcp", URL: "http://localhost:9000", Transport: "sse"}
ts, err := builder.MCPFromConfig("weather", cfg).Build()
func NewMCP ¶
func NewMCP(name string) *MCPBuilder
NewMCP creates a new MCP toolset builder.
Example:
// SSE transport
toolset, _ := builder.NewMCP("weather").
URL("http://localhost:9000").
Build()
// Stdio transport
toolset, _ := builder.NewMCP("filesystem").
Command("npx", "-y", "@modelcontextprotocol/server-filesystem", "/tmp").
Build()
func (*MCPBuilder) Build ¶
func (b *MCPBuilder) Build() (*mcptoolset.Toolset, error)
Build creates the MCP toolset.
Returns an error if required parameters are missing.
func (*MCPBuilder) Command ¶
func (b *MCPBuilder) Command(cmd string, args ...string) *MCPBuilder
Command sets the command and arguments for stdio transport.
Example:
builder.NewMCP("fs").Command("npx", "-y", "@modelcontextprotocol/server-filesystem", "/tmp")
func (*MCPBuilder) Env ¶
func (b *MCPBuilder) Env(env map[string]string) *MCPBuilder
Env sets environment variables for stdio transport.
Example:
builder.NewMCP("fs").Env(map[string]string{"DEBUG": "1"})
func (*MCPBuilder) Filter ¶
func (b *MCPBuilder) Filter(tools ...string) *MCPBuilder
Filter limits which tools from the MCP server are exposed.
Example:
builder.NewMCP("weather").Filter("get_weather", "get_forecast")
func (*MCPBuilder) MustBuild ¶
func (b *MCPBuilder) MustBuild() *mcptoolset.Toolset
MustBuild creates the MCP toolset or panics on error.
Use this only when you're certain the configuration is valid.
func (*MCPBuilder) Transport ¶
func (b *MCPBuilder) Transport(transport string) *MCPBuilder
Transport sets the transport type: "sse", "stdio", or "streamable-http".
Example:
builder.NewMCP("weather").Transport("streamable-http")
func (*MCPBuilder) URL ¶
func (b *MCPBuilder) URL(url string) *MCPBuilder
URL sets the server URL for SSE or HTTP transports.
Example:
builder.NewMCP("weather").URL("http://localhost:9000")
type ReasoningBuilder ¶
type ReasoningBuilder struct {
// contains filtered or unexported fields
}
ReasoningBuilder provides a fluent API for building reasoning configuration.
Example:
reasoning := builder.NewReasoning().
MaxIterations(100).
EnableExitTool(true).
EnableEscalateTool(true).
CompletionInstruction("Call exit_loop when done.").
Build()
func NewReasoning ¶
func NewReasoning() *ReasoningBuilder
NewReasoning creates a new reasoning configuration builder.
Example:
reasoning := builder.NewReasoning().
MaxIterations(50).
Build()
func (*ReasoningBuilder) Build ¶
func (b *ReasoningBuilder) Build() *llmagent.ReasoningConfig
Build creates the reasoning configuration.
func (*ReasoningBuilder) CompletionInstruction ¶
func (b *ReasoningBuilder) CompletionInstruction(instruction string) *ReasoningBuilder
CompletionInstruction sets a custom instruction appended to help the model know when to stop.
Example:
builder.NewReasoning().CompletionInstruction("Call exit_loop when you have a final answer.")
func (*ReasoningBuilder) EnableEscalateTool ¶
func (b *ReasoningBuilder) EnableEscalateTool(enable bool) *ReasoningBuilder
EnableEscalateTool adds the escalate tool for parent delegation. When enabled, the agent can escalate to a higher-level agent.
Example:
builder.NewReasoning().EnableEscalateTool(true)
func (*ReasoningBuilder) EnableExitTool ¶
func (b *ReasoningBuilder) EnableExitTool(enable bool) *ReasoningBuilder
EnableExitTool adds the exit_loop tool for explicit termination. When enabled, the agent can call exit_loop to signal task completion.
Example:
builder.NewReasoning().EnableExitTool(true)
func (*ReasoningBuilder) MaxIterations ¶
func (b *ReasoningBuilder) MaxIterations(max int) *ReasoningBuilder
MaxIterations sets the maximum number of reasoning iterations. This is a SAFETY limit, not the primary termination condition. The loop terminates when semantic conditions are met (no tool calls, etc.)
Default: 100 (high enough to not interfere with normal operation)
Example:
builder.NewReasoning().MaxIterations(50)
type RunnerBuilder ¶
type RunnerBuilder struct {
// contains filtered or unexported fields
}
RunnerBuilder provides a fluent API for building runners.
Runners orchestrate agent execution within sessions, handling:
- Session creation and retrieval
- Agent selection based on session history
- Event streaming and persistence
Example:
r, err := builder.NewRunner("my-app").
WithAgent(myAgent).
WithSessionService(session.InMemoryService()).
Build()
func NewRunner ¶
func NewRunner(appName string) *RunnerBuilder
NewRunner creates a new runner builder.
Example:
r, err := builder.NewRunner("my-app").
WithAgent(myAgent).
Build()
func (*RunnerBuilder) Build ¶
func (b *RunnerBuilder) Build() (*runner.Runner, error)
Build creates the runner.
Returns an error if required parameters are missing.
func (*RunnerBuilder) MustBuild ¶
func (b *RunnerBuilder) MustBuild() *runner.Runner
MustBuild creates the runner or panics on error.
Use this only when you're certain the configuration is valid.
func (*RunnerBuilder) WithAgent ¶
func (b *RunnerBuilder) WithAgent(ag agent.Agent) *RunnerBuilder
WithAgent sets the root agent for execution.
Example:
builder.NewRunner("app").WithAgent(myAgent)
func (*RunnerBuilder) WithCheckpointManager ¶
func (b *RunnerBuilder) WithCheckpointManager(mgr runner.CheckpointManager) *RunnerBuilder
WithCheckpointManager sets the checkpoint manager for fault tolerance.
Example:
builder.NewRunner("app").WithCheckpointManager(checkpointMgr)
func (*RunnerBuilder) WithIndexService ¶
func (b *RunnerBuilder) WithIndexService(svc runner.IndexService) *RunnerBuilder
WithIndexService sets the index service for semantic search.
Example:
builder.NewRunner("app").WithIndexService(indexSvc)
func (*RunnerBuilder) WithMemoryIndex ¶
func (b *RunnerBuilder) WithMemoryIndex(idx memory.IndexService) *RunnerBuilder
WithMemoryIndex sets up memory indexing with the provided index service. This is a convenience method that wraps memory.IndexService.
Example:
indexSvc := memory.NewKeywordIndexService()
builder.NewRunner("app").WithMemoryIndex(indexSvc)
func (*RunnerBuilder) WithSessionService ¶
func (b *RunnerBuilder) WithSessionService(svc session.Service) *RunnerBuilder
WithSessionService sets the session service for persistence. If not set, an in-memory service will be used.
Example:
builder.NewRunner("app").WithSessionService(session.InMemoryService())
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents a built A2A server.
func (*Server) ListenAndServe ¶
ListenAndServe starts the HTTP server.
type ServerBuilder ¶
type ServerBuilder struct {
// contains filtered or unexported fields
}
ServerBuilder provides a fluent API for building A2A servers.
Servers expose agents via the A2A (Agent-to-Agent) protocol, supporting JSON-RPC, gRPC, and HTTP transports.
Example:
srv, err := builder.NewServer().
WithRunner(myRunner).
Address(":8080").
Build()
func NewServer ¶
func NewServer() *ServerBuilder
NewServer creates a new server builder.
Example:
srv, err := builder.NewServer().
WithRunner(r).
Address(":8080").
Build()
func (*ServerBuilder) Address ¶
func (b *ServerBuilder) Address(addr string) *ServerBuilder
Address sets the server listen address.
Example:
builder.NewServer().Address(":9000")
func (*ServerBuilder) Build ¶
func (b *ServerBuilder) Build() (http.Handler, error)
Build creates the HTTP handler for the server.
Returns an error if required parameters are missing.
func (*ServerBuilder) BuildServer ¶
func (b *ServerBuilder) BuildServer() (*Server, error)
BuildServer creates a complete server ready to serve.
Example:
srv, _ := builder.NewServer().
WithRunner(r).
BuildServer()
srv.ListenAndServe()
func (*ServerBuilder) EnableStreaming ¶
func (b *ServerBuilder) EnableStreaming(enabled bool) *ServerBuilder
EnableStreaming enables streaming responses.
Example:
builder.NewServer().EnableStreaming(true)
func (*ServerBuilder) EnableUI ¶
func (b *ServerBuilder) EnableUI(enabled bool) *ServerBuilder
EnableUI enables the built-in web UI.
Example:
builder.NewServer().EnableUI(true)
func (*ServerBuilder) MustBuildServer ¶
func (b *ServerBuilder) MustBuildServer() *Server
MustBuildServer creates the server or panics on error.
func (*ServerBuilder) WithRunner ¶
func (b *ServerBuilder) WithRunner(r *runner.Runner) *ServerBuilder
WithRunner sets the runner for the server.
Example:
builder.NewServer().WithRunner(myRunner)
type ToolsetBuilder ¶
type ToolsetBuilder struct {
// contains filtered or unexported fields
}
ToolsetBuilder wraps multiple tools into a toolset.
Example:
toolset := builder.NewToolset("my-tools").
WithTool(tool1).
WithTool(tool2).
Build()
func NewToolset ¶
func NewToolset(name string) *ToolsetBuilder
NewToolset creates a new toolset builder.
Example:
toolset := builder.NewToolset("custom-tools").
WithTool(myTool).
Build()
func (*ToolsetBuilder) Build ¶
func (b *ToolsetBuilder) Build() tool.Toolset
Build creates the toolset.
func (*ToolsetBuilder) WithTool ¶
func (b *ToolsetBuilder) WithTool(t tool.Tool) *ToolsetBuilder
WithTool adds a tool to the toolset.
Example:
builder.NewToolset("tools").WithTool(myTool)
func (*ToolsetBuilder) WithTools ¶
func (b *ToolsetBuilder) WithTools(tools ...tool.Tool) *ToolsetBuilder
WithTools adds multiple tools to the toolset.
Example:
builder.NewToolset("tools").WithTools(tool1, tool2, tool3)
type VectorProviderBuilder ¶
type VectorProviderBuilder struct {
// contains filtered or unexported fields
}
VectorProviderBuilder provides a fluent API for building vector database providers.
Vector providers store and search embeddings for RAG and memory systems.
Example:
provider, err := builder.NewVectorProvider("chromem").
PersistPath(".hector/vectors").
Compress(true).
Build()
func NewVectorProvider ¶
func NewVectorProvider(providerType string) *VectorProviderBuilder
NewVectorProvider creates a new vector provider builder.
Supported providers: "chromem", "qdrant", "chroma", "pinecone", "milvus", "weaviate"
Example:
// Local embedded provider (chromem)
provider, err := builder.NewVectorProvider("chromem").
PersistPath(".hector/vectors").
Build()
// Cloud provider (Qdrant)
provider, err := builder.NewVectorProvider("qdrant").
Host("localhost").
Port(6334).
Build()
func (*VectorProviderBuilder) APIKey ¶
func (b *VectorProviderBuilder) APIKey(key string) *VectorProviderBuilder
APIKey sets the API key for cloud providers.
Example:
builder.NewVectorProvider("pinecone").APIKey("pk-...")
func (*VectorProviderBuilder) Build ¶
func (b *VectorProviderBuilder) Build() (vector.Provider, error)
Build creates the vector provider.
Returns an error if required parameters are missing or the provider is not implemented.
func (*VectorProviderBuilder) Compress ¶
func (b *VectorProviderBuilder) Compress(compress bool) *VectorProviderBuilder
Compress enables/disables compression for persistent storage (chromem).
Example:
builder.NewVectorProvider("chromem").Compress(true)
func (*VectorProviderBuilder) Host ¶
func (b *VectorProviderBuilder) Host(host string) *VectorProviderBuilder
Host sets the server host for remote providers.
Example:
builder.NewVectorProvider("qdrant").Host("qdrant.example.com")
func (*VectorProviderBuilder) IndexName ¶
func (b *VectorProviderBuilder) IndexName(name string) *VectorProviderBuilder
IndexName sets the index name (Pinecone).
Example:
builder.NewVectorProvider("pinecone").IndexName("my-index")
func (*VectorProviderBuilder) MustBuild ¶
func (b *VectorProviderBuilder) MustBuild() vector.Provider
MustBuild creates the vector provider or panics on error.
Use this only when you're certain the configuration is valid.
func (*VectorProviderBuilder) PersistPath ¶
func (b *VectorProviderBuilder) PersistPath(path string) *VectorProviderBuilder
PersistPath sets the file path for persistent storage (chromem).
Example:
builder.NewVectorProvider("chromem").PersistPath(".hector/vectors")
func (*VectorProviderBuilder) Port ¶
func (b *VectorProviderBuilder) Port(port int) *VectorProviderBuilder
Port sets the server port for remote providers.
Example:
builder.NewVectorProvider("qdrant").Port(6333)
func (*VectorProviderBuilder) UseTLS ¶
func (b *VectorProviderBuilder) UseTLS(useTLS bool) *VectorProviderBuilder
UseTLS enables TLS for secure connections.
Example:
builder.NewVectorProvider("qdrant").UseTLS(true)
type WorkingMemoryBuilder ¶
type WorkingMemoryBuilder struct {
// contains filtered or unexported fields
}
WorkingMemoryBuilder provides a fluent API for building working memory strategies.
Example:
strategy, err := builder.NewWorkingMemory("summary_buffer").
Budget(8000).
Threshold(0.85).
WithLLM(llm).
Build()
func NewWorkingMemory ¶
func NewWorkingMemory(strategyType string) *WorkingMemoryBuilder
NewWorkingMemory creates a new working memory builder.
Supported strategies:
- "buffer_window": Simple sliding window of recent messages
- "token_window": Token-based window management
- "summary_buffer": Summarization-based memory (requires LLM)
Example:
strategy, err := builder.NewWorkingMemory("buffer_window").
WindowSize(20).
Build()
func WorkingMemoryFromConfig ¶
func WorkingMemoryFromConfig(cfg *config.ContextConfig) *WorkingMemoryBuilder
WorkingMemoryFromConfig creates a WorkingMemoryBuilder from a config.ContextConfig. This allows the configuration system to use the builder as its foundation.
Example:
cfg := &config.ContextConfig{Strategy: "buffer_window", WindowSize: 20}
strategy, err := builder.WorkingMemoryFromConfig(cfg).Build()
func (*WorkingMemoryBuilder) Budget ¶
func (b *WorkingMemoryBuilder) Budget(budget int) *WorkingMemoryBuilder
Budget sets the token budget for summary_buffer strategy.
Example:
builder.NewWorkingMemory("summary_buffer").Budget(8000)
func (*WorkingMemoryBuilder) Build ¶
func (b *WorkingMemoryBuilder) Build() (memory.WorkingMemoryStrategy, error)
Build creates the working memory strategy.
Returns an error if required parameters are missing.
func (*WorkingMemoryBuilder) ModelName ¶
func (b *WorkingMemoryBuilder) ModelName(name string) *WorkingMemoryBuilder
ModelName sets the model name for token counting (used by token_window and summary_buffer).
Example:
builder.NewWorkingMemory("token_window").ModelName("gpt-4o").Budget(8000)
func (*WorkingMemoryBuilder) MustBuild ¶
func (b *WorkingMemoryBuilder) MustBuild() memory.WorkingMemoryStrategy
MustBuild creates the working memory strategy or panics on error.
func (*WorkingMemoryBuilder) PreserveRecent ¶
func (b *WorkingMemoryBuilder) PreserveRecent(count int) *WorkingMemoryBuilder
PreserveRecent sets the minimum number of recent messages to always keep (token_window only).
Example:
builder.NewWorkingMemory("token_window").PreserveRecent(5)
func (*WorkingMemoryBuilder) Target ¶
func (b *WorkingMemoryBuilder) Target(target float64) *WorkingMemoryBuilder
Target sets the target percentage after summarization.
Example:
builder.NewWorkingMemory("summary_buffer").Target(0.6)
func (*WorkingMemoryBuilder) Threshold ¶
func (b *WorkingMemoryBuilder) Threshold(threshold float64) *WorkingMemoryBuilder
Threshold sets the threshold for triggering summarization. When token usage exceeds this percentage of budget, summarization is triggered.
Example:
builder.NewWorkingMemory("summary_buffer").Threshold(0.85)
func (*WorkingMemoryBuilder) WindowSize ¶
func (b *WorkingMemoryBuilder) WindowSize(size int) *WorkingMemoryBuilder
WindowSize sets the window size for buffer_window strategy.
Example:
builder.NewWorkingMemory("buffer_window").WindowSize(30)
func (*WorkingMemoryBuilder) WithLLM ¶
func (b *WorkingMemoryBuilder) WithLLM(llm model.LLM) *WorkingMemoryBuilder
WithLLM sets the LLM for summarization (required for summary_buffer).
Example:
builder.NewWorkingMemory("summary_buffer").WithLLM(llm)