Upload README.md
Browse files
examples/smolagents_benchmark/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Smolagents Chat Server Demo
|
2 |
+
|
3 |
+
This is a simple web server that provides a chat interface for interacting with an AI code agent powered by `smolagents` and the Qwen2.5-Coder-32B-Instruct model, enhanced with MCP (Model Control Protocol) tools.
|
4 |
+
|
5 |
+
## Features
|
6 |
+
|
7 |
+
- Web-based chat interface
|
8 |
+
- AI code agent powered by Qwen2.5-Coder
|
9 |
+
- Integration with MCP tools through MCPClient
|
10 |
+
- Asynchronous request handling
|
11 |
+
- Clean, responsive UI
|
12 |
+
- Graceful shutdown handling
|
13 |
+
|
14 |
+
## Requirements
|
15 |
+
|
16 |
+
- Python 3.8+
|
17 |
+
- Starlette
|
18 |
+
- AnyIO
|
19 |
+
- Smolagents with MCP support
|
20 |
+
|
21 |
+
## Installation
|
22 |
+
|
23 |
+
1. Install the required packages:
|
24 |
+
|
25 |
+
```bash
|
26 |
+
pip install starlette anyio smolagents[mcp] uvicorn
|
27 |
+
```
|
28 |
+
|
29 |
+
2. Optional: If you want to use a specific model, you may need additional dependencies.
|
30 |
+
|
31 |
+
## Usage
|
32 |
+
|
33 |
+
1. Run the server:
|
34 |
+
|
35 |
+
```bash
|
36 |
+
uvicorn examples.server.main:app --reload
|
37 |
+
```
|
38 |
+
|
39 |
+
2. Open your browser and navigate to `http://localhost:8000`
|
40 |
+
|
41 |
+
3. Interact with the AI code agent through the chat interface
|
42 |
+
|
43 |
+
## How It Works
|
44 |
+
|
45 |
+
The server consists of two main routes:
|
46 |
+
- `/` - Serves the HTML page with the chat interface
|
47 |
+
- `/chat` - API endpoint that processes messages and returns responses
|
48 |
+
|
49 |
+
The server integrates with MCP tools through the following components:
|
50 |
+
|
51 |
+
1. MCPClient Configuration:
|
52 |
+
```python
|
53 |
+
mcp_server_parameters = {
|
54 |
+
"url": "https://evalstate-hf-mcp-server.hf.space/mcp",
|
55 |
+
"transport": "streamable-http",
|
56 |
+
}
|
57 |
+
mcp_client = MCPClient(server_parameters=mcp_server_parameters)
|
58 |
+
```
|
59 |
+
|
60 |
+
2. CodeAgent with MCP Tools:
|
61 |
+
```python
|
62 |
+
agent = CodeAgent(
|
63 |
+
model=InferenceClientModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct"),
|
64 |
+
tools=mcp_client.get_tools(),
|
65 |
+
)
|
66 |
+
```
|
67 |
+
|
68 |
+
When a user sends a message:
|
69 |
+
1. The message is sent to the `/chat` endpoint
|
70 |
+
2. The server runs the AI code agent in a separate thread
|
71 |
+
3. The agent processes the message using MCP tools
|
72 |
+
4. The agent's response is returned to the client and displayed in the chat
|
73 |
+
|
74 |
+
The server also includes a shutdown handler that properly disconnects the MCP client when the server stops:
|
75 |
+
```python
|
76 |
+
async def shutdown():
|
77 |
+
mcp_client.disconnect()
|
78 |
+
```
|
79 |
+
|
80 |
+
## Customization
|
81 |
+
|
82 |
+
You can modify the `CodeAgent` configuration by changing the model or MCP server parameters. For example:
|
83 |
+
|
84 |
+
```python
|
85 |
+
# Custom MCP server
|
86 |
+
mcp_server_parameters = {
|
87 |
+
"url": "your-mcp-server-url",
|
88 |
+
"transport": "your-transport-method",
|
89 |
+
}
|
90 |
+
|
91 |
+
# Custom agent configuration
|
92 |
+
agent = CodeAgent(
|
93 |
+
model=InferenceClientModel(model_id="your-preferred-model"),
|
94 |
+
tools=mcp_client.get_tools(),
|
95 |
+
)
|
96 |
+
```
|