github.com/anthropics/anthropic-sdk-go@v1.70.1/tools/agenttoolset/helpers_test.go (about) 1 package agenttoolset 2 3 import ( 4 "context" 5 "encoding/json" 6 "strings" 7 "testing" 8 9 anthropic "github.com/anthropics/anthropic-sdk-go" 10 ) 11 12 // runTool executes a BetaTool the way a session/Messages tool runner would and 13 // flattens the outcome to (text, isError) — the shape the tests assert on. 14 func runTool(t *testing.T, tool anthropic.BetaTool, raw json.RawMessage) (string, bool) { 15 t.Helper() 16 out, err := tool.Execute(context.Background(), raw) 17 if err != nil { 18 return err.Error(), true 19 } 20 var sb strings.Builder 21 for _, b := range out { 22 if b.OfText != nil { 23 sb.WriteString(b.OfText.Text) 24 } 25 } 26 return sb.String(), false 27 }