From 5b6bebdcb7da46d1471b3aeacb28b54ba905b3b2 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 19 Jan 2026 15:15:18 +0100 Subject: pkg/aflow: add BadCallError The error allows tools to communicate that an error is not an infrastructure error that must fail the whole workflow, but rather a bad tool invocation by an LLM (e.g. asking for a non-existent file contents). Previously in the codesearcher tool we used a separate Missing bool to communicate that. With the error everything just becomes cleaner and nicer. The errors also allows all other tools to communicate any errors to the LLM when the normal results cannot be provided and don't make sense. --- pkg/aflow/schema.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'pkg/aflow/schema.go') diff --git a/pkg/aflow/schema.go b/pkg/aflow/schema.go index 2b2d77f76..0b0eb8994 100644 --- a/pkg/aflow/schema.go +++ b/pkg/aflow/schema.go @@ -63,7 +63,7 @@ func convertFromMap[T any](m map[string]any, strict, tool bool) (T, error) { f, ok := m[name] if !ok { if tool { - return val, &toolArgsError{fmt.Errorf("missing argument %q", name)} + return val, BadCallError(fmt.Sprintf("missing argument %q", name)) } else { return val, fmt.Errorf("field %q is not present when converting map to %T", name, val) } @@ -79,8 +79,8 @@ func convertFromMap[T any](m map[string]any, strict, tool bool) (T, error) { field.Set(reflect.ValueOf(f)) } else { if tool { - return val, &toolArgsError{fmt.Errorf("argument %q has wrong type: got %T, want %v", - name, f, field.Type().Name())} + return val, BadCallError(fmt.Sprintf("argument %q has wrong type: got %T, want %v", + name, f, field.Type().Name())) } else { return val, fmt.Errorf("field %q has wrong type: got %T, want %v", name, f, field.Type().Name()) @@ -93,8 +93,6 @@ func convertFromMap[T any](m map[string]any, strict, tool bool) (T, error) { return val, nil } -type toolArgsError struct{ error } - // foreachField iterates over all public fields of the struct provided in data. func foreachField(data any) iter.Seq2[string, reflect.Value] { return func(yield func(string, reflect.Value) bool) { -- cgit mrf-deployment