hosted

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("record not found")

ErrNotFound is returned when a record lookup yields no result.

Functions

func RegisterMCPTools added in v1.6.0

func RegisterMCPTools(ctx context.Context, client MCPClientLike, registry *ToolRegistry) error

Types

type CodeExecConfig added in v1.0.0

type CodeExecConfig struct {
	Executor CodeExecutor
	Timeout  time.Duration
	Logger   *zap.Logger
}

CodeExecConfig configures the code execution tool.

type CodeExecOutput added in v1.0.0

type CodeExecOutput struct {
	Stdout   string        `json:"stdout"`
	Stderr   string        `json:"stderr"`
	ExitCode int           `json:"exit_code"`
	Duration time.Duration `json:"duration"`
}

CodeExecOutput holds the result of a code execution.

type CodeExecTool added in v1.0.0

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

CodeExecTool provides sandboxed code execution as a hosted tool.

func NewCodeExecTool added in v1.0.0

func NewCodeExecTool(config CodeExecConfig) *CodeExecTool

NewCodeExecTool creates a new code execution tool.

func (*CodeExecTool) Description added in v1.0.0

func (t *CodeExecTool) Description() string

func (*CodeExecTool) Execute added in v1.0.0

func (t *CodeExecTool) Execute(ctx context.Context, args json.RawMessage) (json.RawMessage, error)

func (*CodeExecTool) Name added in v1.0.0

func (t *CodeExecTool) Name() string

func (*CodeExecTool) Schema added in v1.0.0

func (t *CodeExecTool) Schema() types.ToolSchema

func (*CodeExecTool) Type added in v1.0.0

func (t *CodeExecTool) Type() HostedToolType

type CodeExecutor added in v1.0.0

type CodeExecutor interface {
	Execute(ctx context.Context, language string, code string, timeout time.Duration) (*CodeExecOutput, error)
}

CodeExecutor is the interface for sandboxed code execution. This is a local interface following the workflow-local interface pattern (§15) to avoid importing agent/execution directly.

type EditFileTool added in v1.6.0

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

func NewEditFileTool added in v1.6.0

func NewEditFileTool(cfg FileOpsConfig) *EditFileTool

func (*EditFileTool) Description added in v1.6.0

func (t *EditFileTool) Description() string

func (*EditFileTool) Execute added in v1.6.0

func (t *EditFileTool) Execute(ctx context.Context, args json.RawMessage) (json.RawMessage, error)

func (*EditFileTool) Name added in v1.6.0

func (t *EditFileTool) Name() string

func (*EditFileTool) Schema added in v1.6.0

func (t *EditFileTool) Schema() types.ToolSchema

func (*EditFileTool) Type added in v1.6.0

func (t *EditFileTool) Type() HostedToolType

type FileOpsConfig added in v1.6.0

type FileOpsConfig struct {
	AllowedPaths []string
	MaxFileSize  int64
}

type FileSearchResult

type FileSearchResult struct {
	FileID   string         `json:"file_id"`
	FileName string         `json:"file_name"`
	Content  string         `json:"content"`
	Score    float64        `json:"score"`
	Metadata map[string]any `json:"metadata,omitempty"`
}

FileSearchResult代表文件搜索结果.

type FileSearchStore added in v1.0.0

type FileSearchStore interface {
	Search(ctx context.Context, query string, limit int) ([]FileSearchResult, error)
	Index(ctx context.Context, fileID string, content []byte) error
}

FileSearchStore is the store interface for file search operations. It operates on text queries (not raw vectors), distinct from rag.VectorStore.

type FileSearchTool

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

FileSearchTool 执行文件搜索功能.

func NewFileSearchTool

func NewFileSearchTool(store FileSearchStore, maxResults int) *FileSearchTool

NewFileSearchTool创建了一个新的文件搜索工具.

func (*FileSearchTool) Description

func (t *FileSearchTool) Description() string

func (*FileSearchTool) Execute

func (t *FileSearchTool) Execute(ctx context.Context, args json.RawMessage) (json.RawMessage, error)

func (*FileSearchTool) Name

func (t *FileSearchTool) Name() string

func (*FileSearchTool) Schema

func (t *FileSearchTool) Schema() types.ToolSchema

func (*FileSearchTool) Type

func (t *FileSearchTool) Type() HostedToolType

type GormToolRegistryStore added in v1.6.0

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

GormToolRegistryStore implements ToolRegistryStore on top of gorm.

func NewGormToolRegistryStore added in v1.6.0

func NewGormToolRegistryStore(db *gorm.DB) *GormToolRegistryStore

NewGormToolRegistryStore creates a GORM-backed tool registry store.

func (*GormToolRegistryStore) Create added in v1.6.0

func (*GormToolRegistryStore) Delete added in v1.6.0

func (s *GormToolRegistryStore) Delete(id uint) (int64, error)

func (*GormToolRegistryStore) GetByID added in v1.6.0

func (*GormToolRegistryStore) GetByName added in v1.6.0

func (s *GormToolRegistryStore) GetByName(name string) (ToolRegistration, error)

func (*GormToolRegistryStore) List added in v1.6.0

func (*GormToolRegistryStore) Reload added in v1.6.0

func (*GormToolRegistryStore) Update added in v1.6.0

func (s *GormToolRegistryStore) Update(row *ToolRegistration, updates map[string]any) error

func (*GormToolRegistryStore) WithTransaction added in v1.6.0

func (s *GormToolRegistryStore) WithTransaction(ctx context.Context, fn func(ToolRegistryStore) error) error

type HostedTool

type HostedTool interface {
	Type() HostedToolType
	Name() string
	Description() string
	Schema() types.ToolSchema
	Execute(ctx context.Context, args json.RawMessage) (json.RawMessage, error)
}

HostToole 代表由提供者托管的工具.

func NewProviderBackedWebSearchHostedTool added in v1.5.0

func NewProviderBackedWebSearchHostedTool(cfg ToolProviderConfig, logger *zap.Logger) (HostedTool, error)

NewProviderBackedWebSearchHostedTool builds the hosted web_search tool using built-in provider adapters (tavily/firecrawl/duckduckgo/searxng).

type HostedToolType

type HostedToolType string

Hosted ToolType 定义了主机工具的类型.

const (
	ToolTypeWebSearch  HostedToolType = "web_search"
	ToolTypeFileSearch HostedToolType = "file_search"
	ToolTypeCodeExec   HostedToolType = "code_execution"
	ToolTypeRetrieval  HostedToolType = "retrieval"
	ToolTypeMCP        HostedToolType = "mcp"
	ToolTypeAlias      HostedToolType = "alias"
	ToolTypeFileOps    HostedToolType = "file_ops"
	ToolTypeShell      HostedToolType = "shell"
)

type ListDirectoryTool added in v1.6.0

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

func NewListDirectoryTool added in v1.6.0

func NewListDirectoryTool(cfg FileOpsConfig) *ListDirectoryTool

func (*ListDirectoryTool) Description added in v1.6.0

func (t *ListDirectoryTool) Description() string

func (*ListDirectoryTool) Execute added in v1.6.0

func (*ListDirectoryTool) Name added in v1.6.0

func (t *ListDirectoryTool) Name() string

func (*ListDirectoryTool) Schema added in v1.6.0

func (t *ListDirectoryTool) Schema() types.ToolSchema

func (*ListDirectoryTool) Type added in v1.6.0

type MCPClientLike added in v1.6.0

type MCPClientLike interface {
	ListTools(ctx context.Context) ([]MCPToolInfo, error)
	CallTool(ctx context.Context, name string, args map[string]any) (any, error)
}

type MCPToolBridge added in v1.6.0

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

func NewMCPToolBridge added in v1.6.0

func NewMCPToolBridge(client MCPClientLike, tool MCPToolInfo) *MCPToolBridge

func (*MCPToolBridge) Description added in v1.6.0

func (t *MCPToolBridge) Description() string

func (*MCPToolBridge) Execute added in v1.6.0

func (t *MCPToolBridge) Execute(ctx context.Context, args json.RawMessage) (json.RawMessage, error)

func (*MCPToolBridge) Name added in v1.6.0

func (t *MCPToolBridge) Name() string

func (*MCPToolBridge) Schema added in v1.6.0

func (t *MCPToolBridge) Schema() types.ToolSchema

func (*MCPToolBridge) Type added in v1.6.0

func (t *MCPToolBridge) Type() HostedToolType

type MCPToolInfo added in v1.6.0

type MCPToolInfo struct {
	Name        string
	Description string
	InputSchema map[string]any
}

type ReadFileTool added in v1.6.0

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

func NewReadFileTool added in v1.6.0

func NewReadFileTool(cfg FileOpsConfig) *ReadFileTool

func (*ReadFileTool) Description added in v1.6.0

func (t *ReadFileTool) Description() string

func (*ReadFileTool) Execute added in v1.6.0

func (t *ReadFileTool) Execute(ctx context.Context, args json.RawMessage) (json.RawMessage, error)

func (*ReadFileTool) Name added in v1.6.0

func (t *ReadFileTool) Name() string

func (*ReadFileTool) Schema added in v1.6.0

func (t *ReadFileTool) Schema() types.ToolSchema

func (*ReadFileTool) Type added in v1.6.0

func (t *ReadFileTool) Type() HostedToolType

type RetrievalResult added in v1.0.0

type RetrievalResult struct {
	DocumentID string         `json:"document_id"`
	Content    string         `json:"content"`
	Score      float64        `json:"score"`
	Metadata   map[string]any `json:"metadata,omitempty"`
}

RetrievalResult represents a single retrieval result.

type RetrievalStore added in v1.0.0

type RetrievalStore interface {
	Retrieve(ctx context.Context, query string, topK int) ([]RetrievalResult, error)
}

RetrievalStore is the interface for document retrieval. Local interface to avoid importing rag package directly (§15).

type RetrievalTool added in v1.0.0

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

RetrievalTool provides RAG retrieval as a hosted tool.

func NewRetrievalTool added in v1.0.0

func NewRetrievalTool(store RetrievalStore, maxResults int, logger *zap.Logger) *RetrievalTool

NewRetrievalTool creates a new retrieval tool.

func (*RetrievalTool) Description added in v1.0.0

func (t *RetrievalTool) Description() string

func (*RetrievalTool) Execute added in v1.0.0

func (t *RetrievalTool) Execute(ctx context.Context, args json.RawMessage) (json.RawMessage, error)

func (*RetrievalTool) Name added in v1.0.0

func (t *RetrievalTool) Name() string

func (*RetrievalTool) Schema added in v1.0.0

func (t *RetrievalTool) Schema() types.ToolSchema

func (*RetrievalTool) Type added in v1.0.0

func (t *RetrievalTool) Type() HostedToolType

type ShellConfig added in v1.6.0

type ShellConfig struct {
	Enabled       bool
	WorkDir       string
	Env           []string
	Timeout       time.Duration
	MaxOutputSize int
	AllowedCmds   []string
	BlockedCmds   []string
}

type ShellTool added in v1.6.0

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

func NewShellTool added in v1.6.0

func NewShellTool(cfg ShellConfig) *ShellTool

func (*ShellTool) Description added in v1.6.0

func (t *ShellTool) Description() string

func (*ShellTool) Execute added in v1.6.0

func (t *ShellTool) Execute(ctx context.Context, args json.RawMessage) (json.RawMessage, error)

func (*ShellTool) Name added in v1.6.0

func (t *ShellTool) Name() string

func (*ShellTool) Schema added in v1.6.0

func (t *ShellTool) Schema() types.ToolSchema

func (*ShellTool) Type added in v1.6.0

func (t *ShellTool) Type() HostedToolType

type ToolExecuteFunc added in v1.0.0

type ToolExecuteFunc func(ctx context.Context, args json.RawMessage) (json.RawMessage, error)

ToolExecuteFunc is the function signature for tool execution.

type ToolMiddleware added in v1.0.0

type ToolMiddleware func(next ToolExecuteFunc) ToolExecuteFunc

ToolMiddleware wraps tool execution with cross-cutting concerns.

func WithLogging added in v1.0.0

func WithLogging(logger *zap.Logger) ToolMiddleware

WithLogging returns a middleware that logs tool invocations.

func WithMetrics added in v1.0.0

func WithMetrics(onExecute func(name string, duration time.Duration, err error)) ToolMiddleware

WithMetrics returns a middleware that calls a metrics callback after execution.

func WithTimeout added in v1.0.0

func WithTimeout(d time.Duration) ToolMiddleware

WithTimeout returns a middleware that enforces an execution timeout.

type ToolProviderConfig added in v1.5.0

type ToolProviderConfig struct {
	ID uint `gorm:"primaryKey" json:"id"`
	// Provider must be unique (tavily/firecrawl/duckduckgo/searxng).
	Provider string `gorm:"size:32;not null;uniqueIndex" json:"provider"`
	// APIKey is optional for duckduckgo/searxng and required for tavily/firecrawl.
	APIKey string `gorm:"type:text" json:"-"`
	// BaseURL is optional. When empty, provider-specific defaults are used.
	BaseURL string `gorm:"type:text" json:"base_url,omitempty"`
	// TimeoutSeconds controls provider request timeout.
	TimeoutSeconds int `gorm:"not null;default:15" json:"timeout_seconds"`
	// Priority controls active-provider selection among enabled rows (lower wins).
	Priority  int       `gorm:"not null;default:100;index" json:"priority"`
	Enabled   bool      `gorm:"default:true;index" json:"enabled"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

ToolProviderConfig stores DB-managed provider configuration for hosted tools. For now this table is scoped to web_search provider wiring.

func (ToolProviderConfig) TableName added in v1.5.0

func (ToolProviderConfig) TableName() string

type ToolProviderName added in v1.5.0

type ToolProviderName string

ToolProviderName identifies supported external providers for hosted tools.

const (
	ToolProviderTavily     ToolProviderName = "tavily"
	ToolProviderFirecrawl  ToolProviderName = "firecrawl"
	ToolProviderDuckDuckGo ToolProviderName = "duckduckgo"
	ToolProviderSearXNG    ToolProviderName = "searxng"
)

type ToolRegistration added in v1.4.6

type ToolRegistration struct {
	ID          uint            `gorm:"primaryKey" json:"id"`
	Name        string          `gorm:"size:120;not null;uniqueIndex" json:"name"`
	Description string          `gorm:"type:text" json:"description,omitempty"`
	Target      string          `gorm:"size:120;not null" json:"target"`
	Parameters  json.RawMessage `gorm:"type:json" json:"parameters,omitempty"`
	Enabled     bool            `gorm:"default:true;index" json:"enabled"`
	CreatedAt   time.Time       `json:"created_at"`
	UpdatedAt   time.Time       `json:"updated_at"`
}

ToolRegistration stores DB-managed tool alias configuration. It maps an exposed tool name to an existing runtime target tool.

func (ToolRegistration) TableName added in v1.4.6

func (ToolRegistration) TableName() string

type ToolRegistry

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

ToolRegistry manages hosted tools.

func NewToolRegistry

func NewToolRegistry(logger *zap.Logger, opts ...ToolRegistryOption) *ToolRegistry

NewToolRegistry创建了新的主机工具注册.

func (*ToolRegistry) Execute added in v1.0.0

func (r *ToolRegistry) Execute(ctx context.Context, name string, args json.RawMessage) (json.RawMessage, error)

Execute looks up a tool by name and executes it with the middleware chain applied.

func (*ToolRegistry) Get

func (r *ToolRegistry) Get(name string) (HostedTool, bool)

按名称获取主机工具 。

func (*ToolRegistry) GetSchemas

func (r *ToolRegistry) GetSchemas() []types.ToolSchema

GetSchemas 返回所有工具的策略 。

func (*ToolRegistry) List

func (r *ToolRegistry) List() []HostedTool

列表返回所有已注册的工具 。

func (*ToolRegistry) Register

func (r *ToolRegistry) Register(tool HostedTool)

注册注册一个主机工具 。

func (*ToolRegistry) Unregister added in v1.4.6

func (r *ToolRegistry) Unregister(name string)

Unregister removes a hosted tool by name.

func (*ToolRegistry) Use added in v1.0.0

func (r *ToolRegistry) Use(middleware ...ToolMiddleware)

Use appends middleware(s) to the registry's middleware chain.

type ToolRegistryOption added in v1.6.0

type ToolRegistryOption func(*ToolRegistry)

ToolRegistryOption configures optional dependencies for ToolRegistry.

func WithToolMetrics added in v1.6.0

func WithToolMetrics(c *metrics.Collector) ToolRegistryOption

WithToolMetrics injects a Prometheus metrics collector for tool call instrumentation.

type ToolRegistryStore added in v1.6.0

type ToolRegistryStore interface {
	List() ([]ToolRegistration, error)
	Create(row *ToolRegistration) error
	GetByID(id uint) (ToolRegistration, error)
	GetByName(name string) (ToolRegistration, error)
	Update(row *ToolRegistration, updates map[string]any) error
	Reload(row *ToolRegistration) error
	Delete(id uint) (int64, error)
	WithTransaction(ctx context.Context, fn func(ToolRegistryStore) error) error
}

ToolRegistryStore defines DB access for tool registration management.

type WebSearchArgs

type WebSearchArgs struct {
	Query      string `json:"query"`
	MaxResults int    `json:"max_results,omitempty"`
}

WebSearchArgs 代表网络搜索参数.

type WebSearchConfig

type WebSearchConfig struct {
	APIKey     string
	Endpoint   string
	MaxResults int
	Timeout    time.Duration
}

WebSearchConfig 配置了网络搜索工具.

type WebSearchResult

type WebSearchResult struct {
	Title   string `json:"title"`
	URL     string `json:"url"`
	Snippet string `json:"snippet"`
}

WebSearchResult代表搜索结果.

type WebSearchTool

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

WebSearchTool执行网络搜索功能.

func NewWebSearchTool

func NewWebSearchTool(config WebSearchConfig) *WebSearchTool

新WebSearchTooll创建了新的网络搜索工具.

func (*WebSearchTool) Description

func (t *WebSearchTool) Description() string

func (*WebSearchTool) Execute

func (t *WebSearchTool) Execute(ctx context.Context, args json.RawMessage) (json.RawMessage, error)

func (*WebSearchTool) Name

func (t *WebSearchTool) Name() string

func (*WebSearchTool) Schema

func (t *WebSearchTool) Schema() types.ToolSchema

func (*WebSearchTool) Type

func (t *WebSearchTool) Type() HostedToolType

type WriteFileTool added in v1.6.0

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

func NewWriteFileTool added in v1.6.0

func NewWriteFileTool(cfg FileOpsConfig) *WriteFileTool

func (*WriteFileTool) Description added in v1.6.0

func (t *WriteFileTool) Description() string

func (*WriteFileTool) Execute added in v1.6.0

func (t *WriteFileTool) Execute(ctx context.Context, args json.RawMessage) (json.RawMessage, error)

func (*WriteFileTool) Name added in v1.6.0

func (t *WriteFileTool) Name() string

func (*WriteFileTool) Schema added in v1.6.0

func (t *WriteFileTool) Schema() types.ToolSchema

func (*WriteFileTool) Type added in v1.6.0

func (t *WriteFileTool) Type() HostedToolType

Jump to

Keyboard shortcuts

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