Observation: Error: 'function' object has no attribute 'metadata'
QueryEngineTool
class:from llama_index.core.tools import QueryEngineTool budget_tool = QueryEngineTool.from_defaults( query_engine, name="canadian_budget_2023", description="A RAG engine with some basic facts about the 2023 Canadian federal budget.", )
query_engine
is the function you're trying to use, and name
and description
are the metadata attributes you're supplying.agent = ReActAgent.from_tools( [multiply_tool, add_tool, budget_tool], verbose=True )
multiply_tool
and add_tool
are other tools that you've already set up.AgentRunner
class in LlamaIndex is used to run an agent, which can be any worker that implements the BaseAgentWorker
interface. It doesn't directly provide a method to extract a query engine. AgentRunner
, you can potentially access the query engine from there, depending on the specific type of agent worker. For example, if you used a QueryUnderstandingAgentWorker
or LLMCompilerAgentWorker
, you could access the query engine tools that were passed to it during initialization.AgentRunner
:from llama_index.core.agent import AgentRunner from llama_index.packs.query_understanding_agent.step import QueryUnderstandingAgentWorker from llama_index.core.tools import QueryEngineTool llm = OpenAI(model="gpt-4") tools = [ QueryEngineTool.from_defaults( query_engine=index.as_query_engine(), description="A tool that is useful for retrieving specific snippets from the Paul Graham's life", ), QueryEngineTool.from_defaults( query_engine=steve_index.as_query_engine(), description="A tool that is useful for retrieving specific snippets from the Steve Jobs's life", ), ] agent_worker = QueryUnderstandingAgentWorker.from_tools(tools, llm=llm, verbose=True) agent = AgentRunner(agent_worker)
tools
is a list of QueryEngineTool
instances, each of which wraps a query engine. If you have access to this list, you can access the query engines from there.AgentRunner
instance, you might not be able to extract the query engines. The AgentRunner
class doesn't provide a public API for accessing the underlying agent worker or its properties.QueryEngineTool
and then passing the list of these tools to the from_tools
method of the agent you're creating.from llama_index.core.tools import QueryEngineTool # Assume sql_agent and gmail_agent are your existing agents query_engine_tools = [ QueryEngineTool( query_engine=sql_agent, metadata=ToolMetadata( name="sql_agent", description="Agent that can execute SQL queries." ), ), QueryEngineTool( query_engine=gmail_agent, metadata=ToolMetadata( name="gmail_agent", description="Tool that can send emails on Gmail.", ), ), ] outer_agent = ReActAgent.from_tools(query_engine_tools, llm=llm, verbose=True)
sql_agent
and gmail_agent
are existing agents that you want to use as tools. You wrap each of them in a QueryEngineTool
, providing a name and description for each. Then, you pass the list of these tools to the from_tools
method of the ReActAgent
class to create your new agent.sql_agent
and gmail_agent
are assumed to be instances of classes that inherit from BaseQueryEngine
. This is a base class in LlamaIndex for creating query engines, which are components that can process queries and return results.sql_agent
could be an instance of a class that executes SQL queries against a database, and gmail_agent
could be an instance of a class that interacts with the Gmail API to send emails.from llama_index.core.query_engine import BaseQueryEngine class SQLAgent(BaseQueryEngine): def query(self, input): # Code to execute SQL query and return results pass class GmailAgent(BaseQueryEngine): def query(self, input): # Code to send email via Gmail API and return results pass sql_agent = SQLAgent() gmail_agent = GmailAgent()
SQLAgent
and GmailAgent
are subclasses of BaseQueryEngine
that implement the query
method. You create instances of these classes and then use them as tools in your ReActAgent
.metadata
parameter is required when creating a QueryEngineTool
in LlamaIndex. The metadata
parameter is an instance of the ToolMetadata
class, which includes the name and description of the tool, among other things.QueryEngineTool
:from llama_index.core.tools import QueryEngineTool, ToolMetadata query_engine_tool = QueryEngineTool( query_engine=my_query_engine, metadata=ToolMetadata( name="my_tool", description="A tool that does something useful.", ), )
my_query_engine
is your query engine, and you're creating a ToolMetadata
instance with the name "my_tool" and a description.