Skip to main content
New to Exa? Try the Coding Agent Quickstart to get started in under a minute.

LlamaIndex is a framework for building LLM applications powered by structured data. In this guide, we’ll use Exa’s LlamaIndex integration to:
  1. Specify Exa’s Search and Retrieve Highlight Tool as a LlamaIndex retriever
  2. Set up an OpenAI Agent that uses this tool in its response generation

Get Started

1

Pre-requisites and installation

Install the llama-index, llama-index core, llama-index-tools-exa libraries. OpenAI dependencies are within the core library, so we don’t need to specify that.
Python
Also ensure API keys are initialized properly. The following code uses the EXA_API_KEY as the relevant environment variable name.

Get your Exa API key

2

Instantiate Exa tool

Import the relevant Exa integration library and instantiate LlamaIndex’s ExaToolSpec.
Python
3

Choose the Exa method to use

For this example, we are only interested in passing the search_and_retrieve_highlights method to our agent, so we specify this using the .to_tool_listLlamaIndex method. We also pass current_date, a simple utility so our agent knows the current date.
Python
4

Set up an OpenAI Agent and make Exa-powered requests

Set up the OpenAIAgent, passing the filtered down toolset from above.
Python
We can then use the chat method to interact with the agent.
Python
5

Sample outputs

Output 1: Verbose output of agent operation
Stdout
Output 2: Agent response
Stdout
As you can see, the output generation is enriched with the context of our Exa Search query result!
Last modified on March 17, 2026