Find answers from the community

Updated 2 months ago

Is there any I can wrap any of the

Is there any I can wrap any of the following into a tool?:

my text-to-sql query pipeline is defined as the following:
Plain Text
qp = QueryPipeline(
    modules={..., ..., ...},
    verbose=True
)

I also have an agent wrapped around this pipeline (for retry logic):
Plain Text
agent_worker = QueryPipelineAgentWorker(qp, callback_manager)
agent = agent_worker.as_agent(verbose=True)

I am extremely confused as to how I can have my ReAct chat use the pipeline (or the agent, it doesnt matter which to me) as a "tool". It seems it only "query engines" or functions can be tools. Please any guidance is appreciated
L
G
k
7 comments
You can wrap any function into a tool using FunctionTool
Plain Text
def text2sql(query: str) -> str:
  """Transforms an input query into SQL, and returns the executed response."""
  result = qp.run(...)
  return str(result["some key"])

from llama_index.core.tools import FunctionTool
tool = FunctionTool.from_defaults(fn=text2sql)
Lol didnt know it was such a simple solution, Thank you so much
it would work the same way for agent, right? like result = agent.chat(query) then return str(response)
Not 100% sure what you meant, but I think so!
have u try it yet ? may i ask the result.
Add a reply
Sign up and join the conversation on Discord