From 6d9e015b5e4c35ceb61befd5c34593662d543eaf Mon Sep 17 00:00:00 2001
From: Marcus Schiesser <mail@marcusschiesser.de>
Date: Fri, 22 Mar 2024 19:25:31 +0700
Subject: [PATCH] feat: use claude3 with react agent (#661)

Co-authored-by: Emanuel Ferreira <contatoferreirads@gmail.com>
---
 .changeset/strange-ducks-kiss.md           |  5 +++++
 examples/agent/react_agent.ts              | 10 ++++++++--
 packages/core/src/agent/react/formatter.ts |  2 +-
 packages/edge/package.json                 |  2 +-
 4 files changed, 15 insertions(+), 4 deletions(-)
 create mode 100644 .changeset/strange-ducks-kiss.md

diff --git a/.changeset/strange-ducks-kiss.md b/.changeset/strange-ducks-kiss.md
new file mode 100644
index 000000000..7a42d0937
--- /dev/null
+++ b/.changeset/strange-ducks-kiss.md
@@ -0,0 +1,5 @@
+---
+"llamaindex": patch
+---
+
+feat: use claude3 with react agent
diff --git a/examples/agent/react_agent.ts b/examples/agent/react_agent.ts
index f982734b3..1df04fffb 100644
--- a/examples/agent/react_agent.ts
+++ b/examples/agent/react_agent.ts
@@ -1,4 +1,4 @@
-import { FunctionTool, ReActAgent } from "llamaindex";
+import { Anthropic, FunctionTool, ReActAgent } from "llamaindex";
 
 // Define a function to sum two numbers
 function sumNumbers({ a, b }: { a: number; b: number }): number {
@@ -56,8 +56,14 @@ async function main() {
     parameters: divideJSON,
   });
 
-  // Create an OpenAIAgent with the function tools
+  const anthropic = new Anthropic({
+    apiKey: process.env.ANTHROPIC_API_KEY,
+    model: "claude-3-opus",
+  });
+
+  // Create an ReActAgent with the function tools
   const agent = new ReActAgent({
+    llm: anthropic,
     tools: [functionTool, functionTool2],
     verbose: true,
   });
diff --git a/packages/core/src/agent/react/formatter.ts b/packages/core/src/agent/react/formatter.ts
index d2ed1e3c3..aff8200ec 100644
--- a/packages/core/src/agent/react/formatter.ts
+++ b/packages/core/src/agent/react/formatter.ts
@@ -60,7 +60,7 @@ export class ReActChatFormatter implements BaseAgentChatFormatter {
       } else {
         message = {
           content: reasoningStep.getContent(),
-          role: "system",
+          role: "assistant",
         };
       }
 
diff --git a/packages/edge/package.json b/packages/edge/package.json
index 8f9918caf..8edf4ba89 100644
--- a/packages/edge/package.json
+++ b/packages/edge/package.json
@@ -79,7 +79,7 @@
   "scripts": {
     "copy": "cp -r ../../README.md ../../LICENSE .",
     "update:deps": "node scripts/update-deps.js",
-    "build:core": "pnpm --filter llamaindex build && cp -r ../core/dist . && rm -fr dist/cjs",
+    "build:core": "pnpm --filter llamaindex build && cp -r ../core/dist . && rm -rf dist/cjs",
     "build": "pnpm run update:deps && pnpm run build:core && pnpm copy"
   }
 }
-- 
GitLab