metadata
attribute of the response object. Here's an example of how you can do this:response = agent.chat("Your query here") print(response.metadata)
PandasQueryEngine
, the metadata might include the pandas python instructions used to generate the response:# get pandas python instructions print(response.metadata["pandas_instruction_str"])
QueryEngineTool
objects, which is different from the metadata of the response. The metadata of the QueryEngineTool
objects is static and set when you create the QueryEngineTool
objects, as you've done in your code. This metadata is not automatically included in the response metadata.response.metadata
, it means that the specific tool or query engine you're using is not providing any response metadata.QueryEngineTool
objects in the response metadata, you would need to modify the QueryEngineTool
or the query engine to include this information in the response metadata. This would likely involve modifying the query
method of the query engine to include the desired metadata in the response.QueryEngineTool
and the query engines, I can't provide specific instructions on how to do this. You might want to refer to the LlamaIndex documentation () or the source code of the QueryEngineTool
and the query engines for more information.QueryEngineTool
that was used to generate a response, you can modify the call
method of the QueryEngineTool
to include the tool's metadata in the response. Here's an example of how you can do this:class MyQueryEngineTool(QueryEngineTool): def call(self, *args: Any, **kwargs: Any) -> ToolOutput: query_str = self._get_query_str(*args, **kwargs) response = self._query_engine.query(query_str) return ToolOutput( content=str(response), tool_name=self.metadata.name, raw_input={"input": query_str}, raw_output=response, tool_metadata=self.metadata.dict(), # include tool metadata in the response )
MyQueryEngineTool
is a subclass of QueryEngineTool
that overrides the call
method to include the tool's metadata in the response. The tool's metadata is included in the tool_metadata
field of the ToolOutput
object.MyQueryEngineTool
instead of QueryEngineTool
when defining your query engine tools:query_engine_tools = [ MyQueryEngineTool( query_engine=ppm_query_engine, metadata=ToolMetadata( name="ppm_plan_view", description=( "Provides information about Ppm plan view data." "Don't use your prior knowledge in answering a question" ), ), ), # ... ]
response = agent.chat("Your query here") print(response.tool_metadata)
QueryEngineTool
, which might not be possible or desirable in all situations. Also, this solution assumes that you're using a version of LlamaIndex where the ToolOutput
class has a tool_metadata
field. If this is not the case, you might need to modify the ToolOutput
class as well.PandasQueryEngine
was used to generate a response, you can modify the query
method of the PandasQueryEngine
to include this information in the response metadata. Here's an example of how you can do this:class MyPandasQueryEngine(PandasQueryEngine): def __init__(self, df, name, **kwargs): super().__init__(df, **kwargs) self.name = name def query(self, query_str): response = super().query(query_str) # Add the name of the query engine to the response metadata response.metadata["query_engine_name"] = self.name return response
MyPandasQueryEngine
is a subclass of PandasQueryEngine
that adds a name
attribute to the query engine and includes this name in the response metadata. You can then use MyPandasQueryEngine
instead of PandasQueryEngine
when defining your query engines:ppm_query_engine = MyPandasQueryEngine(df=ppm_df, name="ppm_plan_view", verbose=True) # ...
response = agent.chat("Your query here") print(response.metadata["query_engine_name"])
PandasQueryEngine
, which might not be possible or desirable in all situations. Also, this solution assumes that you're using a version of LlamaIndex where the Response
class has a metadata
field. If this is not the case, you might need to modify the Response
class as well.