Skip to content

Commit d54d11b

Browse files
authored
fix: normalize LLM-hallucinated tool names (#656)
Signed-off-by: Grant Linville <[email protected]>
1 parent e3a43cb commit d54d11b

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

pkg/engine/engine.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ func (e *Engine) complete(ctx context.Context, state *State) (*Return, error) {
396396
}
397397
if toolID == "" {
398398
log.Debugf("failed to find tool id for tool %s in tool_call result", content.ToolCall.Function.Name)
399-
toolID = content.ToolCall.Function.Name
399+
toolID = types.ToolNormalizer(content.ToolCall.Function.Name)
400400
missing = true
401401
}
402402
state.Pending[content.ToolCall.ID] = *content.ToolCall

pkg/tests/runner_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ func TestMissingTool(t *testing.T) {
954954

955955
r.RespondWith(tester.Result{
956956
Func: types.CompletionFunctionCall{
957-
Name: "not bob",
957+
Name: "not.bob",
958958
},
959959
})
960960

pkg/tests/testdata/TestMissingTool/call1-resp.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"toolCall": {
66
"id": "call_1",
77
"function": {
8-
"name": "not bob"
8+
"name": "not.bob"
99
}
1010
}
1111
}

pkg/tests/testdata/TestMissingTool/call2.golden

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"toolCall": {
3636
"id": "call_1",
3737
"function": {
38-
"name": "not bob"
38+
"name": "not.bob"
3939
}
4040
}
4141
}
@@ -46,13 +46,13 @@
4646
"role": "tool",
4747
"content": [
4848
{
49-
"text": "ERROR: can not call unknown tool named [not bob]"
49+
"text": "ERROR: can not call unknown tool named [notBob]"
5050
}
5151
],
5252
"toolCall": {
5353
"id": "call_1",
5454
"function": {
55-
"name": "not bob"
55+
"name": "not.bob"
5656
}
5757
},
5858
"usage": {}

0 commit comments

Comments
 (0)