Skip to content

Commit 5a285e9

Browse files
committed
Merge: Resolve requirements.txt conflict and integrate API dependencies with data pipeline dependencies
2 parents b13613d + aca481d commit 5a285e9

31 files changed

+4397
-5
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,5 @@ node_modules/
122122

123123
# OS files
124124
.DS_Storen
125-
Thumbs.db
125+
Thumbs.db
126+
.augment-guidelines

docs/api.md

Lines changed: 335 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,335 @@
1+
# API Documentation
2+
3+
This document describes the API for DataMCPServerAgent.
4+
5+
## Overview
6+
7+
The DataMCPServerAgent API provides a RESTful interface to interact with the agent system. It allows you to:
8+
9+
- Chat with agents
10+
- Manage agent instances
11+
- Access and manipulate memory
12+
- Execute tools
13+
- Check the health of the API
14+
15+
## Getting Started
16+
17+
### Running the API Server
18+
19+
You can run the API server using the `main.py` script with the `--mode=api` option:
20+
21+
```bash
22+
python main.py --mode=api --host 0.0.0.0 --port 8000 --reload --debug
23+
```
24+
25+
Or you can use the dedicated `run_api.py` script:
26+
27+
```bash
28+
python run_api.py --host 0.0.0.0 --port 8000 --reload --debug
29+
```
30+
31+
### API Documentation
32+
33+
Once the API server is running, you can access the API documentation at:
34+
35+
- Swagger UI: `http://localhost:8000/docs`
36+
- ReDoc: `http://localhost:8000/redoc`
37+
38+
## Authentication
39+
40+
The API supports API key authentication. To enable authentication, set the following environment variables:
41+
42+
```bash
43+
API_ENABLE_AUTH=true
44+
API_KEY_HEADER=X-API-Key
45+
API_KEYS=key1,key2,key3
46+
```
47+
48+
When authentication is enabled, you need to include the API key in the request header:
49+
50+
```
51+
X-API-Key: key1
52+
```
53+
54+
## Endpoints
55+
56+
### Root
57+
58+
- `GET /`: Get API information
59+
60+
### Health
61+
62+
- `GET /health`: Check the health of the API
63+
64+
### Agents
65+
66+
- `GET /agents`: List all available agent modes
67+
- `GET /agents/{agent_mode}`: Get information about a specific agent mode
68+
- `POST /agents`: Create a new agent instance
69+
70+
### Chat
71+
72+
- `POST /chat`: Send a message to the agent and get a response
73+
- `POST /chat/stream`: Send a message to the agent and get a streaming response
74+
- `GET /chat/sessions/{session_id}`: Get chat history for a session
75+
76+
### Memory
77+
78+
- `POST /memory`: Store a memory item
79+
- `GET /memory/{session_id}`: Retrieve memory items for a session
80+
- `DELETE /memory/{session_id}`: Clear memory for a session
81+
82+
### Tools
83+
84+
- `GET /tools`: List all available tools
85+
- `POST /tools/execute`: Execute a tool
86+
87+
## Request and Response Models
88+
89+
### Chat
90+
91+
#### ChatRequest
92+
93+
```json
94+
{
95+
"message": "Hello, agent!",
96+
"session_id": "optional-session-id",
97+
"agent_mode": "basic",
98+
"user_id": "optional-user-id",
99+
"context": {
100+
"key": "value"
101+
},
102+
"stream": false
103+
}
104+
```
105+
106+
#### ChatResponse
107+
108+
```json
109+
{
110+
"message_id": "unique-message-id",
111+
"response": "Hello! How can I help you today?",
112+
"session_id": "session-id",
113+
"created_at": "2023-01-01T00:00:00Z",
114+
"agent_mode": "basic",
115+
"tool_usage": [
116+
{
117+
"tool_name": "web_search",
118+
"tool_input": {
119+
"query": "example query"
120+
},
121+
"tool_output": "example output"
122+
}
123+
],
124+
"sources": [
125+
{
126+
"url": "https://example.com",
127+
"title": "Example Page",
128+
"snippet": "Example snippet"
129+
}
130+
],
131+
"metadata": {
132+
"user_id": "user-id",
133+
"context": {
134+
"key": "value"
135+
}
136+
}
137+
}
138+
```
139+
140+
### Agents
141+
142+
#### AgentRequest
143+
144+
```json
145+
{
146+
"agent_mode": "basic",
147+
"config": {
148+
"key": "value"
149+
}
150+
}
151+
```
152+
153+
#### AgentResponse
154+
155+
```json
156+
{
157+
"agent_id": "unique-agent-id",
158+
"agent_mode": "basic",
159+
"status": "available",
160+
"capabilities": ["chat", "web_search", "web_browsing"],
161+
"created_at": "2023-01-01T00:00:00Z",
162+
"metadata": {
163+
"description": "Basic Agent"
164+
}
165+
}
166+
```
167+
168+
### Memory
169+
170+
#### MemoryRequest
171+
172+
```json
173+
{
174+
"session_id": "session-id",
175+
"query": "optional-query",
176+
"memory_item": {
177+
"key": "value"
178+
},
179+
"memory_backend": "sqlite"
180+
}
181+
```
182+
183+
#### MemoryResponse
184+
185+
```json
186+
{
187+
"session_id": "session-id",
188+
"memory_items": [
189+
{
190+
"id": "memory-id",
191+
"content": "Memory content",
192+
"timestamp": "2023-01-01T00:00:00Z",
193+
"metadata": {
194+
"key": "value"
195+
}
196+
}
197+
],
198+
"memory_backend": "sqlite",
199+
"metadata": {
200+
"operation": "retrieve",
201+
"query": "optional-query",
202+
"limit": 10,
203+
"offset": 0,
204+
"timestamp": "2023-01-01T00:00:00Z"
205+
}
206+
}
207+
```
208+
209+
### Tools
210+
211+
#### ToolRequest
212+
213+
```json
214+
{
215+
"tool_name": "web_search",
216+
"tool_input": {
217+
"query": "example query"
218+
},
219+
"session_id": "optional-session-id",
220+
"agent_mode": "basic"
221+
}
222+
```
223+
224+
#### ToolResponse
225+
226+
```json
227+
{
228+
"tool_name": "web_search",
229+
"tool_output": "example output",
230+
"execution_time": 0.5,
231+
"status": "success",
232+
"metadata": {
233+
"session_id": "session-id",
234+
"agent_mode": "basic",
235+
"tool_input": {
236+
"query": "example query"
237+
}
238+
}
239+
}
240+
```
241+
242+
## Error Handling
243+
244+
The API returns appropriate HTTP status codes and error responses:
245+
246+
```json
247+
{
248+
"error_code": "ERROR_CODE",
249+
"error_message": "Error message",
250+
"error_details": {
251+
"key": "value"
252+
},
253+
"request_id": "request-id"
254+
}
255+
```
256+
257+
## Rate Limiting
258+
259+
The API supports rate limiting. To enable rate limiting, set the following environment variables:
260+
261+
```bash
262+
API_ENABLE_RATE_LIMITING=true
263+
API_RATE_LIMIT_PER_MINUTE=60
264+
```
265+
266+
When rate limiting is enabled, the API will return a 429 Too Many Requests response if the client exceeds the rate limit.
267+
268+
## Environment Variables
269+
270+
The API can be configured using environment variables:
271+
272+
### API Settings
273+
274+
- `API_TITLE`: API title
275+
- `API_DESCRIPTION`: API description
276+
- `API_VERSION`: API version
277+
- `API_OPENAPI_URL`: OpenAPI URL
278+
- `API_DOCS_URL`: Swagger UI URL
279+
- `API_REDOC_URL`: ReDoc URL
280+
281+
### Server Settings
282+
283+
- `API_HOST`: Host to bind the server to
284+
- `API_PORT`: Port to bind the server to
285+
- `API_DEBUG`: Enable debug mode
286+
- `API_RELOAD`: Enable auto-reload on code changes
287+
288+
### Security Settings
289+
290+
- `API_ENABLE_AUTH`: Enable authentication
291+
- `API_KEY_HEADER`: API key header
292+
- `API_KEYS`: Comma-separated list of API keys
293+
294+
### CORS Settings
295+
296+
- `API_ALLOW_ORIGINS`: Comma-separated list of allowed origins for CORS
297+
- `API_ALLOW_METHODS`: Comma-separated list of allowed methods for CORS
298+
- `API_ALLOW_HEADERS`: Comma-separated list of allowed headers for CORS
299+
300+
### Rate Limiting
301+
302+
- `API_ENABLE_RATE_LIMITING`: Enable rate limiting
303+
- `API_RATE_LIMIT_PER_MINUTE`: Rate limit per minute
304+
305+
### Logging
306+
307+
- `API_LOG_LEVEL`: Log level
308+
309+
### Agent Settings
310+
311+
- `API_DEFAULT_AGENT_MODE`: Default agent mode
312+
- `API_ENABLE_ALL_TOOLS`: Enable all tools
313+
314+
### Memory Settings
315+
316+
- `API_MEMORY_BACKEND`: Memory backend (sqlite, file, redis, mongodb)
317+
318+
### Redis Settings
319+
320+
- `API_REDIS_HOST`: Redis host
321+
- `API_REDIS_PORT`: Redis port
322+
- `API_REDIS_DB`: Redis database
323+
- `API_REDIS_PASSWORD`: Redis password
324+
- `API_REDIS_PREFIX`: Redis key prefix
325+
326+
### MongoDB Settings
327+
328+
- `API_MONGODB_URI`: MongoDB URI
329+
- `API_MONGODB_DB`: MongoDB database
330+
331+
### Distributed Settings
332+
333+
- `API_ENABLE_DISTRIBUTED`: Enable distributed mode
334+
- `API_DISTRIBUTED_BACKEND`: Distributed backend (redis, mongodb)
335+
- `API_SESSION_STORE`: Session store (redis, mongodb, memory)

0 commit comments

Comments
 (0)