The AI Agent to manage Elasticsearch Serverless projects

A natural language-powered AI Agent that effortlessly manages Elasticsearch Serverless projects—enabling project creation, deletion, and status checks.

Learn more about Elastic Cloud Serverless, and start a 14-day free trial to test it out yourself.

This little command-line tool lets you manage your Serverless Elasticsearch projects in plain English. It talks to an AI (in this case, OpenAI) to figure out what you mean and call the right functions using LlamaIndex!

What does it do?

  • Create a project: Spin up a new Serverless Elasticsearch project.
  • Delete a project: Remove an existing project (yep, it cleans up after you).
  • Get project status: Check on how your project is doing.
  • Get project details: Fetch all the juicy details about your project.

Check the code on GitHub.

How it works

When you type in something like:

"Create a serverless project named my_project"

…here’s what goes on behind the scenes:

  • User input & context: Your natural language command is sent to the AI agent.
  • Function descriptions: The AI agent already knows about a few functions—like create_ess_project, delete_ess_project, get_ess_project_status, and get_ess_project_details—because we gave it detailed descriptions. These descriptions tell the AI what each function does and what parameters they need.
  • LLM processing: Your query plus the function info is sent off to the LLM. This means the AI sees:
    • The user query: Your plain-English instruction.
    • Available functions & descriptions: Details on what each tool does so it can choose the right one.
    • Context/historic chat info: Since it’s a conversation, it remembers what’s been said before.
  • Function call & response: The AI figures out which function to call, passes along the right parameters (like your project name), and then the function is executed. The response is sent back to you in a friendly format.

In short, we’re sending both your natural language query and a list of detailed tool descriptions to the LLM so it can “understand” and choose the right action for your request.

Setup

Prerequisites:

Before running the AI agent, ensure that you have the following set up:

  1. Python (v3.7 or later) installed.
  2. Elasticsearch serverless account set up on Elastic Cloud.
  3. OpenAI account to interact with the language model.

Steps:

1. Clone the repository:

2. Create a virtual environment (optional but recommended): If you're facing environment-related issues, you can set up a virtual environment for isolation:

3. Install the dependencies: Ensure that all required dependencies are installed by running:

4. Configure your environment: Create a .env file in the project root with the following variables. Here’s an example .env.example file to help you out:

Ensure that you have the correct values for ES_URL, API_KEY, and OPENAI_API_KEY. You can find your API keys in the respective service dashboards.

5. Projects File: The tool uses a projects.json file to store your project mappings (project names to their details). This file will be created automatically if it doesn't already exist.

Running the agent

You’ll see a prompt like this:

Type in your command, and the AI agent will work its magic! When you're done, type exit or quit to leave.

A few more details

  • LLM integration: The LLM is given both your query and detailed descriptions of each available function. This helps it understand the context and decide, for example, whether to call create_ess_project or delete_ess_project.
  • Tool descriptions: Each function tool (created using FunctionTool.from_defaults) has a friendly description. This description is included in the prompt sent to the LLM so that it “knows” what actions are available and what each action expects.
  • Persistence: Your projects and their details are saved in projects.json, so you don’t have to re-enter info every time.
  • Verbose logging: The agent is set to verbose mode, which is great for debugging and seeing how your instructions get translated into function calls.

Example utilization

Related content

Ready to build state of the art search experiences?

Sufficiently advanced search isn’t achieved with the efforts of one. Elasticsearch is powered by data scientists, ML ops, engineers, and many more who are just as passionate about search as your are. Let’s connect and work together to build the magical search experience that will get you the results you want.

Try it yourself