Go言語でAIツールインターフェースを定義する方法
Go
バックエンド
AI
知識
go
// Tool はAIが使用できるツールのインターフェース
type Tool interface {
GetDefinition() ToolDefinition
Execute(ctx context.Context, userID uint, args map[string]interface{}) (*ToolResult, error)
}
// ToolDefinition はツールの定義情報
type ToolDefinition struct {
Name string // ツール名(例: search_memos)
Description string // ツールの説明
Parameters map[string]Parameter // パラメータ定義
}
// Parameter はツールのパラメータ情報
type Parameter struct {
Type string // データ型(string, integer, boolean等)
Description string // パラメータの説明
Required bool // 必須かどうか
Default interface{} // デフォルト値(オプション)
}
// ToolResult はツール実行結果
type ToolResult struct {
Success bool // 実行成功したか
Data map[string]interface{} // 結果データ
Error string // エラーメッセージ(失敗時)
}