diff --git a/go/ai/tools.go b/go/ai/tools.go index 1f3198838d..febc27cfce 100644 --- a/go/ai/tools.go +++ b/go/ai/tools.go @@ -19,6 +19,7 @@ package ai import ( "context" "encoding/json" + "errors" "fmt" "maps" @@ -81,6 +82,15 @@ func (e *toolInterruptError) Error() string { return "tool execution interrupted" } +// IsToolInterruptError determines whether the error is an interrupt error returned by the tool. +func IsToolInterruptError(err error) (bool, map[string]any) { + var tie *toolInterruptError + if errors.As(err, &tie) { + return true, tie.Metadata + } + return false, nil +} + // InterruptOptions provides configuration for tool interruption. type InterruptOptions struct { Metadata map[string]any