symbi-runtime 1.7.1

Agent Runtime System for the Symbi platform
Documentation
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
# Symbiont Tool Review Workflow

An AI-driven system for automated security analysis, human review, and digital signing of MCP (Model Context Protocol) tools within the Symbiont platform.

## Overview

The Tool Review Workflow provides a complete solution for ensuring the security and integrity of MCP tools before they are deployed in production environments. The system combines advanced AI-powered security analysis with human oversight and cryptographic signing to create a robust, auditable workflow.

### Key Features

- 🤖 **AI-Powered Security Analysis**: RAG-enhanced vulnerability detection using comprehensive security knowledge base
- 👤 **Human-in-the-Loop Review**: Streamlined interface for security experts to review critical findings
- 🔐 **Cryptographic Signing**: Digital signing of approved tools using SchemaPin integration
- 📊 **Complete Audit Trail**: Immutable logging of all review decisions and state changes
-**High Performance**: Async Rust implementation supporting concurrent workflows
- 🔄 **State Management**: Robust state machine with error recovery and retry mechanisms

## Quick Start

### Prerequisites

- Rust 1.70+ with cargo
- PostgreSQL 14+
- Redis 6+
- Qdrant vector database

### Installation

1. **Clone and build**:
   ```bash
   git clone https://github.com/symbiont-platform/symbiont.git
   cd symbiont/runtime
   cargo build --release --features full
   ```

2. **Start dependencies**:
   ```bash
   docker-compose up -d postgres redis qdrant
   ```

3. **Configure environment**:
   ```bash
   export DATABASE_URL="postgresql://symbiont:password@localhost/symbiont_tool_review"
   export REDIS_URL="redis://localhost:6379"
   export QDRANT_URL="http://localhost:6333"
   export OPENAI_API_KEY="your_openai_api_key"
   ```

4. **Run the system**:
   ```bash
   cargo run --bin tool-review-api
   ```

### Basic Usage

```rust
use symbiont_runtime::integrations::tool_review::*;

// Submit a tool for review
let tool = McpTool {
    name: "my-tool".to_string(),
    description: "Custom MCP tool".to_string(),
    schema: serde_json::json!({
        "type": "object",
        "properties": {
            "input": {"type": "string"}
        }
    }),
    // ... other fields
};

let orchestrator = ToolReviewOrchestrator::new(/* components */);
let review_id = orchestrator.submit_tool(tool, "user@example.com".to_string()).await?;

// Monitor progress
let state = orchestrator.get_review_state(review_id).await?;
println!("Review status: {:?}", state);
```

## Architecture

The system consists of several key components:

```mermaid
graph TB
    subgraph "API Layer"
        API[REST API Server]
        WS[WebSocket Handler]
    end
    
    subgraph "Core Workflow"
        ORCH[Tool Review Orchestrator]
        SM[State Manager]
    end
    
    subgraph "Analysis Components"
        SA[Security Analyzer]
        KB[Knowledge Base]
        RAG[RAG Engine]
    end
    
    subgraph "Review Components"
        HRI[Human Review Interface]
        QUEUE[Review Queue]
    end
    
    subgraph "Signing Components"
        SP[SchemaPin CLI]
        KS[Key Store]
    end
    
    API --> ORCH
    ORCH --> SA
    ORCH --> HRI
    ORCH --> SP
    SA --> KB
    SA --> RAG
```

### Workflow States

The review process follows a well-defined state machine:

1. **PendingReview** → Tool submitted, waiting for analysis
2. **UnderReview** → AI security analysis in progress
3. **AwaitingHumanReview** → High-risk findings require human decision
4. **Approved** → Tool approved, ready for signing
5. **Signed** → Tool successfully signed and published
6. **Rejected** → Tool rejected due to security concerns

## Components

### [Security Analyzer]../src/integrations/tool_review/analyzer.rs
AI-powered component that analyzes MCP tool schemas for security vulnerabilities using:
- Pattern matching against known vulnerability signatures
- RAG-enhanced context retrieval for threat intelligence
- Risk scoring based on finding severity and confidence

### [Human Review Interface]../src/integrations/tool_review/review_interface.rs
Streamlined interface for security experts to:
- Review AI analysis findings
- Make approval/rejection decisions
- Add manual review notes
- Escalate complex cases

### [Tool Review Orchestrator]../src/integrations/tool_review/orchestrator.rs
Central coordinator that:
- Manages workflow state transitions
- Handles timeout and retry logic
- Emits audit events
- Coordinates between all components

### [Security Knowledge Base]../src/integrations/tool_review/knowledge_base.rs
Comprehensive database of:
- Vulnerability patterns and signatures
- Malicious code detection rules
- False positive indicators
- Remediation recommendations

### [SchemaPin Integration]../src/integrations/schemapin/
Cryptographic signing service that:
- Manages signing keys securely
- Generates digital signatures for approved tools
- Provides verification capabilities
- Integrates with hardware security modules

## API Reference

### REST API

Submit a tool for review:
```http
POST /v1/tool-review/sessions
Content-Type: application/json

{
  "tool": {
    "name": "example-tool",
    "description": "Example MCP tool",
    "schema": { /* JSON schema */ }
  },
  "submitted_by": "user@example.com"
}
```

Get review status:
```http
GET /v1/tool-review/sessions/{review_id}
```

Submit human decision:
```http
POST /v1/tool-review/review/{review_id}/decision
Content-Type: application/json

{
  "decision": "approve",
  "reasoning": "Tool appears safe after manual review",
  "operator_id": "reviewer@example.com"
}
```

### Internal APIs

The system exposes several Rust traits for customization:

- [`SecurityAnalyzer`]api/internal_apis.md#securityanalyzer-trait - Custom security analysis implementations
- [`HumanReviewInterface`]api/internal_apis.md#humanreviewinterface-trait - Custom review interfaces
- [`SchemaPinCli`]api/internal_apis.md#schemapincli-trait - Custom signing implementations

## Configuration

### Environment Variables

| Variable | Description | Required |
|----------|-------------|----------|
| `DATABASE_URL` | PostgreSQL connection string | Yes |
| `REDIS_URL` | Redis connection string | No |
| `QDRANT_URL` | Qdrant server URL | No |
| `OPENAI_API_KEY` | OpenAI API key for RAG | Yes |
| `SCHEMAPIN_KEY_PATH` | Path to signing keys | No |

### Configuration File

```toml
[workflow]
max_analysis_time_seconds = 300
max_human_review_time_seconds = 3600
auto_approve_threshold = 0.9
auto_reject_threshold = 0.1
max_signing_retries = 3

[security_analyzer]
confidence_threshold = 0.6
include_low_severity = false
max_rag_queries = 10

[review_interface]
max_queue_size = 100
priority_boost_hours = 24
```

## Security

The system implements multiple security layers:

- **Authentication**: Bearer token authentication for all API endpoints
- **Authorization**: Role-based access control (submitters, reviewers, admins)
- **Encryption**: TLS 1.3 for transport, AES-256 for data at rest
- **Key Management**: HSM integration for signing key protection
- **Audit Logging**: Immutable audit trail for all security-relevant operations

## Monitoring

Key metrics to monitor:

- `tool_review.submissions.total` - Total tool submissions
- `tool_review.analysis.duration_seconds` - Analysis processing time
- `tool_review.queue.pending_count` - Pending human reviews
- `tool_review.security.findings.total` - Security findings by severity
- `tool_review.signing.success_rate` - Signing success rate

Health check endpoint:
```http
GET /health
```

## Deployment

### Docker

```bash
docker-compose up -d
```

### Kubernetes

```bash
kubectl apply -f k8s/
```

### Monitoring Stack

The system integrates with:
- **Prometheus** for metrics collection
- **Grafana** for dashboards
- **Jaeger** for distributed tracing
- **ELK Stack** for centralized logging

## Documentation

- 📋 [Complete Workflow Documentation]tool_review_workflow.md - Comprehensive system documentation
- 🔌 [API Specifications]api/ - REST API and internal API documentation
- 🏗️ [Architecture Guide]tool_review_workflow.md#architecture - System architecture and design decisions
- 🚀 [Deployment Guide]tool_review_workflow.md#deployment-guide - Production deployment instructions
- 🔧 [Configuration Reference]tool_review_workflow.md#configuration - All configuration options
- 🛡️ [Security Guide]tool_review_workflow.md#security-considerations - Security best practices
- 📊 [Monitoring Guide]tool_review_workflow.md#monitoring-and-troubleshooting - Monitoring and troubleshooting

## Examples

### Complete Workflow Example

```rust
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize system components
    let orchestrator = ToolReviewOrchestrator::new(
        Box::new(AISecurityAnalyzer::new(rag_engine, agent_id)),
        Box::new(StandardReviewInterface::new(config)),
        Box::new(SchemaPinCliWrapper::new()?),
        ToolReviewConfig::default(),
    );
    
    // Submit tool for review
    let review_id = orchestrator.submit_tool(tool, "user@example.com".to_string()).await?;
    
    // Wait for completion
    loop {
        match orchestrator.get_review_state(review_id).await? {
            ToolReviewState::Signed { .. } => {
                println!("✅ Tool successfully signed!");
                break;
            }
            ToolReviewState::Rejected { rejection_reason, .. } => {
                println!("❌ Tool rejected: {}", rejection_reason);
                break;
            }
            _ => tokio::time::sleep(Duration::from_secs(1)).await,
        }
    }
    
    Ok(())
}
```

### Custom Event Handler

```rust
struct NotificationHandler;

#[async_trait]
impl WorkflowEventHandler for NotificationHandler {
    async fn handle_event(&self, event: WorkflowEvent) -> Result<(), Box<dyn std::error::Error>> {
        match event.event_type {
            WorkflowEventType::HumanReviewRequired => {
                send_slack_notification("Security team review needed").await?;
            }
            WorkflowEventType::ToolSigned => {
                send_email_notification("Tool approved and signed").await?;
            }
            _ => {}
        }
        Ok(())
    }
}
```

## Contributing

1. Fork the repository
2. Create a feature branch
3. Add tests for new functionality
4. Ensure all tests pass: `cargo test`
5. Submit a pull request

### Development Setup

```bash
# Install development dependencies
cargo install cargo-watch
cargo install cargo-tarpaulin

# Run tests with coverage
cargo tarpaulin --out html

# Watch for changes during development
cargo watch -x test
```

## Testing

The system includes comprehensive testing:

```bash
# Unit tests
cargo test --lib

# Integration tests
cargo test --test integration

# End-to-end tests
cargo test --test e2e

# Performance tests
cargo test --release --test performance
```

## Performance

Typical performance characteristics:

- **Analysis Time**: 2-5 seconds for standard tools
- **Throughput**: 100+ concurrent reviews
- **Queue Processing**: < 1 second per item
- **API Response Time**: < 100ms (95th percentile)

## Troubleshooting

Common issues and solutions:

### Analysis Timeouts
- Increase `max_analysis_time_seconds` configuration
- Check RAG engine connectivity
- Monitor vector database performance

### Human Review Backlog
- Scale review team
- Implement auto-escalation rules
- Optimize review interface workflow

### Signing Failures
- Verify key availability and permissions
- Check HSM connectivity
- Monitor certificate expiration

## License

Apache License 2.0 - see [LICENSE](../LICENSE) file for details.

## Support

- 📖 **Documentation**: [Complete workflow docs]tool_review_workflow.md
- 🐛 **Issues**: [GitHub Issues]https://github.com/symbiont-platform/symbiont/issues
- 💬 **Discussion**: [GitHub Discussions]https://github.com/symbiont-platform/symbiont/discussions
- 📧 **Email**: tool-review-support@symbiont.platform

---

**Built with ❤️ by the Symbiont Platform Team**