Replies: 2 comments
-
🤖 Hello, Yes, it is indeed possible in LlamaIndex to get an agent to instantly return a tool's output when it calls the tool, similar to the functionality in Langchain. This can be achieved by using the These methods execute a query on the Here is the relevant code: def _run(self, input: str) -> str:
response = self.query_engine.query(input)
if self.return_sources:
return _get_response_with_sources(response)
return str(response)
async def _arun(self, input: str) -> str:
response = await self.query_engine.aquery(input)
if self.return_sources:
return _get_response_with_sources(response)
return str(response) And here is an example of how to create a "Tool" from a from llama_index.langchain_helpers.agents import IndexToolConfig, LlamaIndexTool
tool_config = IndexToolConfig(
query_engine=query_engine,
name=f"Vector Index",
description=f"useful for when you want to answer queries about X",
tool_kwargs={"return_direct": True}
)
tool = LlamaIndexTool.from_tool_config(tool_config) You can find more information about this in the following sources:
I hope this helps! If you have any other questions, feel free to ask. Best, Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
The bot definitely hallucinated that response. Our tool class/agents should probably have a similar return_direct function, added in a PR |
Beta Was this translation helpful? Give feedback.
-
Question Validation
Question
How do I get an agent to instantly return a tool's output when it calls the tool? I know it's possible in Langchain, but is it possible in llamaindex?
https://python.langchain.com/docs/modules/agents/tools/custom_tools#using-tools-to-return-directly
Beta Was this translation helpful? Give feedback.
All reactions