How can I create custom tool for adding two numbers using ReAct agent? #10346
Replies: 1 comment
-
🤖 Hello again @Prabhjot410! It's good to see you diving into more coding challenges. Let's see what we can do to help you with this one. It seems like you're trying to create a custom tool for adding two numbers using a ReAct agent, but you're encountering a KeyError because the tool isn't correctly defined. Here's how you can define an def add(a: int, b: int) -> int:
"""Add two integers and returns the result integer"""
return a + b
from llama_index.tools import FunctionTool
add_tool = FunctionTool.from_defaults(fn=add) Then, you can initialize the ReAct agent with the from llama_index.agent import ReActAgent
from llama_index.llms import OpenAI
llm = OpenAI(model="gpt-3.5-turbo-instruct")
agent = ReActAgent.from_tools([add_tool, multiply_tool], llm=llm, verbose=True) Now, the If you want to create a more complex custom tool, you can create a class that extends the I hope this helps! If you have any other questions, feel free to ask. Best, SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to build custom tool then passing it into ReAct Agent but I am getting the KeyError: tool. Which I think, my tools is not built correctly
Beta Was this translation helpful? Give feedback.
All reactions