Find answers from the community

Updated 10 months ago

Hi, I have two `FunctionTool`s named

Hi, I have two FunctionTools named foo_tool and bar_tool that I want to use in a QueryPlanTool which only accepts QueryEngineTools.
Plain Text
def foo():
    return "foo"
def bar():
    return "bar"
foo_tool = FunctionTool.from_defaults(fn=foo)
bar_tool = FunctionTool.from_defaults(fn=bar)

How can I convert FunctionTool to QueryEngineTool? Or create QueryEngineTool with the same logic as foo and bar?
L
a
4 comments
No way to convert these I think, besides wrapping them in a custom query engine πŸ˜…

The query plan tool is a little alpha. Perhaps they could be updated to accept broader tool types
I'm struggling to attempt your suggestion of using a custom query engine... mind taking a look please @Logan M

My code below to use a simple CustomQueryEngine with a ReActAgent is giving an error

Plain Text
  File "/home/x/anaconda3/envs/foo/lib/python3.10/site-packages/llama_index/core/agent/react/step.py", line 242, in _process_actions
    tool_output = tool.call(**reasoning_step.action_input)
TypeError: BaseToolAsyncAdapter.call() got an unexpected keyword argument 'nodes'


Here's my code using llama-index==0.10.6

Plain Text
import random
from llama_index.core.tools import QueryEngineTool, ToolMetadata, QueryPlanTool
from llama_index.core.query_engine import CustomQueryEngine
from llama_index.core.response_synthesizers import BaseSynthesizer
from llama_index.core import ServiceContext, get_response_synthesizer
from llama_index.core.agent import ReActAgent


service_context = ServiceContext.from_defaults(llm=LLM, embed_model=EMBED_MODEL)
response_synthesizer = get_response_synthesizer(service_context=service_context)


class FooQueryEngine(CustomQueryEngine):
    DATA = [
        "Foo is avaiable in stores right now.",
        "Foo is sold out and wont be in stock till next year.",
    ]

    def custom_query(self, query_str: str):
        return random.choice(self.DATA)


query_plan_tool = QueryPlanTool.from_defaults(
    query_engine_tools=[
        QueryEngineTool(
            query_engine=FooQueryEngine(),
            metadata=ToolMetadata(
                name="Foo availability engine",
                description="Provides availability of Foo",
            ),
        )
    ],
    response_synthesizer=response_synthesizer,
)


agent = ReActAgent.from_tools([query_plan_tool], llm=llm, verbose=True)
print(agent.chat("When can I buy a Foo?"))
hmmm, im surprised that didn't work πŸ€”
i'll need to replicate to debug
Add a reply
Sign up and join the conversation on Discord