tools.go 953 B

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