tools.go

 1package tools
 2
 3import "context"
 4
 5type ToolInfo struct {
 6	Name        string
 7	Description string
 8	Parameters  map[string]any
 9	Required    []string
10}
11
12type toolResponseType string
13
14const (
15	ToolResponseTypeText  toolResponseType = "text"
16	ToolResponseTypeImage toolResponseType = "image"
17)
18
19type ToolResponse struct {
20	Type    toolResponseType `json:"type"`
21	Content string           `json:"content"`
22	IsError bool             `json:"is_error"`
23}
24
25func NewTextResponse(content string) ToolResponse {
26	return ToolResponse{
27		Type:    ToolResponseTypeText,
28		Content: content,
29	}
30}
31
32func NewTextErrorResponse(content string) ToolResponse {
33	return ToolResponse{
34		Type:    ToolResponseTypeText,
35		Content: content,
36		IsError: true,
37	}
38}
39
40type ToolCall struct {
41	ID    string `json:"id"`
42	Name  string `json:"name"`
43	Input string `json:"input"`
44}
45
46type BaseTool interface {
47	Info() ToolInfo
48	Run(ctx context.Context, params ToolCall) (ToolResponse, error)
49}