refactor(agent): changed regex for tool use extraction to look for optional "Input:" prefix to comply with Cohere command-r models (#1654)

This commit is contained in:
Savas Ziplies
2025-02-14 09:17:03 +01:00
committed by GitHub
parent e724f7e9f2
commit 6d37d440a6
2 changed files with 6 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"llamaindex": patch
---
fix: Update react agent to support tool calls from Cohere command-r models
+1 -1
View File
@@ -100,7 +100,7 @@ function extractToolUse(
inputText: string,
): [thought: string, action: string, input: string] {
const pattern =
/\s*Thought: (.*?)\nAction: ([a-zA-Z0-9_]+).*?\.*Input: .*?(\{.*?\})/s;
/\s*Thought: (.*?)\nAction: ([a-zA-Z0-9_]+).*?\.*[Input:]*.*?(\{.*?\})/s;
const match = inputText.match(pattern);