aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/aflow/func_tool.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2026-01-16 20:48:47 +0100
committerDmitry Vyukov <dvyukov@google.com>2026-01-20 21:12:57 +0000
commit4dc35ec28780d6a78e8afcf2650d4ada4fcd245c (patch)
tree2d230546858e301914fc8f3d92fb83935ba7a796 /pkg/aflow/func_tool.go
parent91e26ec437abcd42a8255aa88e31b45da059529e (diff)
pkg/aflow: handle common LLM mis-behaviors wrt tool calling
Gracefully handle (reply to LLM with error): - incorrect tool name - incorrect tool arg type - missing tool arg Silently handle: - more than one call to set-results - excessive tool args Fixes #6604
Diffstat (limited to 'pkg/aflow/func_tool.go')
-rw-r--r--pkg/aflow/func_tool.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/pkg/aflow/func_tool.go b/pkg/aflow/func_tool.go
index cd069db84..48b47b1e5 100644
--- a/pkg/aflow/func_tool.go
+++ b/pkg/aflow/func_tool.go
@@ -40,11 +40,17 @@ func (t *funcTool[State, Args, Results]) declaration() *genai.FunctionDeclaratio
}
func (t *funcTool[State, Args, Results]) execute(ctx *Context, args map[string]any) (map[string]any, error) {
- state, err := convertFromMap[State](ctx.state, false)
+ state, err := convertFromMap[State](ctx.state, false, false)
if err != nil {
return nil, err
}
- a, err := convertFromMap[Args](args, true)
+ // We parse args in non-strict mode too.
+ // LLM shouldn't provide excessive args, but they are known to mess up things
+ // in all possible ways occasionally. Generally we want to handle such cases
+ // in some way, rather than fail the whole workflow. We could reply to it
+ // with an error about this, but it's unclear if the additional round-trip
+ // worth it, it already provided all the actual arguments.
+ a, err := convertFromMap[Args](args, false, true)
if err != nil {
return nil, err
}