Documentation
¶
Overview ¶
Package pkg provides a config-first AI agent platform with a clean programmatic API.
Hector can be used in three ways:
Config-First (Primary) ¶
Load agents from YAML configuration:
h, err := pkg.FromConfig("config.yaml")
if err != nil {
log.Fatal(err)
}
defer h.Close()
// Start A2A server
h.Serve(":8080")
Programmatic API (Simple) ¶
Build a single agent programmatically:
h, err := pkg.New(
pkg.WithOpenAI(openai.Config{APIKey: key}),
pkg.WithMCPTool("weather", "http://localhost:9000"),
pkg.WithInstruction("You are a helpful assistant."),
)
if err != nil {
log.Fatal(err)
}
defer h.Close()
response, err := h.Generate(ctx, "How is the weather in Berlin?")
Multi-Agent Patterns ¶
Hector supports two multi-agent patterns aligned with adk-go:
Pattern 1 - Transfer (sub-agents take over):
// Create specialized agents
researcher, _ := pkg.NewAgent(llmagent.Config{
Name: "researcher",
Description: "Researches topics in depth",
Model: model,
})
writer, _ := pkg.NewAgent(llmagent.Config{
Name: "writer",
Description: "Writes content based on research",
Model: model,
})
// Create parent with sub-agents (transfer tools auto-created)
h, _ := pkg.New(
pkg.WithOpenAI(openai.Config{APIKey: key}),
pkg.WithSubAgents(researcher, writer),
)
Pattern 2 - Delegation (parent maintains control):
// Create specialized agents
searchAgent, _ := pkg.NewAgent(llmagent.Config{
Name: "web_search",
Description: "Searches the web for information",
Model: model,
})
// Create parent that uses agent as a tool
h, _ := pkg.New(
pkg.WithOpenAI(openai.Config{APIKey: key}),
pkg.WithAgentTool(searchAgent), // Parent calls searchAgent, gets results back
)
Or use the helper function directly:
searchTool := pkg.AgentAsTool(searchAgent)
h, _ := pkg.New(
pkg.WithOpenAI(openai.Config{APIKey: key}),
pkg.WithTool(searchTool),
)
Package pkg is Hector, built natively on the A2A (Agent-to-Agent) protocol using the a2a-go library.
Architecture Overview ¶
Hector follows a clean, interface-driven architecture inspired by Google's ADK-Go, with the following core concepts:
- Agent: The fundamental unit of execution, implementing the Agent interface
- Session: Manages conversation state and history
- Tool/Toolset: Capabilities that agents can invoke
- Runner: Orchestrates agent execution within sessions
- Server: Exposes agents via A2A protocol (JSON-RPC, gRPC, HTTP)
Key Design Principles ¶
- Native A2A: Uses github.com/a2aproject/a2a-go directly, no custom protobuf
- Interface-First: All core components are defined as interfaces for testability
- Iterator Pattern: Uses Go 1.23+ iter.Seq2 for clean event streaming
- Context Hierarchy: Clear separation of read-only vs mutable context
- Lazy Loading: Toolsets connect to external services on first use
Index ¶
- func FindAgentPath(root Agent, name string) []string
- func WalkAgents(root Agent, visitor func(Agent, int) bool)
- type Agent
- func FindAgent(root Agent, name string) Agent
- func ListAgents(root Agent) []Agent
- func NewAgent(cfg llmagent.Config) (Agent, error)
- func NewLoopAgent(cfg LoopConfig) (Agent, error)
- func NewParallelAgent(cfg ParallelConfig) (Agent, error)
- func NewRemoteAgent(cfg RemoteAgentConfig) (Agent, error)
- func NewSequentialAgent(cfg SequentialConfig) (Agent, error)
- type AgentConfig
- type CallableTool
- type Event
- type Hector
- func (h *Hector) Agent(name string) (agent.Agent, bool)
- func (h *Hector) Close() error
- func (h *Hector) Config() *config.Config
- func (h *Hector) DefaultAgent() (agent.Agent, bool)
- func (h *Hector) Generate(ctx context.Context, input string) (string, error)
- func (h *Hector) GenerateStream(ctx context.Context, input string) iter.Seq2[*agent.Event, error]
- func (h *Hector) Run(ctx context.Context, input string) iter.Seq2[*agent.Event, error]
- func (h *Hector) RunWithSession(ctx context.Context, userID, sessionID, input string) iter.Seq2[*agent.Event, error]
- func (h *Hector) Runtime() *runtime.Runtime
- func (h *Hector) Serve(addr string) error
- func (h *Hector) SessionService() session.Service
- type LLM
- type LLMAgentConfig
- type LLMAgentReasoningConfig
- type LLMConfig
- type LoopConfig
- type Option
- func WithAgent(name string, cfg *config.AgentConfig) Option
- func WithAgentName(name string) Option
- func WithAgentTool(ag agent.Agent) Option
- func WithAgentTools(agents ...agent.Agent) Option
- func WithAnthropic(acfg anthropic.Config) Option
- func WithControlTools(enableExit, enableEscalate bool) Option
- func WithGemini(gcfg gemini.Config) Option
- func WithInstruction(instruction string) Option
- func WithLLM(llm model.LLM) Option
- func WithLLMConfig(name string, cfg *config.LLMConfig) Option
- func WithMCPCommand(name, command string, args ...string) Option
- func WithMCPTool(name, url string, filter ...string) Option
- func WithMCPToolHTTP(name, url string, filter ...string) Option
- func WithOllama(ocfg ollama.Config) Option
- func WithOpenAI(ocfg openai.Config) Option
- func WithReasoning(cfg *config.ReasoningConfig) Option
- func WithSessionService(s session.Service) Option
- func WithStreaming(enabled bool) Option
- func WithSubAgents(agents ...agent.Agent) Option
- func WithTool(t tool.Tool) Option
- func WithToolConfig(name string, cfg *config.ToolConfig) Option
- func WithTools(tools ...tool.Tool) Option
- func WithToolset(ts tool.Toolset) Option
- type ParallelConfig
- type ReasoningConfig
- type RemoteAgentConfig
- type SequentialConfig
- type Tool
- type ToolConfig
- type Toolset
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindAgentPath ¶
FindAgentPath returns the path to an agent in the tree. The path is a slice of agent names from root to the target. Returns nil if the agent is not found.
func WalkAgents ¶
WalkAgents visits all agents in the tree depth-first. The visitor function is called for each agent with its depth level.
Example:
pkg.WalkAgents(root, func(ag pkg.Agent, depth int) bool {
fmt.Printf("%s%s\n", strings.Repeat(" ", depth), ag.Name())
return true // continue walking
})
Types ¶
type Agent ¶
Agent is the core agent interface.
func FindAgent ¶
FindAgent searches for an agent by name in the agent tree. This provides the same functionality as ADK-Go's find_agent() method.
Example:
root, _ := pkg.NewAgent(llmagent.Config{
Name: "coordinator",
SubAgents: []pkg.Agent{researcher, writer},
})
found := pkg.FindAgent(root, "researcher")
if found != nil {
// Use the found agent
}
func ListAgents ¶
ListAgents returns a flat list of all agents in the tree.
func NewAgent ¶
NewAgent creates a new LLM agent programmatically. This is the recommended way to create agents for multi-agent patterns.
Example:
model, _ := openai.New(openai.Config{APIKey: key})
agent, _ := pkg.NewAgent(pkg.AgentOptions{
Name: "researcher",
Description: "Researches topics",
Model: model,
Tools: []tool.Tool{searchTool},
})
func NewLoopAgent ¶
func NewLoopAgent(cfg LoopConfig) (Agent, error)
NewLoopAgent creates an agent that runs sub-agents repeatedly.
Runs sub-agents in sequence for N iterations or until escalation. Set MaxIterations=0 for indefinite looping until escalation.
Use this for iterative refinement workflows, such as:
- Code review and improvement cycles
- Content revision loops
- Optimization iterations
Example:
reviewer, _ := pkg.NewAgent(llmagent.Config{Name: "reviewer", Model: model, ...})
improver, _ := pkg.NewAgent(llmagent.Config{Name: "improver", Model: model, ...})
refiner, _ := pkg.NewLoopAgent(pkg.LoopConfig{
Name: "refiner",
Description: "Iteratively refines output",
SubAgents: []pkg.Agent{reviewer, improver},
MaxIterations: 3,
})
func NewParallelAgent ¶
func NewParallelAgent(cfg ParallelConfig) (Agent, error)
NewParallelAgent creates an agent that runs sub-agents simultaneously.
All sub-agents receive the same input and run in parallel. Events from all sub-agents are yielded as they complete.
Use this for:
- Running different algorithms simultaneously
- Generating multiple responses for review
- Getting diverse perspectives on a problem
Example:
voter1, _ := pkg.NewAgent(llmagent.Config{Name: "voter1", Model: model, ...})
voter2, _ := pkg.NewAgent(llmagent.Config{Name: "voter2", Model: model, ...})
voter3, _ := pkg.NewAgent(llmagent.Config{Name: "voter3", Model: model, ...})
voters, _ := pkg.NewParallelAgent(pkg.ParallelConfig{
Name: "voters",
Description: "Gets multiple perspectives",
SubAgents: []pkg.Agent{voter1, voter2, voter3},
})
func NewRemoteAgent ¶
func NewRemoteAgent(cfg RemoteAgentConfig) (Agent, error)
NewRemoteAgent creates a remote A2A agent.
Remote agents communicate with agents running in different processes or on different hosts using the A2A (Agent-to-Agent) protocol.
Remote agents can be:
- Used as sub-agents for transfer patterns
- Wrapped as tools using AgentAsTool()
- Part of workflow agents (sequential, parallel, loop)
Example:
// From URL (agent card resolved automatically)
remoteHelper, _ := pkg.NewRemoteAgent(pkg.RemoteAgentConfig{
Name: "remote_helper",
Description: "A remote helper agent",
URL: "http://localhost:9000",
})
// Use as sub-agent
h, _ := pkg.New(
pkg.WithOpenAI(openai.Config{APIKey: key}),
pkg.WithSubAgents(remoteHelper),
)
// Use as tool
h, _ := pkg.New(
pkg.WithOpenAI(openai.Config{APIKey: key}),
pkg.WithAgentTool(remoteHelper),
)
func NewSequentialAgent ¶
func NewSequentialAgent(cfg SequentialConfig) (Agent, error)
NewSequentialAgent creates an agent that runs sub-agents once, in sequence.
Use this when you want execution to occur in a fixed, strict order, such as a processing pipeline.
Example:
stage1, _ := pkg.NewAgent(llmagent.Config{Name: "stage1", Model: model, ...})
stage2, _ := pkg.NewAgent(llmagent.Config{Name: "stage2", Model: model, ...})
stage3, _ := pkg.NewAgent(llmagent.Config{Name: "stage3", Model: model, ...})
pipeline, _ := pkg.NewSequentialAgent(pkg.SequentialConfig{
Name: "pipeline",
Description: "Processes data through multiple stages",
SubAgents: []pkg.Agent{stage1, stage2, stage3},
})
type AgentConfig ¶
type AgentConfig = config.AgentConfig
AgentConfig is the configuration for an agent.
type CallableTool ¶
type CallableTool = tool.CallableTool
CallableTool is a tool that can be called synchronously.
type Hector ¶
type Hector struct {
// contains filtered or unexported fields
}
Hector is the main entry point for the Hector platform. It wraps a runtime.Runtime and provides a clean API.
func FromConfig ¶
FromConfig creates a Hector instance from a config file.
func FromConfigWithContext ¶
FromConfigWithContext creates a Hector instance from a config file with context.
func New ¶
New creates a Hector instance programmatically. All options are converted to config and run through the same runtime as FromConfig.
func (*Hector) DefaultAgent ¶
DefaultAgent returns the default agent.
func (*Hector) Generate ¶
Generate produces a response for the given input. This is a convenience method for simple single-turn interactions.
func (*Hector) GenerateStream ¶
GenerateStream produces a streaming response.
func (*Hector) RunWithSession ¶
func (h *Hector) RunWithSession(ctx context.Context, userID, sessionID, input string) iter.Seq2[*agent.Event, error]
RunWithSession executes the agent with a specific session.
func (*Hector) SessionService ¶
SessionService returns the session service.
type LLMAgentConfig ¶
LLMAgentConfig is the configuration for an LLM agent.
type LLMAgentReasoningConfig ¶
type LLMAgentReasoningConfig = llmagent.ReasoningConfig
LLMAgentReasoningConfig configures the reasoning loop for LLM agents.
type LoopConfig ¶
type LoopConfig = workflowagent.LoopConfig
LoopConfig is the configuration for a loop agent.
type Option ¶
type Option func(*builder) error
Option configures a Hector instance.
func WithAgent ¶
func WithAgent(name string, cfg *config.AgentConfig) Option
WithAgent adds a custom agent configuration.
func WithAgentName ¶
WithAgentName sets the default agent name.
func WithAgentTool ¶
WithAgentTool adds an agent as a callable tool (Pattern 2: delegation). The parent agent maintains control and receives structured results.
This follows the adk-go agenttool pattern where the sub-agent runs in an isolated session and returns results to the parent.
Example:
searchAgent, _ := llmagent.New(llmagent.Config{
Name: "web_search",
Description: "Searches the web for information",
Model: model,
})
h, _ := pkg.New(
pkg.WithOpenAI(openai.Config{APIKey: key}),
pkg.WithAgentTool(searchAgent), // Parent can call web_search tool
)
func WithAgentTools ¶
WithAgentTools adds multiple agents as callable tools. Convenience wrapper for adding multiple agent tools at once.
Example:
h, _ := pkg.New(
pkg.WithOpenAI(openai.Config{APIKey: key}),
pkg.WithAgentTools(searchAgent, analysisAgent, writerAgent),
)
func WithAnthropic ¶
WithAnthropic configures Anthropic as the LLM provider.
func WithControlTools ¶
WithControlTools enables control flow tools for explicit loop termination. When enabled, the agent can call exit_loop to signal completion or escalate to delegate to a parent agent.
Example:
pkg.WithControlTools(true, true) // Enable both exit and escalate
func WithGemini ¶
WithGemini configures Gemini as the LLM provider.
func WithInstruction ¶
WithInstruction sets the system instruction for the default agent.
func WithLLM ¶
WithLLM configures a custom LLM instance. This bypasses the factory and uses the provided LLM directly.
func WithLLMConfig ¶
WithLLMConfig adds an LLM from config.
func WithMCPCommand ¶
WithMCPCommand adds an MCP toolset using stdio transport.
func WithMCPTool ¶
WithMCPTool adds an MCP toolset using SSE transport.
func WithMCPToolHTTP ¶
WithMCPToolHTTP adds an MCP toolset using streamable-http transport. Use this for Composio and other HTTP-based MCP servers.
func WithOllama ¶
WithOllama configures Ollama as the LLM provider. Ollama runs locally and doesn't require an API key.
func WithOpenAI ¶
WithOpenAI configures OpenAI as the LLM provider.
func WithReasoning ¶
func WithReasoning(cfg *config.ReasoningConfig) Option
WithReasoning configures the chain-of-thought reasoning loop. This controls how the agent iterates through tool calls and responses.
Example:
pkg.WithReasoning(&config.ReasoningConfig{
MaxIterations: 50,
EnableExitTool: true,
EnableEscalateTool: true,
})
func WithSessionService ¶
WithSessionService sets a custom session service.
func WithStreaming ¶
WithStreaming enables token-by-token streaming for the default agent.
func WithSubAgents ¶
WithSubAgents adds sub-agents for automatic transfer (Pattern 1). Transfer tools are automatically created for each sub-agent, allowing the parent agent to hand off control when needed.
This follows the adk-go transfer pattern where the parent agent stops and the sub-agent takes over completely.
Example:
researcher, _ := llmagent.New(llmagent.Config{Name: "researcher", ...})
writer, _ := llmagent.New(llmagent.Config{Name: "writer", ...})
h, _ := pkg.New(
pkg.WithOpenAI(openai.Config{APIKey: key}),
pkg.WithSubAgents(researcher, writer),
)
The agent will have transfer_to_researcher and transfer_to_writer tools.
func WithTool ¶
WithTool adds a single tool directly. Use this when you have a tool.Tool implementation ready to use.
Example:
myTool := &MyCustomTool{}
h, _ := pkg.New(
pkg.WithOpenAI(openai.Config{APIKey: key}),
pkg.WithTool(myTool),
)
func WithToolConfig ¶
func WithToolConfig(name string, cfg *config.ToolConfig) Option
WithToolConfig adds a tool from config.
type ParallelConfig ¶
type ParallelConfig = workflowagent.ParallelConfig
ParallelConfig is the configuration for a parallel agent.
type ReasoningConfig ¶
type ReasoningConfig = config.ReasoningConfig
ReasoningConfig configures the reasoning loop.
type RemoteAgentConfig ¶
type RemoteAgentConfig = remoteagent.Config
RemoteAgentConfig is the configuration for a remote A2A agent.
type SequentialConfig ¶
type SequentialConfig = workflowagent.SequentialConfig
SequentialConfig is the configuration for a sequential agent.
type Tool ¶
Tool is the core tool interface.
func AgentAsTool ¶
AgentAsTool converts an agent to a tool (Pattern 2: delegation). The parent agent maintains control and receives structured results.
Example:
searchTool := pkg.AgentAsTool(searchAgent)
parentAgent, _ := pkg.NewAgent(pkg.AgentOptions{
Tools: []tool.Tool{searchTool},
})
func AgentAsToolWithConfig ¶
AgentAsToolWithConfig converts an agent to a tool with configuration.
func EscalateTool ¶
func EscalateTool() Tool
EscalateTool creates a tool for escalating to parent agent.
func ExitLoopTool ¶
func ExitLoopTool() Tool
ExitLoopTool creates a tool for explicit loop termination.
func TransferTool ¶
TransferTool creates a tool for transferring to another agent.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package agent defines the core agent interfaces and types for Hector v2.
|
Package agent defines the core agent interfaces and types for Hector v2. |
|
llmagent
Package llmagent provides an LLM-based agent implementation for Hector v2.
|
Package llmagent provides an LLM-based agent implementation for Hector v2. |
|
remoteagent
Package remoteagent provides remote A2A agent support.
|
Package remoteagent provides remote A2A agent support. |
|
runneragent
Package runneragent provides a deterministic tool execution agent.
|
Package runneragent provides a deterministic tool execution agent. |
|
workflowagent
Package workflowagent provides workflow agents for orchestrating multi-agent flows.
|
Package workflowagent provides workflow agents for orchestrating multi-agent flows. |
|
Package auth provides authentication and authorization for Hector v2.
|
Package auth provides authentication and authorization for Hector v2. |
|
Package builder provides fluent builder APIs for programmatic agent construction.
|
Package builder provides fluent builder APIs for programmatic agent construction. |
|
Package checkpoint provides execution state capture and recovery.
|
Package checkpoint provides execution state capture and recovery. |
|
Package config provides configuration loading and management for Hector v2.
|
Package config provides configuration loading and management for Hector v2. |
|
provider
Package provider defines the config source abstraction.
|
Package provider defines the config source abstraction. |
|
Package embedder provides text embedding services for semantic search.
|
Package embedder provides text embedding services for semantic search. |
|
examples
|
|
|
programmatic
command
Example programmatic demonstrates the comprehensive programmatic API of Hector.
|
Example programmatic demonstrates the comprehensive programmatic API of Hector. |
|
weather
command
Example weather demonstrates using Hector with MCP tools.
|
Example weather demonstrates using Hector with MCP tools. |
|
Package guardrails provides composable safety controls for Hector agents.
|
Package guardrails provides composable safety controls for Hector agents. |
|
Package httpclient provides an HTTP client with retry, backoff, and rate limit handling.
|
Package httpclient provides an HTTP client with retry, backoff, and rate limit handling. |
|
Package instruction provides instruction templating for Hector v2 agents.
|
Package instruction provides instruction templating for Hector v2 agents. |
|
Package model defines the LLM interface for Hector v2.
|
Package model defines the LLM interface for Hector v2. |
|
anthropic
Package anthropic provides an Anthropic Claude LLM implementation.
|
Package anthropic provides an Anthropic Claude LLM implementation. |
|
gemini
Package gemini implements the model.LLM interface for Google Gemini models.
|
Package gemini implements the model.LLM interface for Google Gemini models. |
|
ollama
Package ollama provides an Ollama LLM implementation.
|
Package ollama provides an Ollama LLM implementation. |
|
openai
Package openai provides an OpenAI LLM implementation using the Responses API.
|
Package openai provides an OpenAI LLM implementation using the Responses API. |
|
Package observability provides OpenTelemetry tracing and Prometheus metrics.
|
Package observability provides OpenTelemetry tracing and Prometheus metrics. |
|
Package rag provides Retrieval-Augmented Generation (RAG) capabilities.
|
Package rag provides Retrieval-Augmented Generation (RAG) capabilities. |
|
Package ratelimit provides a comprehensive rate limiting system for Hector v2.
|
Package ratelimit provides a comprehensive rate limiting system for Hector v2. |
|
Package runner provides the orchestration layer for agent execution.
|
Package runner provides the orchestration layer for agent execution. |
|
Package runtime builds and manages Hector agents from configuration.
|
Package runtime builds and manages Hector agents from configuration. |
|
Package server provides the HTTP and gRPC server implementation for Hector.
|
Package server provides the HTTP and gRPC server implementation for Hector. |
|
Package session provides session management for Hector v2.
|
Package session provides session management for Hector v2. |
|
Package task provides task management for Hector v2.
|
Package task provides task management for Hector v2. |
|
Package tool defines interfaces for tools that agents can invoke.
|
Package tool defines interfaces for tools that agents can invoke. |
|
agenttool
Package agenttool provides a tool that allows an agent to call another agent.
|
Package agenttool provides a tool that allows an agent to call another agent. |
|
approvaltool
Package approvaltool provides a Human-in-the-Loop (HITL) tool example.
|
Package approvaltool provides a Human-in-the-Loop (HITL) tool example. |
|
commandtool
Package commandtool provides a secure, streaming command execution tool.
|
Package commandtool provides a secure, streaming command execution tool. |
|
controltool
Package controltool provides control flow tools for agent reasoning loops.
|
Package controltool provides control flow tools for agent reasoning loops. |
|
functiontool
Package functiontool provides a convenient way to create tools from typed Go functions.
|
Package functiontool provides a convenient way to create tools from typed Go functions. |
|
mcptoolset
Package mcptoolset provides a Toolset implementation for MCP servers.
|
Package mcptoolset provides a Toolset implementation for MCP servers. |
|
searchtool
Package searchtool provides a search tool for agents to query document stores.
|
Package searchtool provides a search tool for agents to query document stores. |
|
Package trigger provides scheduled and event-driven agent invocation.
|
Package trigger provides scheduled and event-driven agent invocation. |
|
Package utils provides utility functions for v2.
|
Package utils provides utility functions for v2. |
|
Package vector provides a unified interface for vector database operations.
|
Package vector provides a unified interface for vector database operations. |