tool

package
v1.0.30 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomSchema

func GenerateRandomSchema(schema map[string]interface{}) interface{}

GenerateRandomData 根据 map 结构的 Schema 生成随机数据

func InterfaceToString

func InterfaceToString(i interface{}) (string, error)

InterfaceToString 转换成 string

func ListMcpTools

func ListMcpTools(mcpserver *mcpserversse.McpServerSse) (res *mcp.ListToolsResult, err error)

ListMcpTools 获取 mcp 工具列表

func NewMcpClientCache added in v1.0.2

func NewMcpClientCache(mcpServerSse *mcpserversse.McpServerSse) (*mcpClientCache, error)

构建一个新的 mcp client cache

func ToOpenAITool

func ToOpenAITool(tool Tool) map[string]interface{}

ToOpenAITool converts a Tool to the OpenAI tool format

func ToOpenAIToolPB

func ToOpenAIToolPB(tool Tool) *openai.FunctionToolParam

ToOpenAITool converts a Tool to the OpenAI tool format

func ToOpenAITools

func ToOpenAITools(tools []Tool) []map[string]interface{}

ToOpenAITools converts a slice of Tools to the OpenAI tool format

Types

type FunctionTool

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

FunctionTool is a tool implemented as a Go function

func NewFunctionTool

func NewFunctionTool(name, description string, fn interface{}, schema map[string]interface{}) (
	*FunctionTool, error)

NewFunctionTool creates a new function tool

func (*FunctionTool) Execute

func (t *FunctionTool) Execute(ctx context.Context, params map[string]interface{}) (interface{}, error)

Execute executes the tool with the given parameters

func (*FunctionTool) GetDescription

func (t *FunctionTool) GetDescription() string

GetDescription returns the description of the tool

func (*FunctionTool) GetName

func (t *FunctionTool) GetName() string

GetName returns the name of the tool

func (*FunctionTool) GetParametersSchema

func (t *FunctionTool) GetParametersSchema() map[string]interface{}

GetParametersSchema returns the JSON schema for the tool parameters

func (*FunctionTool) GetTimeout

func (m *FunctionTool) GetTimeout() time.Duration

GetTimeout 获取超时时间

func (*FunctionTool) ResultToString

func (t *FunctionTool) ResultToString(output interface{}) string

ResultToString ...

func (*FunctionTool) SetTimeout

func (m *FunctionTool) SetTimeout(t time.Duration)

SetTimeout 工具输出结果转换成 string

func (*FunctionTool) WithDescription

func (t *FunctionTool) WithDescription(description string) *FunctionTool

WithDescription updates the description of the tool

func (*FunctionTool) WithName

func (t *FunctionTool) WithName(name string) *FunctionTool

WithName updates the name of the tool

func (*FunctionTool) WithSchema

func (t *FunctionTool) WithSchema(schema map[string]interface{}) *FunctionTool

WithSchema sets a custom schema for the tool parameters

type McpTool

type McpTool struct {
	Name    string
	Cache   *mcpClientCache
	Timeout time.Duration
}

McpTool ...

func (*McpTool) Execute

func (m *McpTool) Execute(ctx context.Context, params map[string]interface{}) (interface{}, error)

Execute executes the tool with the given parameter

func (*McpTool) GetDescription

func (m *McpTool) GetDescription() string

GetDescription returns the description of the tool

func (*McpTool) GetName

func (m *McpTool) GetName() string

GetName returns the name of the tool

func (*McpTool) GetParametersSchema

func (m *McpTool) GetParametersSchema() map[string]interface{}

GetParametersSchema returns the JSON schema for the tool parameters

func (*McpTool) GetTimeout

func (m *McpTool) GetTimeout() time.Duration

GetTimeout 获取超时时间

func (*McpTool) ResultToString

func (m *McpTool) ResultToString(output interface{}) string

ResultToString ...

func (*McpTool) SetTimeout

func (m *McpTool) SetTimeout(t time.Duration)

SetTimeout 工具输出结果转换成 string

type Tool

type Tool interface {
	// GetName returns the name of the tool
	GetName() string

	// GetDescription returns the description of the tool
	GetDescription() string

	// GetParametersSchema returns the JSON schema for the tool parameters
	GetParametersSchema() map[string]interface{}

	// Execute executes the tool with the given parameters
	Execute(ctx context.Context, params map[string]interface{}) (interface{}, error)

	// ResultToString 工具输出结果转换成 string
	ResultToString(result interface{}) string

	// GetTimeout 获取超时时间
	GetTimeout() time.Duration

	// SetTimeout 配置工具超时时间
	SetTimeout(t time.Duration)
}

Tool represents a capability that can be used by an agent

func CreateToolFromDefinition

func CreateToolFromDefinition(definition map[string]interface{}, executeFn func(map[string]interface{}) (interface{}, error)) Tool

CreateToolFromDefinition creates a Tool from an OpenAI tool definition

Jump to

Keyboard shortcuts

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