Skip to content

Commit

Permalink
refactor(agent): changed regex for tool use extraction to look for op…
Browse files Browse the repository at this point in the history
…tional "Input:" prefix to comply with Cohere command-r models (#1654)
  • Loading branch information
nea authored Feb 14, 2025
1 parent e724f7e commit 6d37d44
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/sweet-llamas-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"llamaindex": patch
---

fix: Update react agent to support tool calls from Cohere command-r models
2 changes: 1 addition & 1 deletion packages/llamaindex/src/agent/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 6d37d44

Please sign in to comment.