tools

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

tools 包定义 Leros 的最小 Tool 抽象。

当前阶段只提供基础接口和 agent 运行时注入的上下文信息。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithToolContext

func ContextWithToolContext(ctx context.Context, toolCtx ToolContext) context.Context

ContextWithToolContext stores run-scoped tool context on a context.Context.

func JSONString

func JSONString(value interface{}) (string, error)

JSONString encodes structured tool output as the string payload returned to the model.

Types

type BaseTool

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

BaseTool stores the LLM-facing metadata shared by concrete tools.

func NewBaseTool

func NewBaseTool(name string, description string, inputSchema Schema) BaseTool

NewBaseTool creates a reusable metadata base for a concrete tool.

func (BaseTool) Description

func (t BaseTool) Description() string

Description returns the LLM-facing tool description.

func (BaseTool) InputSchema

func (t BaseTool) InputSchema() Schema

InputSchema returns the tool argument schema.

func (BaseTool) Name

func (t BaseTool) Name() string

Name returns the stable tool identifier.

type Property

type Property struct {
	Type        string    `json:"type"`
	Description string    `json:"description,omitempty"`
	Enum        []string  `json:"enum,omitempty"`
	Items       *Property `json:"items,omitempty"`
}

Property describes a single field inside a tool schema.

type Registry

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

Registry 提供最小 Tool 注册与获取能力。

func NewRegistry

func NewRegistry() *Registry

NewRegistry 创建一个新的 Tool 注册表。

func (*Registry) AvailableToolNames added in v0.1.5

func (r *Registry) AvailableToolNames(names []string) []string

AvailableToolNames filters the given names to those registered.

func (*Registry) Get

func (r *Registry) Get(name string) (Tool, error)

Get 根据名称获取 Tool。

func (*Registry) List

func (r *Registry) List() []Tool

List returns all registered tools sorted by tool name.

func (*Registry) Register

func (r *Registry) Register(tool Tool) error

Register 注册一个 Tool,同名 Tool 会被新实例覆盖。

type Schema

type Schema struct {
	Type       string               `json:"type"`
	Required   []string             `json:"required,omitempty"`
	Properties map[string]*Property `json:"properties,omitempty"`
}

Schema describes tool input or output in a provider-agnostic shape.

type Tool

type Tool interface {
	Name() string
	Description() string
	InputSchema() Schema
	Execute(ctx context.Context, input map[string]interface{}) (string, error)
}

Tool 是 Leros 的最小工具接口。

type ToolContext

type ToolContext struct {
	// RunID 是本次 agent 运行的唯一标识。
	RunID string
	// TraceID 是跨服务关联的分布式追踪标识。
	TraceID string
	// AssistantID 是执行本次运行的助手标识。
	AssistantID string
	// UserID 是发起本次运行的人类用户标识。
	UserID string
	// AccountID 是租户或组织账号标识。
	AccountID string
	// Channel 是接收请求的交互渠道(如 "github"、"slack")。
	Channel string
	// ConversationID 是本次运行所属的会话标识。
	ConversationID string
	// ExternalID 是外部渠道中的发起者标识。
	ExternalID string
	// WorkNodeID 是执行本次运行时的工作节点标识。
	WorkNodeID string
	// WorkDir 是本次运行隔离工作区的绝对路径。
	WorkDir string
	// Metadata 携带从请求透传的任意键值对。
	Metadata map[string]any
}

ToolContext 携带 agent runtime 注入的 run 级身份与会话元数据。

func RequireToolContext

func RequireToolContext(ctx context.Context) (ToolContext, error)

RequireToolContext returns run-scoped tool context or an error when it is missing.

func ToolContextFrom

func ToolContextFrom(ctx context.Context) (ToolContext, bool)

ToolContextFrom returns run-scoped tool context stored on ctx.

type Validator

type Validator interface {
	Validate(input map[string]interface{}) error
}

Validator is implemented by tools that perform local input validation before execution.

Directories

Path Synopsis
Package artifact_declare provides a tool for declaring project artifacts produced during a task execution.
Package artifact_declare provides a tool for declaring project artifacts produced during a task execution.
Package memory exposes Leros built-in memory as a runtime tool.
Package memory exposes Leros built-in memory as a runtime tool.
Package nodetools provides worker-local tools for operating an assistant node.
Package nodetools provides worker-local tools for operating an assistant node.
Package skillmanage exposes SkillStore mutations as a runtime tool.
Package skillmanage exposes SkillStore mutations as a runtime tool.
Package skilluse provides the runtime tool for loading Leros skill documents.
Package skilluse provides the runtime tool for loading Leros skill documents.
Package todo exposes the run-scoped runtime todo list as a Leros tool.
Package todo exposes the run-scoped runtime todo list as a Leros tool.

Jump to

Keyboard shortcuts

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