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
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
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?"))