Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReAct agent crashes when no tool needed #858

Open
alexander-fischer opened this issue May 19, 2024 · 0 comments
Open

ReAct agent crashes when no tool needed #858

alexander-fischer opened this issue May 19, 2024 · 0 comments

Comments

@alexander-fischer
Copy link

I use the ReActAgent together with Llama3 via Ollama. If I ask a normal question like "Hello. How are you?" the agent crashes, since it's searching for a tool to use. I guess it should not throw an error if no tool needs to be used. Here is the stack trace:

Starting step(id, 0cf7f648-3c0c-4651-90a2-e3713085e94d).
Enqueueing output for step(id, 0cf7f648-3c0c-4651-90a2-e3713085e94d).
/Users/alex/dev/research/llamaindex-ts/node_modules/llamaindex/dist/cjs/agent/react.js:63
        throw new Error(`Could not extract tool use from input text: "${inputText}"`);
              ^
Error: Could not extract tool use from input text: "I need to use a tool to help me answer the question.

Action: None
Action Input: None

Please let me know how I can assist you with your task or question."
    at extractToolUse (/Users/alex/dev/research/llamaindex-ts/node_modules/llamaindex/dist/cjs/agent/react.js:63:15)
    at reACTOutputParser (/Users/alex/dev/research/llamaindex-ts/node_modules/llamaindex/dist/cjs/agent/react.js:176:54)
    at taskHandler (/Users/alex/dev/research/llamaindex-ts/node_modules/llamaindex/dist/cjs/agent/react.js:283:30)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.pull (/Users/alex/dev/research/llamaindex-ts/node_modules/llamaindex/dist/cjs/agent/base.js:432:13)

Here is the code for reproducing:

import { FunctionTool, Ollama, ReActAgent } from "llamaindex"

function add({ a, b }: { a: number; b: number }) {
  return `${a + b}`
}

const sumJSON = {
  type: "object",
  properties: {
    a: {
      type: "number",
      description: "The first number",
    },
    b: {
      type: "number",
      description: "The second number",
    },
  },
  required: ["a", "b"],
} as const

const sumTool = new FunctionTool(add, {
  name: "sumTool",
  description: "Add two integers and returns the result integer",
  parameters: sumJSON,
})

function multiply({ a, b }: { a: number; b: number }) {
  return `${a * b}`
}

const multiplyJSON = {
  type: "object",
  properties: {
    a: {
      type: "number",
      description: "The first number",
    },
    b: {
      type: "number",
      description: "The second number",
    },
  },
  required: ["a", "b"],
} as const

const multiplyTool = new FunctionTool(multiply, {
  name: "multiplyTool",
  description: "Multiply two integers and returns the result integer",
  parameters: multiplyJSON,
})

async function main() {
  const context = `You're an agent that function as a calculator. 
  Use the tools only if you're asked to calculate something.
  Don't provide more information than it was asked for.
  Do not rely on prior knowledge.`

  const ollama = new Ollama({
    model: "llama3",
  })

  const agent = new ReActAgent({
    llm: ollama,
    tools: [sumTool, multiplyTool],
    systemPrompt: context,
    verbose: true,
  })

  const prompt = "Hello. How are you?"

  const { response } = await agent.chat({
    message: prompt,
    verbose: true,
  })
  console.log("ANSWER:", response.message.content)
}

void main().then(() => {
  console.log("Done")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant