ClientMind is an intelligent customer service automation agent built for the Elasticsearch Agent Builder Hackathon. It leverages Elasticsearch's advanced search capabilities and LLM reasoning to automate messy e-commerce support workflows.
- Dual-Path RAG (Memory + Knowledge): Unlike standard RAG that only looks at documents, ClientMind queries structured customer history (ES|QL) and unstructured knowledge (ELSER) simultaneously.
- Memory Evolution: After each interaction, the agent extracts new customer insights and updates the Elasticsearch persona index, creating a continuous learning loop.
- Human-in-the-Loop: A professional admin dashboard for reviewing, editing, and approving AI-generated drafts before they are sent.
- High-Performance Retrieval: Leveraging Elasticsearch's unified platform to achieve sub-100ms context retrieval for complex reasoning.
graph TD
%% Trigger Layer
Start["1. Webhook (Email JSON)"] --> Extract["2. Extract Fields (Email, Subject, Body)"]
%% Perception Layer
Extract --> Classify["3. Intent Classification (LLM)"]
Classify -- "Non-Sales" --> StandardFlow["4. Standard Template Reply"] --> End1((End))
Classify -- "Sales Inquiry" --> ParallelStart((5. Dual-Path Retrieval))
%% Memory Path
ParallelStart --> MemQuery["5a. Build ES Query (ES|QL)"]
MemQuery --> ES_Mem["6a. Search clientmind_persona"]
ES_Mem --> MemResult["7a. Return: Preferences + Interaction History"]
%% Knowledge Path
ParallelStart --> KnowQuery["5b. Semantic Search (ELSER)"]
KnowQuery --> ES_Know["6b. Search clientmind_knowledge"]
ES_Know --> KnowResult["7b. Return: Relevant Doc Fragments"]
%% Reasoning Layer
MemResult --> ContextBuilder["8. Construct Prompt Context"]
KnowResult --> ContextBuilder
ContextBuilder --> SystemPrompt["9. Inject System Prompt (Rules & Persona)"]
SystemPrompt --> LLM_CoT["10. Reasoning (Chain of Thought)"]
%% Execution Layer
LLM_CoT --> GenDraft["11. Generate Reply Draft"]
GenDraft --> ShowUI["12. Push to Admin Dashboard"]
%% Evolution Layer (Async)
ShowUI -- "Admin Approval" --> SendMail["13. Gmail API Send"]
SendMail --> ExtractNew["14. Extract New Insights"]
ExtractNew --> UpsertES["15. Update ES (Memory Evolution)"] --> End2((Loop Closure))
The project includes a production-ready n8n workflow clientmind-workflow.json that acts as the "nervous system" of the agent:
- Orchestration: It orchestrates Gmail triggers, intent classification, and the Dual-RAG retrieval API.
- State Management: It uses n8n's Wait node to handle the human approval process, pausing the execution until the admin clicks "Approve" in the Dashboard.
- Deployment: Simply import the JSON file into your n8n instance.
To make the workflow operational for judging:
- Import Workflow: In n8n, go to "Workflows" -> "Import from File" and select
clientmind-workflow.json. - Configure Credentials:
- The
Gmail TriggerandReply to a messagenodes will show a connection error. - Click on these nodes and create/select your own Gmail OAuth2 API credentials.
- Ensure your Gmail API has
https://www.googleapis.com/auth/gmail.modifyscope.
- The
- Local API Connectivity:
- The workflow points to
http://localhost:3000. If running n8n in Docker, ensure it can reach your host machine (e.g., usinghttp://host.docker.internal:3000).
- The workflow points to
- Activate: Set the workflow to Active to begin polling for new customer inquiries.
agent-builder/: Contains the core Agent definitions.system_prompt.md: The "brain" of the agent, defining reasoning steps.tools_dsl.json: Tool definitions using Elastic's ES|QL and Semantic Retrieval.
clientmind-workflow.json: The complete n8n workflow for email automation.src/app/api/: Backend API routes for RAG, Draft Generation, and Classification.scripts/: Initialization scripts for Elasticsearch indices and mock data.
- Node.js 20+ & pnpm
- An Elasticsearch Cloud instance (8.15+)
- An OpenAI or Anthropic API Key
- Clone the repository.
- Install dependencies:
pnpm install
- Copy
.env.exampleto.envand fill in your credentials.
Run the initialization script to create indices and import sample knowledge base data:
pnpm ts-node scripts/init-elastic.tspnpm devWatch the Demo Video (Please replace this with your actual video link before submission)
To use the Agent Builder with this project:
- Open your Elastic Cloud Console.
- Navigate to Agent Builder.
- Copy the definitions from
agent-builder/tools_dsl.jsoninto the Tools section. - Paste the content of
agent-builder/system_prompt.mdinto the Instructions.
To help the judging panel evaluate the integration depth, here is a mapping of our implementation to the Elasticsearch Agent Builder contest requirements:
- Dual-Path RAG Engine: Our Core RAG Logic implements a hybrid retrieval strategy. It executes ELSER-powered semantic search for unstructured knowledge and ES|QL pipeline queries for structured customer history simultaneously, achieving sub-100ms retrieval latency.
- Vector & Semantic Search: We utilize the
clientmind_knowledgeindex with ELSER (v2) to ensure high-precision retrieval without the need for external embedding models. - Structured Analytics (ES|QL): We use ES|QL to perform real-time data processing of customer personas, enabling the agent to reason based on historical order frequency and interaction sentiment.
- Native Agent Configuration: Detailed tool definitions and API integration schemas are located in
agent-builder/tools_dsl.json, designed specifically for the Elastic Agent Builder environment. - Sophisticated System Prompts: Our System Instructions utilize Chain-of-Thought (CoT) prompting, guiding the LLM through intent classification, context synthesis, and draft generation.
- Dynamic Persona Updates: Post-interaction, the system extracts new customer insights and "evolves" the memory stored in Elasticsearch, ensuring the agent becomes smarter with every email.
- n8n Orchestration: The complete "nervous system" of the agent is defined in
clientmind-workflow.json, handling everything from Gmail webhooks to human-in-the-loop approvals.
- License: Licensed under Apache 2.0.
- Setup Scripts: Includes
init-elastic.tsfor one-click index creation and mapping configuration (BM25 + ELSER).
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.