A Python chatbot client for interacting with Elasticsearch Agent Builder using the Agent-to-Agent (A2A) protocol, with built-in benchmarking capabilities.
- Interactive Chat Interface: Real-time conversation with Elasticsearch agents
- A2A Protocol Support: Full implementation of the A2A protocol specification
- Benchmarking Tools: Run multiple chat sessions to measure response times and performance
- Context Management: Maintain conversation context across multiple messages
- Response Time Tracking: Automatic measurement of agent response times
- Statistics & Analytics: Comprehensive performance metrics (min, max, mean, median, standard deviation)
- JSON Export: Save benchmark results for further analysis
- Python 3.7 or higher
- Elasticsearch instance with Agent Builder enabled (Serverless or Stack 9.2.0+)
- Elasticsearch API key with access to Agent Builder
- Agent ID from your configured agent
-
Clone or download this repository
-
Install dependencies:
pip install -r requirements.txt- Create a
.envfile based on.env.example:
cp .env.example .env- Edit
.envand add your Elasticsearch credentials:
ELASTIC_URL=https://your-elasticsearch-instance.elastic.cloud
AGENT_ID=your-agent-id
API_KEY=your-api-keyStart an interactive chat session with your agent:
python chatbot.pyCommands in chat mode:
- Type your message and press Enter to chat
new- Start a new conversation contextexitorquit- Exit the chat
Enable debug mode:
python chatbot.py --debugIf responses aren't working correctly, use the debug script to inspect raw API communication:
python debug_chat.pyThis will show:
- The exact request payload being sent
- The complete response structure from Elasticsearch
- Analysis of where the response text should be extracted from
Run performance benchmarks on your agent:
Basic benchmark with custom messages:
python benchmark.py -m "Hello" "How are you?" "Goodbye" -i 10Using a configuration file:
python benchmark.py -c benchmark_config.jsonWith shared context across iterations:
python benchmark.py -m "Hello" "Tell me more" --shared-context -i 5Save results to file:
python benchmark.py -m "Test message" -i 10 -o results.jsonCreate a JSON file to define your benchmark:
{
"messages": [
"Hello, how can you help me?",
"What are your capabilities?",
"Can you help me with data analysis?",
"Thank you for the information"
],
"iterations": 10
}benchmark.py options:
-m, --messages: Messages to send (space-separated)-i, --iterations: Number of iterations (default: 5)-c, --config: Path to JSON configuration file--shared-context: Use same context across all iterations-o, --output: Output file for results (JSON format)
Core client implementing the A2A protocol:
- JSON-RPC 2.0 message formatting
- HTTP communication with Elasticsearch
- Response time measurement
- Agent card retrieval
Interactive chat interface:
- Colored terminal output
- Context management
- Real-time conversation
- Agent information display
Performance testing tool:
- Multiple iteration support
- Statistical analysis
- JSON export capability
- Configurable test scenarios
Benchmark results include:
Statistics:
- Total requests
- Successful requests
- Min/Max response times
- Mean response time
- Median response time
- Standard deviation
- Total elapsed time
Detailed Results:
- Per-iteration timing
- Individual message responses
- Error tracking
==========================================
Agent Information:
==========================================
Agent ID: my-agent-123
Name: Customer Support Agent
==========================================
You: Hello, how can you help me?
Agent: I can help you with customer inquiries, product information, and support requests.
(Response time: 1.23s)
==========================================
Benchmark Results
==========================================
Total Requests: 30
Successful: 30
Response Times (seconds):
Min: 0.856s
Max: 2.134s
Mean: 1.245s
Median: 1.198s
StdDev: 0.312s
Total: 37.350s
==========================================
This implementation follows the A2A protocol specification:
- JSON-RPC 2.0: Standard request/response format
- Message Structure: Supports text, file, and data parts
- Context Tracking: Maintains conversation context via contextId
- Error Handling: Proper error code handling per specification
Agent only returns description/greeting instead of responding:
This was a common issue caused by incorrect request format. Fixed in latest version - the client now sends messages directly to Elasticsearch without the JSON-RPC 2.0 wrapper (which Elasticsearch doesn't use).
If you still have issues:
-
Update your code - Make sure you're using the latest version where
use_jsonrpc=Falseis the default -
Run debug script to see raw requests:
python debug_chat.py
This will show the exact request/response format being used.
-
Enable debug mode in chatbot:
python chatbot.py --debug
Or set in
.env:DEBUG=true -
Verify the request format:
- By default, messages are sent directly (not wrapped in JSON-RPC)
- The request should be just the message object with
messageId,role, andparts - If you need JSON-RPC format for some reason, set
use_jsonrpc=True
Authentication errors:
- Verify your API key is correct
- Ensure the API key has Agent Builder permissions
Connection errors:
- Check your ELASTIC_URL is correct
- Verify network connectivity to Elasticsearch
Agent not found:
- Confirm your AGENT_ID exists
- Check agent is deployed and accessible
Missing dependencies:
pip install -r requirements.txt- Never commit your
.envfile to version control - Keep your API key secure
- Use environment variables for sensitive configuration
- Rotate API keys regularly
This project is provided as-is for use with Elasticsearch Agent Builder.