Documentation
¶
Index ¶
- type BashRuntime
- type BatchCallResult
- type CallToolInput
- type CallToolResult
- type ChainResult
- type ChainStep
- type CodeRuntime
- type ExecutionResult
- type HTTPBridgeServer
- type Language
- type NodeJSRuntime
- type PythonRuntime
- type RuntimeConfig
- type RuntimeManager
- func (m *RuntimeManager) AvailableLanguages() []Language
- func (m *RuntimeManager) Execute(ctx context.Context, lang Language, code string, input map[string]any) (*ExecutionResult, error)
- func (m *RuntimeManager) GetRuntime(lang Language) (CodeRuntime, bool)
- func (m *RuntimeManager) SetPythonBridgeURL(url string)
- func (m *RuntimeManager) SetPythonTools(tools []string)
- type ToolBridge
- func (b *ToolBridge) CallTool(ctx context.Context, name string, input map[string]any, tc *tools.ToolContext) (*CallToolResult, error)
- func (b *ToolBridge) CallToolJSON(ctx context.Context, name string, inputJSON string, tc *tools.ToolContext) (*CallToolResult, error)
- func (b *ToolBridge) CallToolsBatch(ctx context.Context, calls []CallToolInput, tc *tools.ToolContext) *BatchCallResult
- func (b *ToolBridge) CallToolsParallel(ctx context.Context, calls []CallToolInput, tc *tools.ToolContext) *BatchCallResult
- func (b *ToolBridge) GetTool(name string) (tools.Tool, error)
- func (b *ToolBridge) GetToolSchema(name string) (map[string]any, error)
- func (b *ToolBridge) ListAvailableTools() []string
- type ToolCallRequest
- type ToolCallResponse
- type ToolChain
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BashRuntime ¶
type BashRuntime struct {
// contains filtered or unexported fields
}
BashRuntime Bash 运行时
func NewBashRuntime ¶
func NewBashRuntime(config *RuntimeConfig) *BashRuntime
NewBashRuntime 创建 Bash 运行时
func (*BashRuntime) Execute ¶
func (r *BashRuntime) Execute(ctx context.Context, code string, input map[string]any) (*ExecutionResult, error)
func (*BashRuntime) IsAvailable ¶
func (r *BashRuntime) IsAvailable() bool
func (*BashRuntime) Language ¶
func (r *BashRuntime) Language() Language
type BatchCallResult ¶
type BatchCallResult struct {
Results []*CallToolResult `json:"results"`
Succeeded int `json:"succeeded"`
Failed int `json:"failed"`
}
BatchCallResult 批量调用结果
type CallToolInput ¶
CallToolInput 工具调用输入
type CallToolResult ¶
type CallToolResult struct {
Name string `json:"name"`
Success bool `json:"success"`
Result any `json:"result,omitempty"`
Error string `json:"error,omitempty"`
}
CallToolResult 工具调用结果
type ChainResult ¶
type ChainResult struct {
Steps []*CallToolResult `json:"steps"`
FinalResult any `json:"final_result"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
ChainResult 链执行结果
type ChainStep ¶
type ChainStep struct {
Name string `json:"name"`
Input map[string]any `json:"input"`
// InputMapper 可选:将前一步结果映射到当前输入
InputMapper func(prevResult any) map[string]any `json:"-"`
}
ChainStep 链中的一步
type CodeRuntime ¶
type CodeRuntime interface {
// Execute 执行代码
Execute(ctx context.Context, code string, input map[string]any) (*ExecutionResult, error)
// Language 返回支持的语言
Language() Language
// IsAvailable 检查运行时是否可用
IsAvailable() bool
}
CodeRuntime 代码运行时接口
type ExecutionResult ¶
type ExecutionResult struct {
Success bool `json:"success"`
Output any `json:"output,omitempty"`
Stdout string `json:"stdout,omitempty"`
Stderr string `json:"stderr,omitempty"`
Error string `json:"error,omitempty"`
ExitCode int `json:"exit_code"`
Duration int64 `json:"duration_ms"`
}
ExecutionResult 代码执行结果
type HTTPBridgeServer ¶ added in v0.20.0
type HTTPBridgeServer struct {
// contains filtered or unexported fields
}
HTTPBridgeServer HTTP 桥接服务器 提供 HTTP API 供 Python/Node.js 代码调用 Go 侧的工具
func NewHTTPBridgeServer ¶ added in v0.20.0
func NewHTTPBridgeServer(bridge *ToolBridge, addr string) *HTTPBridgeServer
NewHTTPBridgeServer 创建 HTTP 桥接服务器
func (*HTTPBridgeServer) SetContextFactory ¶ added in v0.20.0
func (s *HTTPBridgeServer) SetContextFactory(factory func() *tools.ToolContext)
SetContextFactory 设置工具上下文工厂
func (*HTTPBridgeServer) Shutdown ¶ added in v0.20.0
func (s *HTTPBridgeServer) Shutdown(ctx context.Context) error
Shutdown 关闭服务器
func (*HTTPBridgeServer) Start ¶ added in v0.20.0
func (s *HTTPBridgeServer) Start() error
Start 启动服务器
func (*HTTPBridgeServer) StartAsync ¶ added in v0.20.0
func (s *HTTPBridgeServer) StartAsync() error
StartAsync 异步启动服务器
type NodeJSRuntime ¶
type NodeJSRuntime struct {
// contains filtered or unexported fields
}
NodeJSRuntime Node.js 运行时
func NewNodeJSRuntime ¶
func NewNodeJSRuntime(config *RuntimeConfig) *NodeJSRuntime
NewNodeJSRuntime 创建 Node.js 运行时
func (*NodeJSRuntime) Execute ¶
func (r *NodeJSRuntime) Execute(ctx context.Context, code string, input map[string]any) (*ExecutionResult, error)
func (*NodeJSRuntime) IsAvailable ¶
func (r *NodeJSRuntime) IsAvailable() bool
func (*NodeJSRuntime) Language ¶
func (r *NodeJSRuntime) Language() Language
type PythonRuntime ¶
type PythonRuntime struct {
// contains filtered or unexported fields
}
PythonRuntime Python 运行时
func NewPythonRuntime ¶
func NewPythonRuntime(config *RuntimeConfig) *PythonRuntime
NewPythonRuntime 创建 Python 运行时
func (*PythonRuntime) Execute ¶
func (r *PythonRuntime) Execute(ctx context.Context, code string, input map[string]any) (*ExecutionResult, error)
func (*PythonRuntime) IsAvailable ¶
func (r *PythonRuntime) IsAvailable() bool
func (*PythonRuntime) Language ¶
func (r *PythonRuntime) Language() Language
func (*PythonRuntime) SetBridgeURL ¶ added in v0.20.0
func (r *PythonRuntime) SetBridgeURL(url string)
SetBridgeURL 设置 HTTP 桥接服务器地址 (PTC 支持)
func (*PythonRuntime) SetTools ¶ added in v0.20.0
func (r *PythonRuntime) SetTools(tools []string)
SetTools 设置可用工具列表 (PTC 支持)
type RuntimeConfig ¶
type RuntimeConfig struct {
Timeout time.Duration
WorkDir string
Env map[string]string
MaxOutput int // 最大输出字节数
}
RuntimeConfig 运行时配置
type RuntimeManager ¶
type RuntimeManager struct {
// contains filtered or unexported fields
}
RuntimeManager 运行时管理器
func NewRuntimeManager ¶
func NewRuntimeManager(config *RuntimeConfig) *RuntimeManager
NewRuntimeManager 创建运行时管理器
func (*RuntimeManager) AvailableLanguages ¶
func (m *RuntimeManager) AvailableLanguages() []Language
AvailableLanguages 返回可用的语言列表
func (*RuntimeManager) Execute ¶
func (m *RuntimeManager) Execute(ctx context.Context, lang Language, code string, input map[string]any) (*ExecutionResult, error)
Execute 执行代码
func (*RuntimeManager) GetRuntime ¶
func (m *RuntimeManager) GetRuntime(lang Language) (CodeRuntime, bool)
GetRuntime 获取指定语言的运行时
func (*RuntimeManager) SetPythonBridgeURL ¶ added in v0.20.0
func (m *RuntimeManager) SetPythonBridgeURL(url string)
SetPythonBridgeURL 设置 Python 运行时的 HTTP 桥接服务器地址 (PTC 支持)
func (*RuntimeManager) SetPythonTools ¶ added in v0.20.0
func (m *RuntimeManager) SetPythonTools(tools []string)
SetPythonTools 设置 Python 运行时的可用工具列表 (PTC 支持)
type ToolBridge ¶
type ToolBridge struct {
// contains filtered or unexported fields
}
ToolBridge 工具桥接器 提供统一的工具调用接口,支持程序化调用和批量执行
func (*ToolBridge) CallTool ¶
func (b *ToolBridge) CallTool(ctx context.Context, name string, input map[string]any, tc *tools.ToolContext) (*CallToolResult, error)
CallTool 调用单个工具
func (*ToolBridge) CallToolJSON ¶
func (b *ToolBridge) CallToolJSON(ctx context.Context, name string, inputJSON string, tc *tools.ToolContext) (*CallToolResult, error)
CallToolJSON 使用 JSON 字符串调用工具
func (*ToolBridge) CallToolsBatch ¶
func (b *ToolBridge) CallToolsBatch(ctx context.Context, calls []CallToolInput, tc *tools.ToolContext) *BatchCallResult
CallToolsBatch 批量调用工具(顺序执行)
func (*ToolBridge) CallToolsParallel ¶
func (b *ToolBridge) CallToolsParallel(ctx context.Context, calls []CallToolInput, tc *tools.ToolContext) *BatchCallResult
CallToolsParallel 并行调用工具
func (*ToolBridge) GetTool ¶
func (b *ToolBridge) GetTool(name string) (tools.Tool, error)
GetTool 获取或创建工具实例
func (*ToolBridge) GetToolSchema ¶
func (b *ToolBridge) GetToolSchema(name string) (map[string]any, error)
GetToolSchema 获取工具的 schema
func (*ToolBridge) ListAvailableTools ¶
func (b *ToolBridge) ListAvailableTools() []string
ListAvailableTools 列出所有可用工具
type ToolCallRequest ¶ added in v0.20.0
ToolCallRequest 工具调用请求
type ToolCallResponse ¶ added in v0.20.0
type ToolCallResponse struct {
Success bool `json:"success"`
Result any `json:"result,omitempty"`
Error string `json:"error,omitempty"`
}
ToolCallResponse 工具调用响应
type ToolChain ¶
type ToolChain struct {
// contains filtered or unexported fields
}
ToolChain 工具链 - 按顺序执行一系列工具,前一个的输出可作为后一个的输入
func (*ToolChain) Execute ¶
func (c *ToolChain) Execute(ctx context.Context, tc *tools.ToolContext) *ChainResult
Execute 执行工具链