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

Prerequisites 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_list LlamaIndex 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
The agent calls the Exa tools it was given, then answers from the results. The exact output varies with the query and the publication dates of the pages Exa returns.

Read the Search API guide

Review Exa search parameters and response fields.

Read the LlamaIndex tool reference

Explore LlamaIndex tools and agent configuration.
Last modified on July 31, 2026