diff --git a/go/ai/tools.go b/go/ai/tools.go index 1f3198838d..4fb128dde9 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" } +// Determine whether the error is an interrupt error returned by the tool。 +func IsToolInterruptError(err error) (map[string]any, bool) { + var tie *toolInterruptError + if errors.As(err, &tie) { + return tie.Metadata, true + } + return nil, false +} + // InterruptOptions provides configuration for tool interruption. type InterruptOptions struct { Metadata map[string]any