Documentation
¶
Overview ¶
Package toolcall provides toolcall framework
Index ¶
- Variables
- func Error(err error) string
- func FixBrokenJSON(broken string) (result string)
- func GetOrCreateTool(name, description, category string) (int64, error)
- func GetTokenFromNetrc(host string) (string, error)
- func GetToolDisplayName(name string) string
- func HandleToolCall(ctx context.Context, toolName string, argsRaw string) (result string, user string, err error)
- func HandleToolCalls(ctx context.Context, tcs []prompt.ToolCall) (inputs []prompt.Message)
- func RecordToolUsage(ctx context.Context, toolID int64, success bool, errorMsg string) error
- func RegisterTool(tool ToolDef)
- func ToArrayType[T PrimitiveType](anyValues []any, anyValuesLen int) []T
- func ToolArgsValue[T Primitive](args ToolArgs, key string, defaultValue T) T
- func TruncateHead(s string, maxLen int) string
- func TruncateHeadTail(s string, maxLen int) string
- func TruncateJSON(content string, maxRunes int) string
- func TruncateMarkdown(content string, maxRunes int) string
- func TruncateSummary(result string, maxRunes int) string
- func TruncateTail(s string, maxLen int) string
- func TruncateToolResult(result string) string
- type ArrayType
- type Function
- type NetrcEntry
- type Primitive
- type PrimitiveType
- type Tool
- type ToolArgs
- type ToolContent
- type ToolDef
- type ToolDesc
- type ToolResultTruncator
- type ToolUsage
- type ToolUsageStat
Constants ¶
This section is empty.
Variables ¶
var DefaultToolResultTruncator = &ToolResultTruncator{ MaxRunes: 200000, MaxBytes: 800000, KeepBothEnds: true, TruncationMarker: "\n\n[...内容已截断...]\n\n", }
DefaultToolResultTruncator 默认工具结果截断器。 1M 上下文时代(~250K tokens),大幅提升截断阈值。 MaxRunes=200K(~50K tokens),MaxBytes=800KB, 仅为极端情况(如误输出超大文件)提供安全网。
Functions ¶
func GetOrCreateTool ¶
GetOrCreateTool 获取或创建工具
func GetTokenFromNetrc ¶
GetTokenFromNetrc 从.netrc文件获取指定主机的token
func HandleToolCall ¶
func HandleToolCall(ctx context.Context, toolName string, argsRaw string) (result string, user string, err error)
HandleToolCall 处理工具调用(带统计和超时)
func HandleToolCalls ¶
HandleToolCalls 处理工具调用(带统计)
func RecordToolUsage ¶
RecordToolUsage 记录工具使用
func ToArrayType ¶
func ToArrayType[T PrimitiveType](anyValues []any, anyValuesLen int) []T
func ToolArgsValue ¶
ToolArgsValue 安全获取类型化参数值
func TruncateHead ¶
TruncateHead 截取字符串头部,超出部分用省略号代替。 若原字符串长度 <= maxLen,直接返回原串。 若 maxLen <= 省略号长度,返回省略号的前 maxLen 个字符。 否则返回 "原串前若干字符" + "..."
func TruncateHeadTail ¶
TruncateHeadTail 截取字符串头部和尾部,中间用省略号连接。 若原字符串长度 <= maxLen,直接返回原串。 若 maxLen <= 省略号长度,返回省略号的前 maxLen 个字符。 否则将可用字符数(maxLen - 省略号长度)平均分配给头尾(尾部可能多一个字符),返回 "头" + "..." + "尾"
func TruncateMarkdown ¶
TruncateMarkdown 截断Markdown内容
func TruncateSummary ¶
TruncateSummary 智能截断并添加摘要
func TruncateTail ¶
TruncateTail 截取字符串尾部,超出部分用省略号代替。 若原字符串长度 <= maxLen,直接返回原串。 若 maxLen <= 省略号长度,返回省略号的前 maxLen 个字符。 否则返回 "..." + "原串后若干字符"
Types ¶
type ArrayType ¶
type Function ¶
type NetrcEntry ¶
NetrcEntry 表示.netrc文件中的一个条目
func ParseNetrc ¶
func ParseNetrc(path string) ([]NetrcEntry, error)
ParseNetrc 解析.netrc文件,支持单行格式:machine host login user password token
type Primitive ¶
type Primitive interface {
PrimitiveType | ArrayType
}
type PrimitiveType ¶
type Tool ¶
type Tool struct {
Type string `json:"type"`
Function Function `json:"function"`
// contains filtered or unexported fields
}
Tool 定义可调用的工具
type ToolContent ¶
type ToolContent struct {
Result string `json:"result,omitzero"`
Error string `json:"error,omitzero"`
Suggestion string `json:"suggestion,omitzero"`
}
func (*ToolContent) String ¶
func (tc *ToolContent) String() (content string)
type ToolDef ¶
type ToolDef struct {
Name string
DisplayName string
Description string
Strict bool
Parameters map[string]any
Category string
Timeout time.Duration // 工具执行超时时间
Handler func(ctx context.Context, args ToolArgs) (string, string, error)
}
ToolDef 工具定义
type ToolDesc ¶
type ToolDesc struct {
ID int64
Name string
Description string
Category string
UsageCount int
CreatedAt time.Time
UpdatedAt time.Time
}
ToolDesc 表示一个工具
type ToolResultTruncator ¶
type ToolResultTruncator struct {
// 最大字符数(rune数量)
MaxRunes int
// 最大字节数
MaxBytes int
// 是否保留开头和结尾
KeepBothEnds bool
// 截断标记
TruncationMarker string
}
ToolResultTruncator 工具结果截断器
func (*ToolResultTruncator) Truncate ¶
func (t *ToolResultTruncator) Truncate(result string) string
Truncate 截断字符串
type ToolUsage ¶
type ToolUsage struct {
ID int64
ProjectPath string
ToolID int64
UsedAt time.Time
Success bool
ErrorMsg string
}
ToolUsage 表示工具使用记录
Source Files
¶
- netrc.go
- tool.go
- tool_def.go
- truncate.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package alltools to load all tools
|
Package alltools to load all tools |
|
Package file provides file ops tool calls
|
Package file provides file ops tool calls |
|
Package flycheck registers the flycheck tool for LLM-driven syntax checking.
|
Package flycheck registers the flycheck tool for LLM-driven syntax checking. |
|
Package history 注册 note 工具,供 LLM 在对话结束时记录笔记
|
Package history 注册 note 工具,供 LLM 在对话结束时记录笔记 |
|
Package issue to address issue create, list, show, assign, close
|
Package issue to address issue create, list, show, assign, close |
|
Package shell for shell tools
|
Package shell for shell tools |