|
| 1 | +# Elastic Agent Builder A2A App |
| 2 | + |
| 3 | +**Getting started with Agent Builder and A2A using Microsoft Agent Framework** |
| 4 | + |
| 5 | +This is an example Python console app that demonstrates how to connect and utilize an [Elastic Agent Builder](https://www.elastic.co/elasticsearch/agent-builder) agent via the Agent2Agent (A2A) Protocol orchestrated with the [Microsoft Agent Framework](https://learn.microsoft.com/en-us/agent-framework/overview/agent-framework-overview). |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +1. An Elasticsearch project/deployment running in [Elastic Cloud](https://cloud.elastic.co/registration?utm_source=github&utm_content=elasticsearch-labs-example-apps). |
| 10 | + * Requires Elasticsearch serverless project (or for hosted deployments at least Elasticsearch version 9.2.0). |
| 11 | +2. A text editor or an integrated development environment (IDE) like [Visual Studio Code](https://code.visualstudio.com/download) running on your local computer. |
| 12 | +3. [Python version 3.10 or greater](https://www.python.org/downloads/) installed on your local computer. |
| 13 | + |
| 14 | +## Set up your Elasticsearch project |
| 15 | + |
| 16 | +1. Create an index named `my-docs` in your Elasticsearch project by running the following command in Elastic Developer Tools: |
| 17 | + |
| 18 | + PUT /my-docs |
| 19 | + { |
| 20 | + "mappings": { |
| 21 | + "properties": { |
| 22 | + "title": { "type": "text" }, |
| 23 | + "content": { |
| 24 | + "type": "semantic_text" |
| 25 | + }, |
| 26 | + "filename": { "type": "keyword" }, |
| 27 | + "last_modified": { "type": "date" } |
| 28 | + } |
| 29 | + } |
| 30 | + } |
| 31 | +2. Insert a document into your index named `greetings.md` by running the following command in Elastic Developer Tools: |
| 32 | + |
| 33 | + PUT /my-docs/_doc/greetings-md |
| 34 | + { |
| 35 | + "title": "Greetings", |
| 36 | + "content": " |
| 37 | + # Greetings |
| 38 | + ## Basic Greeting |
| 39 | + Hello! |
| 40 | + |
| 41 | + ## Helloworld Greeting |
| 42 | + Hello World! 🌎 |
| 43 | + |
| 44 | + ## Not Greeting |
| 45 | + I'm only a greeting agent. 🤷 |
| 46 | + |
| 47 | + ", |
| 48 | + "filename": "greetings.md", |
| 49 | + "last_modified": "2025-11-04T12:00:00Z" |
| 50 | + } |
| 51 | + |
| 52 | +3. In Elastic Agent Builder, create a **tool** with the following values: |
| 53 | +* **Type**: `ES|QL` |
| 54 | +* **Tool ID**: `example.get_greetings` |
| 55 | +* **Description**: `Get greetings doc from Elasticsearch my-docs index.` |
| 56 | +* **ES|QL**: |
| 57 | + |
| 58 | + FROM my-docs | WHERE filename == "greetings.md" |
| 59 | + |
| 60 | +4. In Elastic Agent Builder, create an **agent** with the following values: |
| 61 | +* **Agent ID**: `helloworld_agent` |
| 62 | +* **Custom Instructions**: |
| 63 | + |
| 64 | + If the prompt contains greeting text like "Hi" or "Hello" then respond with only the Basic Hello text from your documents. |
| 65 | + |
| 66 | + If the prompt contains the text “Hello World” then respond with only the Hello World text from your documents. |
| 67 | + |
| 68 | + In all other cases where the prompt does not contain greeting words, then respond with only the Not Greeting text from your documents. |
| 69 | + |
| 70 | +* **Display Name**: `HelloWorld Agent` |
| 71 | +* **Display Description**: `An agent that responds to greetings.` |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +## Clone the example app |
| 76 | + |
| 77 | +1. Open a terminal and clone the Search Labs source code repository which contains the Elastic Agent Builder A2A App example. Run the following command to clone the example app: |
| 78 | + |
| 79 | + git clone https://github.com/elastic/elasticsearch-labs |
| 80 | + |
| 81 | +3. `cd` to change directory to the example code located in the `supporting-blog-content/agent-builder-a2a-agent-framework` subdirectory. |
| 82 | + |
| 83 | + cd elasticsearch-labs/supporting-blog-content/agent-builder-a2a-agent-framework |
| 84 | + |
| 85 | +## Set up the environment variables |
| 86 | + |
| 87 | +1. Set up the environment variables with values copied from your Elastic project. |
| 88 | + 1. Make a copy of the file `env.example` and name the new file `.env ` |
| 89 | + 2. Edit the `.env` file to set the values of the environment variables to use the values copied from your Elastic project. |
| 90 | + * Replace <YOUR-ELASTIC-AGENT-BUILDER-URL\> |
| 91 | + 1. In your Elastic project, go to the Elastic Agent Builder - Tools page. Click the **MCP Server** dropdown at the top of the Tools page. Select **Copy MCP Server URL.** |
| 92 | + 2. Add the **MCP Server URL** value to the `.env` file. |
| 93 | + * Find where the placeholder text “**<YOUR-ELASTIC-AGENT-BUILDER-URL\>**” appears and paste in the copied **MCP Server URL** to replace the placeholder text. Now edit the pasted **MCP Server URL**. Delete the text “mcp” at the end of the URL and replace it with the text “a2a”. The edited URL should look something like this |
| 94 | + |
| 95 | + `https://example-project-a123.kb.westus2.azure.elastic.cloud/api/agent_builder/a2a` |
| 96 | + |
| 97 | + * Replace <YOUR-ELASTIC-API-KEY\> |
| 98 | + 1. In your Elastic project, click **Elasticsearch** in the navigation menu to go to your project’s home page. |
| 99 | + 2. Click **Create API key** to create a new API key. |
| 100 | + 3. After the API key is created, copy the API Key value. |
| 101 | + 4. Add the API Key value to the `.env` file. |
| 102 | + * Find where the placeholder text “**<YOUR-ELASTIC-API-KEY\>**” appears and paste in the copied API Key value to replace the placeholder text. |
| 103 | + |
| 104 | + 3. Save the changes to the `.env` file. |
| 105 | + |
| 106 | +## Running the example app with Python |
| 107 | + |
| 108 | +1. Create a Python virtual environment by running the following code in the terminal. |
| 109 | + |
| 110 | + python -m venv .venv |
| 111 | + |
| 112 | +2. Activate the Python virtual environment. |
| 113 | + * If you’re running MacOS, the command to activate the virtual environment is: |
| 114 | + |
| 115 | + source .venv/bin/activate |
| 116 | + |
| 117 | + * If you’re on Windows, the command to activate the virtual environment is: |
| 118 | + |
| 119 | + .venv\Scripts\activate |
| 120 | + |
| 121 | +3. Install the Microsoft Agent Framework along with its necessary Python packages by running the following `pip` command: |
| 122 | + |
| 123 | + pip install -r requirements.txt |
| 124 | + |
| 125 | +4. Run the example app by entering the following command into the terminal: |
| 126 | + |
| 127 | + python elastic_agent_builder_a2a.py |
| 128 | + |
| 129 | +## Running the example app with Docker |
| 130 | + |
| 131 | +1. Run the example app with Docker by entering the following command into the terminal: |
| 132 | + |
| 133 | + docker compose run elastic-agent-builder-a2a |
0 commit comments