aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/aflow/llm_agent.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2026-01-19 15:15:18 +0100
committerDmitry Vyukov <dvyukov@google.com>2026-01-20 21:12:57 +0000
commit5b6bebdcb7da46d1471b3aeacb28b54ba905b3b2 (patch)
treed60fdce83c9b47fb39327f0bdc40b734a7213985 /pkg/aflow/llm_agent.go
parent8088ac4199a6e947c38db669c11d4441a9d59581 (diff)
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.
Diffstat (limited to 'pkg/aflow/llm_agent.go')
-rw-r--r--pkg/aflow/llm_agent.go21
1 files changed, 11 insertions, 10 deletions
diff --git a/pkg/aflow/llm_agent.go b/pkg/aflow/llm_agent.go
index b473c9e7a..5934bf9bd 100644
--- a/pkg/aflow/llm_agent.go
+++ b/pkg/aflow/llm_agent.go
@@ -246,24 +246,25 @@ func (a *LLMAgent) callTools(ctx *Context, tools map[string]Tool, calls []*genai
},
})
}
+ appendError := func(message string) {
+ appendPart(map[string]any{"error": message})
+ }
tool := tools[call.Name]
if tool == nil {
- appendPart(map[string]any{
- "error": fmt.Sprintf("tool %q does not exist, please correct the name", call.Name),
- })
+ appendError(fmt.Sprintf("tool %q does not exist, please correct the name", call.Name))
continue
}
results, err := tool.execute(ctx, call.Args)
if err != nil {
- if argsErr := new(toolArgsError); errors.As(err, &argsErr) {
- // LLM provided wrong arguments to the tool,
- // return the error back to the LLM instead of failing.
- appendPart(map[string]any{
- "error": err.Error(),
- })
+ // LLM provided wrong arguments to the tool,
+ // or the tool returned error message to the LLM.
+ // Return the error back to the LLM instead of failing.
+ if callErr := new(badCallError); errors.As(err, &callErr) {
+ appendError(err.Error())
continue
}
- return nil, nil, err
+ return nil, nil, fmt.Errorf("tool %v failed: error: %w\nargs: %+v",
+ call.Name, err, call.Args)
}
appendPart(results)
if a.Outputs != nil && tool == a.Outputs.tool {