Add example for using retriever with agents #1224
Replies: 6 comments 1 reply
-
@tom-leamon, you can use a |
Beta Was this translation helpful? Give feedback.
-
That does work, but it seems to take significantly longer to use the tool and respond compared to using a ContextChatEngine. Is this a limitation of function calling APIs? Or is there a way avoid tool use but still perform retrieval? |
Beta Was this translation helpful? Give feedback.
-
@himself65 @marcusschiesser is it possible to have agents use a retriever without a QueryEngineTool? With If the agent could use the retriever without an additional tool call, like Without this capability I am forced to have users manually choose if they want an agent or not, depending on if they need it to perform tool use (like searching the web) or provide the highest quality answer in the shortest time. I would prefer to have a single paradigm that both always has full context and can use tools. Is this something that is already possible, or perhaps could be added to the roadmap? |
Beta Was this translation helpful? Give feedback.
-
@tom-leamon to reduce the latency, you can use a tool that directly calls the retriever. I added an example to the examples folder, see https://github.com/run-llama/LlamaIndexTS/blob/main/examples/agent/retriever_openai_agent.ts (compare with the same example using the query engine tool: https://github.com/run-llama/LlamaIndexTS/blob/main/examples/agent/query_openai_agent.ts) The differences are:
You can see the difference at run-time by adding the In the simple use case, both approaches lead to the same result - Would be great to get some feedback from your use case! |
Beta Was this translation helpful? Give feedback.
-
Hey, @marcusschiesser I wanted to circle back on the low latency issue with agents, similar to what we see with ContextChatEngine. Right now, the agent can only take a retriever or tools in the constructor, disabling the retriever if tools are passed: export class LLMAgent extends AgentRunner<LLM> {
constructor(params: LLMAgentParams) {
const llm = params.llm ?? (Settings.llm ? (Settings.llm as LLM) : null);
if (!llm) throw new Error("llm must be provided for either in params or Settings.llm");
super({
llm,
chatHistory: params.chatHistory ?? [],
systemPrompt: params.systemPrompt ?? null,
runner: new LLMAgentWorker(),
tools: "tools" in params ? params.tools : params.toolRetriever.retrieve.bind(params.toolRetriever),
verbose: params.verbose ?? false,
});
}
createStore = AgentRunner.defaultCreateStore;
taskHandler = AgentRunner.defaultTaskHandler;
} This setup limits the agent’s ability to perform fast semantic searches and insert content from found nodes directly into the LLM query. Using a QueryEngineTool adds noticeable delay, which is a concern for real-time apps. Also, making tool usage optional might confuse users who expect a straightforward experience where the agent can operate with full context without extra steps. This mutually exclusive approach has been in the repo since its beginning. Are there any issues with allowing the retriever and tools to work together? If not, I’d be happy to help implement that change. |
Beta Was this translation helpful? Give feedback.
-
@erik-balfe, the agent doesn't support a retriever as an argument, but a If using a retriever tool (see https://github.com/run-llama/LlamaIndexTS/blob/main/examples/agent/retriever_openai_agent.ts) is not sufficient for your use case, you could try calling a context generator (see |
Beta Was this translation helpful? Give feedback.
-
Currently, there are no examples in the documentation which illustrate how to use retrievers with agents in order to leverage expanded context through embeddings. It's not immediately clear if this is even possible, though the types suggest it is.
If it's not currently available, implementing this feature would be hugely beneficial in increasing the performance of agents.
Beta Was this translation helpful? Give feedback.
All reactions