agent

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package agent declares the building blocks for implement vet agent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAgentUI

func NewAgentUI(agent Agent, session Session, config AgentUIConfig) *agentUI

NewAgentUI creates a new agent UI instance

func NewMcpClientToolBuilder

func NewMcpClientToolBuilder(config McpClientToolBuilderConfig) (*mcpClientToolBuilder, error)

NewMcpClientToolBuilder creates a new MCP client tool builder for `vet` MCP server. This basically connects to vet MCP server over SSE or executes the `vet server mcp` command to start a MCP server in stdio mode. We maintain loose coupling between the MCP client and the MCP server by allowing the client to be configured with a set of flags to enable/disable specific tools. We do this to ensure vet MCP contract is not violated and evolves independently. vet Agents will in turn depend on vet MCP server for data access.

func NewMockAgent

func NewMockAgent() *mockAgent

NewMockAgent creates a new mock agent

func NewMockSession

func NewMockSession() *mockSession

NewMockSession creates a new mock session

func NewReactQueryAgent

func NewReactQueryAgent(model model.ToolCallingChatModel,
	config ReactQueryAgentConfig, opts ...reactQueryAgentOpt,
) (*reactQueryAgent, error)

func NewSession

func NewSession(memory Memory) (*session, error)

func NewSimpleMemory

func NewSimpleMemory() (*simpleMemory, error)

func NewToolContentCompactor added in v1.13.0

func NewToolContentCompactor(config ToolContentCompactorConfig) func(context.Context, []*schema.Message) []*schema.Message

NewToolContentCompactor returns a MessageRewriter that compacts tool result content for the specified tool names. It preserves the most recent tool result for each tool name and replaces earlier results with a compact placeholder, reducing context window usage when tools are called repeatedly.

func StartUI

func StartUI(agent Agent, session Session) error

StartUI starts the TUI application with the default configuration

func StartUIWithConfig

func StartUIWithConfig(agent Agent, session Session, config AgentUIConfig) error

StartUIWithConfig starts the TUI application with the provided configuration

func WithTools

func WithTools(tools []tool.BaseTool) reactQueryAgentOpt

Types

type Agent

type Agent interface {
	// Execute executes the agent with the given input and returns the output.
	// Internally the agent may perform a multi-step operation based on config,
	// instructions and available tools.
	Execute(context.Context, Session, Input, ...AgentExecutionContextOpt) (Output, error)
}

type AgentExecutionContext

type AgentExecutionContext struct {
	// OnToolCall is called when the agent is about to call a tool.
	// This is used for introspection only and not to mutate the agent's behavior.
	OnToolCall func(context.Context, Session, Input, string, string) error

	// OnThinking is called when the model produces reasoning/thinking content.
	// This is used for introspection only and not to mutate the agent's behavior.
	OnThinking func(ctx context.Context, content string) error
}

AgentExecutionContext is to pass additional context to the agent on a per execution basis. This is required so that an agent can be configured and shared with different components while allowing the component to pass additional context to the agent.

type AgentExecutionContextOpt

type AgentExecutionContextOpt func(*AgentExecutionContext)

func WithThinkingHook added in v1.13.0

func WithThinkingHook(fn func(ctx context.Context, content string) error) AgentExecutionContextOpt

type AgentToolCallIntrospectionFn

type AgentToolCallIntrospectionFn func(context.Context, string, string) (string, error)

AgentToolCallIntrospectionFn is a function that introspects a tool call. This is aligned with eino contract.

type AgentUIConfig

type AgentUIConfig struct {
	Width                int
	Height               int
	InitialSystemMessage string
	TextInputPlaceholder string
	TitleText            string
	MaxHistory           int

	// Only for informational purposes.
	ModelName   string
	ModelVendor string
	ModelFast   bool
}

AgentUIConfig defines the configuration for the UI

func DefaultAgentUIConfig

func DefaultAgentUIConfig() AgentUIConfig

DefaultAgentUIConfig returns the opinionated default configuration for the UI

type AnswerFormat

type AnswerFormat string
const (
	AnswerFormatMarkdown AnswerFormat = "markdown"
	AnswerFormatJSON     AnswerFormat = "json"
)

type Input

type Input struct {
	Query string
}

type McpClientToolBuilderConfig

type McpClientToolBuilderConfig struct {
	// Common config
	ClientName    string
	ClientVersion string

	// SSE client config
	SseURL  string
	Headers map[string]string

	// Stdout client config
	SkipDefaultTools           bool
	SQLQueryToolEnabled        bool
	SQLQueryToolDBPath         string
	PackageRegistryToolEnabled bool

	// Enable debug mode for the MCP client.
	Debug bool
}

type Memory

type Memory interface {
	AddInteraction(ctx context.Context, interaction *schema.Message) error
	GetInteractions(ctx context.Context) ([]*schema.Message, error)
	Clear(ctx context.Context) error
}

type Model

type Model struct {
	Vendor string
	Name   string
	Fast   bool
	Client model.ToolCallingChatModel
}

func BuildModelFromEnvironment

func BuildModelFromEnvironment(fastMode bool, enableThinking bool) (*Model, error)

BuildModelFromEnvironment builds a model from the environment variables. The order of preference is: 1. OpenAI 2. Claude 3. Gemini 4. Others..

When enableThinking is true, models that support reasoning/thinking content will be configured to include it in responses (e.g. Gemini's IncludeThoughts).

type Output

type Output struct {
	Answer string
	Format AnswerFormat
}

type ReactQueryAgentConfig

type ReactQueryAgentConfig struct {
	MaxSteps        int
	SystemPrompt    string
	MessageRewriter func(ctx context.Context, messages []*schema.Message) []*schema.Message
}

type Session

type Session interface {
	ID() string
	Memory() Memory
}

type ToolBuilder

type ToolBuilder interface {
	Build(context.Context) ([]tool.BaseTool, error)
}

type ToolContentCompactorConfig added in v1.13.0

type ToolContentCompactorConfig struct {
	// ToolNames is the list of tool names whose results should be compacted.
	ToolNames []string
	// MinContentSize is the minimum content length (in bytes) for a tool result
	// to be eligible for compaction. Results shorter than this are left as-is.
	// Default: 0 (compact all matching results regardless of size).
	MinContentSize int
	// CompactMessage is the replacement content for compacted tool results.
	// If empty, a default message is used.
	CompactMessage string
}

ToolContentCompactorConfig configures the behavior of NewToolContentCompactor.

func DefaultToolContentCompactorConfig added in v1.13.0

func DefaultToolContentCompactorConfig() ToolContentCompactorConfig

DefaultToolContentCompactorConfig returns a baseline config with sensible defaults. Callers should set ToolNames for their specific agent.

Directories

Path Synopsis
Package tui provides a lively terminal UI for watching agent execution in non-interactive mode.
Package tui provides a lively terminal UI for watching agent execution in non-interactive mode.

Jump to

Keyboard shortcuts

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