File size: 20,432 Bytes
2ec0d39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
# Secure AI Agents Suite - API Reference Documentation

## Overview

The Secure AI Agents Suite provides a comprehensive API for autonomous AI agent interactions. This documentation covers all endpoints, parameters, response formats, and usage examples.

## Table of Contents

1. [Base URL and Authentication](#base-url-and-authentication)
2. [Core Endpoints](#core-endpoints)
3. [Agent Management](#agent-management)
4. [Performance Monitoring](#performance-monitoring)
5. [WebSocket APIs](#websocket-apis)
6. [Error Handling](#error-handling)
7. [Rate Limiting](#rate-limiting)
8. [SDK Reference](#sdk-reference)

## Base URL and Authentication

### Base URL
```
Production: https://your-space-url.hf.space
Local: http://localhost:7860
```

### Authentication
```python
# Headers
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
    "User-Agent": "Secure-AI-Agents-Suite/2.0.0"
}
```

### API Versioning
```python
# Current version: v1
headers["API-Version"] = "v1"
```

## Core Endpoints

### 1. Process Request

#### POST /api/v1/process

**Description**: Process a user request through the autonomous agent system.

**Request Body**:
```json
{
    "user_input": "string",
    "context": {
        "budget": "number",
        "timeline": "string",
        "team_size": "number",
        "industry": "string",
        "additional_params": "object"
    },
    "agent_type": "string",
    "max_execution_time": "number",
    "options": {
        "enable_monitoring": "boolean",
        "save_results": "boolean",
        "async_mode": "boolean"
    }
}
```

**Parameters**:

| Parameter | Type | Required | Description | Default |
|-----------|------|----------|-------------|---------|
| `user_input` | string | Yes | The user's request text (max 10,000 chars) | - |
| `context` | object | No | Additional context as key-value pairs | {} |
| `agent_type` | string | No | Agent type ("GeneralAgent", "EnterpriseAgent", etc.) | "GeneralAgent" |
| `max_execution_time` | number | No | Maximum execution time in seconds (30-300) | 120 |
| `options.enable_monitoring` | boolean | No | Enable detailed monitoring | true |
| `options.save_results` | boolean | No | Save results for later retrieval | true |
| `options.async_mode` | boolean | No | Run request asynchronously | false |

**Response**:
```json
{
    "status": "success",
    "request_id": "uuid-string",
    "timestamp": "2024-11-29T17:04:26.632Z",
    "agent_type": "GeneralAgent",
    "processing_time": 0.142,
    "results": {
        "analysis": {
            "intent": {
                "primary": "strategic_planning",
                "secondary": ["content_creation", "market_analysis"],
                "confidence": 0.89
            },
            "complexity": {
                "level": "high",
                "score": 8.5,
                "factors": ["multi_step_planning", "strategic_thinking"],
                "estimated_duration_minutes": 15
            },
            "success_probability": 0.85,
            "risk_factors": ["time_constraint", "resource_availability"],
            "adaptation_requirements": ["dynamic_planning", "feedback_integration"]
        },
        "plan": {
            "tasks": [
                {
                    "id": 1,
                    "description": "Market research and competitor analysis",
                    "priority": "high",
                    "duration_minutes": 120,
                    "dependencies": [],
                    "success_criteria": ["comprehensive_analysis", "actionable_insights"],
                    "fallback_strategies": ["use_previous_data", "simplified_analysis"]
                }
            ],
            "total_estimated_duration": 240,
            "critical_path": [1, 2, 3],
            "resource_requirements": {
                "cpu": "moderate",
                "memory": "high",
                "storage": "low"
            },
            "risk_mitigation": {
                "primary_risks": ["resource_shortage", "time_constraints"],
                "mitigation_strategies": ["resource_pooling", "parallel_processing"]
            }
        },
        "execution": {
            "status": "completed",
            "completed_tasks": 3,
            "total_tasks": 3,
            "success_rate": 1.0,
            "execution_time_minutes": 8.5,
            "adaptations_made": 1,
            "decisions_made": 2,
            "failed_tasks": [],
            "performance_metrics": {
                "efficiency_score": 0.92,
                "quality_score": 0.89,
                "completion_rate": 1.0
            },
            "iterations": [
                {
                    "iteration": 1,
                    "tasks_executed": 2,
                    "success_rate": 0.9,
                    "changes_made": ["refined_strategy", "adjusted_timeline"]
                }
            ]
        },
        "summary": "Comprehensive 3-month marketing strategy created with optimized budget allocation...",
        "recommendations": [
            "Focus on digital channels for cost-effectiveness",
            "Implement A/B testing for campaign optimization",
            "Consider seasonal trends in timing"
        ]
    },
    "monitoring": {
        "memory_usage": "145MB",
        "cpu_utilization": "12.5%",
        "cache_hit_rate": 0.78,
        "error_rate": 0.0
    },
    "metadata": {
        "version": "2.0.0",
        "model_used": "autonomous_engine_v2",
        "processing_mode": "synchronous"
    }
}
```

**Status Codes**:
- `200`: Success
- `400`: Bad Request (validation error)
- `429`: Rate Limit Exceeded
- `500`: Internal Server Error
- `503`: Service Unavailable

**Example Usage**:
```python
import requests
import json

url = "http://localhost:7860/api/v1/process"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer your-api-key"
}

payload = {
    "user_input": "Create a comprehensive marketing plan for our new mobile app",
    "context": {
        "budget": 50000,
        "timeline": "3 months",
        "team_size": 5,
        "industry": "technology"
    },
    "agent_type": "EnterpriseAgent",
    "max_execution_time": 180,
    "options": {
        "enable_monitoring": True,
        "save_results": True,
        "async_mode": False
    }
}

response = requests.post(url, json=payload, headers=headers)
result = response.json()
print(json.dumps(result, indent=2))
```

### 2. Get Request Status

#### GET /api/v1/status/{request_id}

**Description**: Get the status of an asynchronous request.

**Path Parameters**:
- `request_id` (string): The unique request identifier

**Response**:
```json
{
    "status": "completed",
    "request_id": "uuid-string",
    "timestamp": "2024-11-29T17:04:26.632Z",
    "progress": {
        "stage": "execution",
        "completed_percentage": 75,
        "current_task": "content generation",
        "estimated_completion": "2024-11-29T17:05:00.000Z"
    },
    "partial_results": {
        "analysis": "completed",
        "plan": "completed",
        "execution": "in_progress"
    },
    "errors": [],
    "estimated_total_time": 120
}
```

### 3. Get Results

#### GET /api/v1/results/{request_id}

**Description**: Retrieve the complete results of a completed request.

**Path Parameters**:
- `request_id` (string): The unique request identifier

**Query Parameters**:
- `format` (string): Response format ("json", "summary", "detailed") - default: "json"

**Response**: Same as POST /api/v1/process response format.

## Agent Management

### 4. List Available Agents

#### GET /api/v1/agents

**Description**: Get list of available agent types and their capabilities.

**Response**:
```json
{
    "agents": [
        {
            "name": "GeneralAgent",
            "type": "general",
            "description": "Multi-domain task handling with balanced capabilities",
            "capabilities": [
                "task_planning",
                "context_analysis",
                "adaptive_execution"
            ],
            "specialties": ["general_purpose", "flexible_thinking"],
            "max_context_length": 5000,
            "typical_response_time": 0.15,
            "success_rate": 0.98
        },
        {
            "name": "EnterpriseAgent",
            "type": "enterprise",
            "description": "Strategic business planning and enterprise-level decision making",
            "capabilities": [
                "strategic_planning",
                "business_analysis",
                "risk_assessment",
                "compliance_awareness"
            ],
            "specialties": ["business_strategy", "financial_planning", "operational_optimization"],
            "max_context_length": 10000,
            "typical_response_time": 0.20,
            "success_rate": 0.96
        }
    ],
    "total_agents": 5,
    "default_agent": "GeneralAgent"
}
```

### 5. Get Agent Info

#### GET /api/v1/agents/{agent_name}

**Description**: Get detailed information about a specific agent.

**Path Parameters**:
- `agent_name` (string): Name of the agent

**Response**:
```json
{
    "name": "EnterpriseAgent",
    "configuration": {
        "temperature": 0.7,
        "max_tokens": 2000,
        "top_p": 0.9,
        "frequency_penalty": 0.0,
        "presence_penalty": 0.0
    },
    "capabilities": [
        {
            "name": "strategic_planning",
            "description": "Long-term strategic planning and roadmap development",
            "supported_contexts": ["business", "finance", "operations"],
            "quality_score": 0.95
        }
    ],
    "performance_metrics": {
        "total_requests": 1250,
        "success_rate": 0.96,
        "average_response_time": 0.20,
        "memory_efficiency": 0.85,
        "error_rate": 0.04
    },
    "limitations": {
        "max_input_length": 10000,
        "max_execution_time": 300,
        "context_overflow_handling": "truncate"
    }
}
```

## Performance Monitoring

### 6. System Health

#### GET /api/v1/health

**Description**: Get system health and status information.

**Response**:
```json
{
    "status": "healthy",
    "timestamp": "2024-11-29T17:04:26.632Z",
    "uptime_seconds": 86400,
    "version": "2.0.0",
    "system": {
        "memory": {
            "total_gb": 8.0,
            "used_gb": 2.5,
            "available_gb": 5.5,
            "usage_percentage": 31.25
        },
        "cpu": {
            "cores": 4,
            "usage_percentage": 12.5,
            "load_average": [0.5, 0.3, 0.2]
        },
        "disk": {
            "total_gb": 100.0,
            "used_gb": 15.0,
            "available_gb": 85.0,
            "usage_percentage": 15.0
        }
    },
    "services": {
        "api_server": "healthy",
        "agent_manager": "healthy",
        "cache_server": "healthy",
        "database": "not_configured"
    },
    "metrics": {
        "total_requests": 1250,
        "requests_per_minute": 5.2,
        "average_response_time": 0.142,
        "error_rate": 0.02
    }
}
```

### 7. Performance Metrics

#### GET /api/v1/metrics

**Description**: Get detailed performance metrics.

**Query Parameters**:
- `time_range` (string): Time range for metrics ("1h", "24h", "7d", "30d") - default: "1h"
- `include_agent_details` (boolean): Include per-agent metrics - default: false

**Response**:
```json
{
    "time_range": "1h",
    "timestamp": "2024-11-29T17:04:26.632Z",
    "overall_metrics": {
        "total_requests": 125,
        "successful_requests": 123,
        "failed_requests": 2,
        "success_rate": 0.984,
        "average_response_time": 0.142,
        "p50_response_time": 0.120,
        "p95_response_time": 0.280,
        "p99_response_time": 0.450,
        "requests_per_minute": 2.1,
        "peak_requests_per_minute": 8.5
    },
    "agent_metrics": {
        "GeneralAgent": {
            "requests": 75,
            "success_rate": 0.987,
            "average_response_time": 0.138,
            "error_rate": 0.013
        }
    },
    "system_metrics": {
        "memory_usage": {
            "peak_gb": 3.2,
            "average_gb": 2.1,
            "current_gb": 2.5
        },
        "cpu_usage": {
            "peak_percentage": 25.0,
            "average_percentage": 12.5,
            "current_percentage": 15.0
        }
    },
    "error_breakdown": {
        "validation_errors": 1,
        "timeout_errors": 1,
        "system_errors": 0
    },
    "cache_performance": {
        "hit_rate": 0.78,
        "total_requests": 125,
        "cache_hits": 98,
        "cache_misses": 27
    }
}
```

### 8. Analytics Dashboard Data

#### GET /api/v1/analytics

**Description**: Get data for analytics dashboard.

**Query Parameters**:
- `dashboard_type` (string): Type of dashboard ("overview", "performance", "agents")
- `time_range` (string): Time range for data
- `granularity` (string): Data granularity ("minute", "hour", "day")

**Response**:
```json
{
    "dashboard_type": "overview",
    "time_range": "24h",
    "granularity": "hour",
    "data": {
        "response_times": [
            {"timestamp": "2024-11-29T16:00:00.000Z", "value": 0.145},
            {"timestamp": "2024-11-29T17:00:00.000Z", "value": 0.142}
        ],
        "success_rates": [
            {"timestamp": "2024-11-29T16:00:00.000Z", "value": 0.98},
            {"timestamp": "2024-11-29T17:00:00.000Z", "value": 0.984}
        ],
        "request_counts": [
            {"timestamp": "2024-11-29T16:00:00.000Z", "value": 65},
            {"timestamp": "2024-11-29T17:00:00.000Z", "value": 60}
        ],
        "agent_distribution": [
            {"agent": "GeneralAgent", "count": 85, "percentage": 68},
            {"agent": "EnterpriseAgent", "count": 25, "percentage": 20}
        ]
    },
    "trends": {
        "response_time_trend": "decreasing",
        "success_rate_trend": "stable",
        "request_volume_trend": "increasing"
    }
}
```

## WebSocket APIs

### 9. Real-time Metrics Stream

#### WebSocket /ws/metrics

**Description**: Stream real-time performance metrics.

**Connection**:
```javascript
const ws = new WebSocket('ws://localhost:7860/ws/metrics');
```

**Message Format**:
```json
{
    "type": "metrics_update",
    "timestamp": "2024-11-29T17:04:26.632Z",
    "data": {
        "response_time": 0.142,
        "memory_usage": 67.2,
        "cpu_usage": 12.5,
        "active_requests": 3,
        "queue_size": 0
    }
}
```

### 10. Execution Progress Stream

#### WebSocket /ws/progress/{request_id}

**Description**: Stream execution progress for a specific request.

**Message Types**:

**Progress Update**:
```json
{
    "type": "progress_update",
    "request_id": "uuid",
    "timestamp": "2024-11-29T17:04:26.632Z",
    "data": {
        "stage": "execution",
        "current_task": "generating_content",
        "completed_tasks": 2,
        "total_tasks": 5,
        "progress_percentage": 40,
        "estimated_time_remaining": 45
    }
}
```

**Completion**:
```json
{
    "type": "completion",
    "request_id": "uuid",
    "timestamp": "2024-11-29T17:04:26.632Z",
    "status": "success",
    "summary": "Request completed successfully"
}
```

## Error Handling

### Error Response Format

```json
{
    "error": {
        "code": "VALIDATION_ERROR",
        "message": "Input validation failed",
        "details": {
            "field": "user_input",
            "reason": "Input too long",
            "max_length": 10000,
            "current_length": 15000
        },
        "timestamp": "2024-11-29T17:04:26.632Z",
        "request_id": "uuid-string",
        "documentation_url": "https://docs.example.com/errors/VALIDATION_ERROR"
    }
}
```

### Error Codes

| Code | Description | HTTP Status | Recovery |
|------|-------------|-------------|----------|
| `VALIDATION_ERROR` | Input validation failed | 400 | Fix input parameters |
| `RATE_LIMIT_EXCEEDED` | Rate limit exceeded | 429 | Wait and retry |
| `AGENT_UNAVAILABLE` | Requested agent unavailable | 503 | Try different agent |
| `EXECUTION_TIMEOUT` | Request execution timed out | 504 | Increase timeout or simplify |
| `MEMORY_LIMIT_EXCEEDED` | System memory limit exceeded | 507 | Reduce concurrent requests |
| `INTERNAL_ERROR` | Internal server error | 500 | Contact support |

## Rate Limiting

### Rate Limits

- **Global**: 100 requests per minute
- **Per IP**: 100 requests per minute
- **Per Agent**: 200 requests per minute per agent type
- **Burst Limit**: 20 requests per second

### Rate Limit Headers

```http
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1640995200
X-RateLimit-Window: 60
```

### Rate Limit Response

```json
{
    "error": {
        "code": "RATE_LIMIT_EXCEEDED",
        "message": "Rate limit exceeded. Try again in 30 seconds.",
        "retry_after": 30,
        "limit": 100,
        "window": 60
    }
}
```

## SDK Reference

### Python SDK

#### Installation
```bash
pip install secure-ai-agents-suite
```

#### Basic Usage
```python
from secure_ai_agents import AgentClient

# Initialize client
client = AgentClient(
    base_url="http://localhost:7860",
    api_key="your-api-key"
)

# Process request
result = client.process_request(
    user_input="Create a marketing strategy",
    context={"budget": 50000, "timeline": "3 months"},
    agent_type="EnterpriseAgent"
)

print(result.summary)
```

#### Async Usage
```python
import asyncio
from secure_ai_agents import AsyncAgentClient

async def main():
    client = AsyncAgentClient(base_url="http://localhost:7860")
    
    # Submit async request
    request_id = await client.submit_request(
        user_input="Complex multi-step workflow",
        context={"priority": "high"}
    )
    
    # Monitor progress
    async for progress in client.monitor_progress(request_id):
        print(f"Progress: {progress.progress_percentage}%")
    
    # Get results
    result = await client.get_results(request_id)
    print(result.summary)

asyncio.run(main())
```

### JavaScript SDK

#### Installation
```bash
npm install secure-ai-agents-suite
```

#### Basic Usage
```javascript
import { AgentClient } from 'secure-ai-agents-suite';

const client = new AgentClient({
    baseUrl: 'http://localhost:7860',
    apiKey: 'your-api-key'
});

// Process request
const result = await client.processRequest({
    userInput: 'Create a business plan',
    context: { industry: 'technology', size: 'startup' },
    agentType: 'EnterpriseAgent'
});

console.log(result.summary);
```

#### WebSocket Usage
```javascript
// Real-time progress monitoring
const progressStream = client.monitorProgress('request-id');

progressStream.on('progress', (progress) => {
    console.log(`Progress: ${progress.completedTasks}/${progress.totalTasks}`);
});

progressStream.on('complete', (result) => {
    console.log('Request completed:', result.summary);
});
```

### Response Streaming

For large responses, you can enable streaming:

```python
client = AgentClient(base_url="http://localhost:7860", stream=True)

async for chunk in client.process_request_stream(
    user_input="Complex analysis request"
):
    print(chunk)  # Process each chunk as it arrives
```

## Rate Limiting and Performance

### Best Practices

1. **Use Async Mode**: For complex requests, use `async_mode: true`
2. **Batch Processing**: Group similar requests when possible
3. **Context Optimization**: Keep context data minimal and relevant
4. **Timeout Management**: Set appropriate timeouts based on request complexity
5. **Error Handling**: Implement proper error handling with exponential backoff

### Performance Optimization

```python
# Enable response caching
client = AgentClient(
    base_url="http://localhost:7860",
    cache_responses=True,
    cache_ttl=3600
)

# Use connection pooling
client = AgentClient(
    base_url="http://localhost:7860",
    max_connections=10,
    max_keepalive_connections=5
)

# Enable compression
client = AgentClient(
    base_url="http://localhost:7860",
    compression=True
)
```

## Changelog

### Version 2.0.0 (2024-11-29)

- Added autonomous planning and reasoning capabilities
- Implemented real-time performance monitoring
- Added WebSocket APIs for streaming
- Enhanced security with input validation
- Improved error handling and recovery
- Added comprehensive API documentation

### Version 1.5.0

- Basic agent functionality
- Simple request/response API
- Performance monitoring