Documentation
¶
Overview ¶
Package toolcall provides toolcall framework
Index ¶
- Variables
- func CreateOrGetSessionID(ctx context.Context) (sessionID int64, err error)
- func Error(err error) string
- func FixBrokenJSON(broken string) (result string)
- func GetCurrentSessionID(ctx context.Context) (sessionID int64)
- 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 JudgeHistory(messages []*Message)
- func RecordToolUsage(ctx context.Context, toolID int64, success bool, errorMsg string) error
- func RegisterTool(tool ToolDef)
- func SaveMessages(ctx context.Context, msgs ...Message) error
- func ToArrayType[T PrimitiveType](anyValues []any, anyValuesLen int) []T
- func ToSQLNullString(tcs []ToolCall) (toolCalls sql.NullString)
- func ToolArgsValue[T Primitive](args ToolArgs, key string, defaultValue T) T
- func ToolCallsID(tcs []ToolCall) string
- 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
- func UpdateContent(ctx context.Context, id int64, content string) (err error)
- func UpdateHistory(ctx context.Context, id int64) (err error)
- func UpdateToolCalls(ctx context.Context, id int64, tcs []ToolCall) (err error)
- type ArrayType
- type Function
- type Message
- func CleanupReverse(messages []Message) (cleaned []Message)
- func HandleToolCalls(ctx context.Context, tcs []ToolCall) (inputs []Message)
- func ListHistory(ctx context.Context) ([]*Message, error)
- func LoadHistory(ctx context.Context) ([]Message, error)
- func LoadPrompts(ctx context.Context) ([]Message, error)
- func ShowMessage(ctx context.Context, id int64) (message *Message, err error)
- type NetrcEntry
- type Primitive
- type PrimitiveType
- type Tool
- type ToolArgs
- type ToolCall
- type ToolCallFunction
- type ToolContent
- type ToolDef
- type ToolDesc
- type ToolResultTruncator
- type ToolUsage
- type ToolUsageStat
Constants ¶
This section is empty.
Variables ¶
var DefaultToolResultTruncator = &ToolResultTruncator{ MaxRunes: 8000, MaxBytes: 16000, KeepBothEnds: true, TruncationMarker: "\n\n[...内容已截断...]\n\n", }
DefaultToolResultTruncator 默认工具结果截断器
Functions ¶
func CreateOrGetSessionID ¶
CreateOrGetSessionID 获取或创建会话ID
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 RecordToolUsage ¶
RecordToolUsage 记录工具使用
func SaveMessages ¶
SaveMessages 保存消息(事务)
func ToArrayType ¶
func ToArrayType[T PrimitiveType](anyValues []any, anyValuesLen int) []T
func ToSQLNullString ¶
func ToSQLNullString(tcs []ToolCall) (toolCalls sql.NullString)
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 个字符。 否则返回 "..." + "原串后若干字符"
func UpdateContent ¶
UpdateContent update message content
func UpdateHistory ¶
UpdateHistory update message session_id to 0
Types ¶
type ArrayType ¶
type Function ¶
type Message ¶
type Message struct {
ID int64 `json:"-"`
SessionID int64 `json:"-"`
ModelID int64 `json:"-"`
Role string `json:"role"`
ReasoningContent string `json:"reasoning_content"`
Content string `json:"content"` // 始终输出,即使为空字符串
ToolCalls []ToolCall `json:"tool_calls,omitempty"` // 仅当有工具调用时输出
ToolCallID string `json:"tool_call_id,omitempty"` // 仅当 role="tool" 时输出
CreatedAt time.Time `json:"-"`
OK bool `json:"-"`
// contains filtered or unexported fields
}
Message 扩展,支持工具调用(注意:Content 字段不再使用 omitempty)
func CleanupReverse ¶
CleanupReverse - make the messages clean, remove the mistake message
func HandleToolCalls ¶
HandleToolCalls 处理工具调用(带统计)
func ListHistory ¶
ListHistory 加载指定会话的所有历史消息,按时间升序返回
func LoadHistory ¶
LoadHistory 加载指定会话的所有历史消息,按时间升序返回
func LoadPrompts ¶
LoadPrompts loads the system prompt combined with skill prompts.
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 ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Type string `json:"type"`
Function ToolCallFunction `json:"function"`
}
type ToolCallFunction ¶
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
¶
- message.go
- netrc.go
- prompt.go
- session.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 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 |