Skip to content

Commit a65f7bc

Browse files
committed
Adding code for serverless-ai-agent
1 parent cf42c5d commit a65f7bc

File tree

3 files changed

+483
-0
lines changed

3 files changed

+483
-0
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# Elasticsearch Serverless AI Agent
2+
3+
This little command-line tool lets you manage your [Serverless Elasticsearch projects](https://www.elastic.co/guide/en/serverless/current/intro.html) 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!
4+
5+
### What Does It Do?
6+
- **Create a project**: Spin up a new Serverless Elasticsearch project.
7+
- **Delete a project**: Remove an existing project (yep, it cleans up after you).
8+
- **Get project status**: Check on how your project is doing.
9+
- **Get project details**: Fetch all the juicy details about your project.
10+
11+
### How It Works
12+
When you type in something like:
13+
14+
_"Create a serverless project named my_project"_
15+
16+
…here’s what goes on behind the scenes:
17+
18+
- **User Input & Context:** Your natural language command is sent to the AI agent.
19+
- **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.
20+
- **LLM Processing:** Your query plus the function info is sent off to the LLM. This means the AI sees:
21+
- **The User Query**: Your plain-English instruction.
22+
- **Available Functions & Descriptions**: Details on what each tool does so it can choose the right one.
23+
- **Context/Historic Chat Info**: Since it’s a conversation, it remembers what’s been said before.
24+
- **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.
25+
26+
In short, we’re sending both your natural language query and a list of detailed tool descriptions to the LLM so it can “understandd” and choose the right action for your request.
27+
28+
### Setup
29+
30+
- **Clone the Repoo:**
31+
```
32+
git clone [email protected]:framsouza/serverless-ai-agent.git
33+
cd serverless-ai-agent
34+
```
35+
36+
- **Install the Dependencies**: Make sure you have Python installed, then run:
37+
```
38+
pip install -r requirements.txt
39+
```
40+
41+
- **Configure Your Environment**: Create a .env file in the project root with these variables:
42+
```
43+
ES_URL=your_elasticsearch_api_url
44+
API_KEY=your_elasticsearch_api_key
45+
REGION=your_region
46+
OPENAI_API_KEY=your_openai_api_key
47+
```
48+
49+
- **Projects File**: The tool uses a `projects.json` file to store your project mappings (project names to their details). This file is created automatically if it doesn’t exist.
50+
51+
### Running the agent
52+
53+
```
54+
python main.py
55+
```
56+
57+
You’ll see a prompt like this:
58+
59+
```
60+
Welcome to the Serverless Project AI Agent Tool!
61+
You can ask things like:
62+
- 'Create a serverless project named my_project'
63+
- 'Delete the serverless project named my_project'
64+
- 'Get the status of the serverless project named my_project'
65+
- 'Get the details of the serverless project named my_project'
66+
```
67+
68+
Type in your command, and the AI agent will work its magic! When you're done, type `exit` or `quit` to leave.
69+
70+
### A few more details
71+
72+
- **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`.
73+
- **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.
74+
- **Persistence**: Your projects and their details are saved in projects.json, so you don’t have to re-enter info every time.
75+
- **Verbose Logging**: The agent is set to verbose mode, which is great for debugging and seeing how your instructions get translated into function calls.
76+
77+
### Example utilization
78+
79+
80+
```
81+
python main.py
82+
83+
Welcome to the Serverless Project AI Agent Tool!
84+
85+
You can ask things like:
86+
- 'Create a serverless project named my_project'
87+
- 'Delete the serverless project named my_project'
88+
- 'Get the status of the serverless project named my_project'
89+
- 'Get the details of the serverless project named my_project'
90+
91+
User: Create a serverless project named my-february-test
92+
Added user message to memory: Create a serverless project named my-february-test
93+
94+
=== Calling Function ===
95+
Calling function: create_ess_project with args: {"project_name":"my-february-test"}
96+
========================
97+
98+
99+
Agent: The serverless Elasticsearch project named "my-february-test" has been created successfully. Here are the details:
100+
101+
- **Project ID:** <>>
102+
- **Elasticsearch Endpoint:** [https://my-february-test-ccc399.es.eu-west-1.aws.qa.elastic.cloud](https://my-february-test-ccc399.es.eu-west-1.aws.qa.elastic.cloud)
103+
- **Kibana Endpoint:** [https://my-february-test-ccc399.kb.eu-west-1.aws.qa.elastic.cloud](https://my-february-test-ccc399.kb.eu-west-1.aws.qa.elastic.cloud)
104+
105+
User: get my-february-test status
106+
Added user message to memory: get my-february-test status
107+
108+
=== Calling Function ===
109+
Calling function: get_ess_project_status with args: {"project_name":"my-february-test"}
110+
========================
111+
112+
Agent: The status of the "my-february-test" project is currently **initializing**.
113+
114+
User: get my-february-test info
115+
Added user message to memory: get my-february-test info
116+
117+
=== Calling Function ===
118+
Calling function: get_ess_project_details with args: {"project_name":"my-february-test"}
119+
========================
120+
121+
Agent: Here are the details for the "my-february-test" project:
122+
123+
- **Project Name:** my-february-test
124+
- **Alias:** my-february-test-ccc399
125+
- **Cloud ID:** ""
126+
- **Project ID:** ""
127+
- **Region ID:** aws-eu-west-1
128+
- **Created At:** 2025-02-12T15:42:00.530177619Z
129+
- **Created By:** 571213384
130+
- **Organization ID:** ""
131+
- **Type:** Elasticsearch
132+
- **Optimized For:** General Purpose
133+
- **Search Lake:**
134+
- **Boost Window:** 7
135+
- **Search Power:** 100
136+
- **Endpoints:**
137+
- **Elasticsearch:** https://my-february-test-ccc399.es.eu-west-1.aws.qa.elastic.cloud
138+
- **Kibana:** https://my-february-test-ccc399.kb.eu-west-1.aws.qa.elastic.cloud
139+
- **Credentials:**
140+
- **Username:** ""
141+
- **Password:** ""
142+
143+
Please ensure to keep the credentials secure.
144+
145+
User: please delete the my-february-test project
146+
Added user message to memory: please delete the my-february-test project
147+
148+
=== Calling Function ===
149+
Calling function: delete_ess_project with args: {"project_name":"my-february-test"}
150+
========================
151+
152+
Agent: The "my-february-test" project has been deleted successfully.
153+
```
154+
155+
[See original code](https://github.com/framsouza/serverless-ai-agent)

0 commit comments

Comments
 (0)