From c89370e66975b704c12238130f69733264820d4b Mon Sep 17 00:00:00 2001 From: zhouquan_wang Date: Fri, 12 Sep 2025 16:30:22 +0800 Subject: [PATCH] Add an interrupt error judgment function --- go/ai/tools.go | 10 ++++++++++ 1 file changed, 10 insertions(+) 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