mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-04-29 06:49:45 +00:00
ci: fix sonarqube config and test suite failures
This commit is contained in:
parent
34bcb2b609
commit
5085dcf96f
138 changed files with 23558 additions and 33981 deletions
|
|
@ -4,11 +4,9 @@
|
|||
|
||||
---
|
||||
|
||||
> **Agent-to-Agent Protocol v0.3** — Enables any AI agent to use OmniRoute as an intelligent routing agent via JSON-RPC 2.0.
|
||||
> **Protocolo de agente a agente v0.3**: permite que cualquier agente de IA utilice OmniRoute como agente de enrutamiento inteligente a través de JSON-RPC 2.0.
|
||||
|
||||
The A2A Server exposes OmniRoute as a **first-class agent** that other agents can discover, delegate tasks to, and collaborate with using the [A2A Protocol](https://google.github.io/A2A/).
|
||||
|
||||
---
|
||||
El servidor A2A expone a OmniRoute como un**agente de primera clase**que otros agentes pueden descubrir, delegar tareas y colaborar mediante el [Protocolo A2A](https://google.github.io/A2A/).---
|
||||
|
||||
## Arquitectura
|
||||
|
||||
|
|
@ -43,15 +41,12 @@ The A2A Server exposes OmniRoute as a **first-class agent** that other agents ca
|
|||
|
||||
### Agent Discovery
|
||||
|
||||
Every A2A-compatible agent exposes an **Agent Card** at `/.well-known/agent.json`:
|
||||
|
||||
```bash
|
||||
Cada agente compatible con A2A expone una**Tarjeta de agente**en `/.well-known/agent.json`:```bash
|
||||
curl http://localhost:20128/.well-known/agent.json
|
||||
```
|
||||
|
||||
**Response:**
|
||||
````
|
||||
|
||||
```json
|
||||
**Respuesta:**```json
|
||||
{
|
||||
"name": "OmniRoute",
|
||||
"description": "Intelligent AI gateway with auto-routing across 50+ providers",
|
||||
|
|
@ -88,7 +83,7 @@ curl http://localhost:20128/.well-known/agent.json
|
|||
"apiKeyHeader": "Authorization"
|
||||
}
|
||||
}
|
||||
```
|
||||
````
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -96,27 +91,24 @@ curl http://localhost:20128/.well-known/agent.json
|
|||
|
||||
### `message/send` — Synchronous Execution
|
||||
|
||||
Send a message to a skill and receive the complete response.
|
||||
|
||||
```bash
|
||||
Envía un mensaje a una habilidad y recibe la respuesta completa.```bash
|
||||
curl -X POST http://localhost:20128/a2a \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_KEY" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"id": "1",
|
||||
"method": "message/send",
|
||||
"params": {
|
||||
"skill": "smart-routing",
|
||||
"messages": [{"role": "user", "content": "Write a Python hello world"}],
|
||||
"metadata": {"model": "auto", "combo": "fast-coding"}
|
||||
}
|
||||
}'
|
||||
```
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_KEY" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"id": "1",
|
||||
"method": "message/send",
|
||||
"params": {
|
||||
"skill": "smart-routing",
|
||||
"messages": [{"role": "user", "content": "Write a Python hello world"}],
|
||||
"metadata": {"model": "auto", "combo": "fast-coding"}
|
||||
}
|
||||
}'
|
||||
|
||||
**Response:**
|
||||
````
|
||||
|
||||
```json
|
||||
**Respuesta:**```json
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": "1",
|
||||
|
|
@ -133,36 +125,33 @@ curl -X POST http://localhost:20128/a2a \
|
|||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
````
|
||||
|
||||
### `message/stream` — SSE Streaming
|
||||
|
||||
Same as `message/send` but returns Server-Sent Events for real-time streaming.
|
||||
|
||||
```bash
|
||||
Igual que "mensaje/enviar", pero devuelve eventos enviados por el servidor para transmisión en tiempo real.```bash
|
||||
curl -N -X POST http://localhost:20128/a2a \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_KEY" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"id": "1",
|
||||
"method": "message/stream",
|
||||
"params": {
|
||||
"skill": "smart-routing",
|
||||
"messages": [{"role": "user", "content": "Explain quantum computing"}]
|
||||
}
|
||||
}'
|
||||
```
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_KEY" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"id": "1",
|
||||
"method": "message/stream",
|
||||
"params": {
|
||||
"skill": "smart-routing",
|
||||
"messages": [{"role": "user", "content": "Explain quantum computing"}]
|
||||
}
|
||||
}'
|
||||
|
||||
**SSE Events:**
|
||||
````
|
||||
|
||||
```
|
||||
**Eventos de ESS:**```
|
||||
data: {"jsonrpc":"2.0","method":"message/stream","params":{"task":{"id":"...","state":"working"},"chunk":{"type":"text","content":"Quantum computing..."}}}
|
||||
|
||||
: heartbeat 2026-03-04T21:00:00Z
|
||||
|
||||
data: {"jsonrpc":"2.0","method":"message/stream","params":{"task":{"id":"...","state":"completed"},"metadata":{...}}}
|
||||
```
|
||||
````
|
||||
|
||||
### `tasks/get` — Query Task Status
|
||||
|
||||
|
|
@ -188,40 +177,36 @@ curl -X POST http://localhost:20128/a2a \
|
|||
|
||||
### `smart-routing`
|
||||
|
||||
Routes prompts through OmniRoute's intelligent pipeline with full observability.
|
||||
Enruta indicaciones a través del canal inteligente de OmniRoute con total observabilidad.
|
||||
|
||||
**Parameters (in `metadata`):**
|
||||
**Parámetros (en `metadatos`):**
|
||||
|
||||
| Parameter | Type | Default | Description |
|
||||
| --------- | -------- | ------------ | ---------------------------------------------------------------------------------------- |
|
||||
| `model` | `string` | `"auto"` | Target model (e.g., `claude-sonnet-4`, `gpt-4o`, `auto`) |
|
||||
| `combo` | `string` | active combo | Specific combo to route through |
|
||||
| `budget` | `number` | none | Maximum cost in USD for this request |
|
||||
| `role` | `string` | none | Task role hint: `coding`, `review`, `planning`, `analysis`, `debugging`, `documentation` |
|
||||
| Parámetro | Tipo | Predeterminado | Descripción |
|
||||
| ------------- | -------- | ------------------ | ------------------------------------------------------------------------------------------------------------------ |
|
||||
| `modelo` | `cadena` | `"automático"` | Modelo de destino (por ejemplo, `claude-sonnet-4`, `gpt-4o`, `auto`) |
|
||||
| `combinado` | `cadena` | combinación activa | Combo específico para enrutar |
|
||||
| `presupuesto` | `número` | ninguno | Costo máximo en USD para esta solicitud |
|
||||
| `rol` | `cadena` | ninguno | Sugerencia de rol de tarea: `codificación`, `revisión`, `planificación`, `análisis`, `depuración`, `documentación` |
|
||||
|
||||
**Returns:**
|
||||
**Devoluciones:**
|
||||
|
||||
| Field | Description |
|
||||
| ------------------------------ | --------------------------------------------------------- |
|
||||
| `artifacts[].content` | The LLM response text |
|
||||
| `metadata.routing_explanation` | Human-readable explanation of routing decision |
|
||||
| `metadata.cost_envelope` | Estimated vs actual cost with currency |
|
||||
| `metadata.resilience_trace` | Array of events (primary_selected, fallback_needed, etc.) |
|
||||
| `metadata.policy_verdict` | Whether the request was allowed and why |
|
||||
| Campo | Descripción |
|
||||
| --------------------------------------- | -------------------------------------------------------------- | ---------------------- |
|
||||
| `artefactos[].content` | El texto de respuesta del LLM |
|
||||
| `metadatos.explicación_de_enrutamiento` | Explicación legible por humanos de la decisión de enrutamiento |
|
||||
| `metadatos.cost_envelope` | Costo estimado versus costo real con moneda |
|
||||
| `metadatos.resilience_trace` | Matriz de eventos (primary_selected, fallback_needed, etc.) |
|
||||
| `metadatos.policy_verdict` | Si se permitió la solicitud y por qué | ### `quota-management` |
|
||||
|
||||
### `quota-management`
|
||||
Responde consultas en lenguaje natural sobre cuotas de proveedores.
|
||||
|
||||
Answers natural-language queries about provider quotas.
|
||||
**Tipos de consulta (inferidos del contenido del mensaje):**
|
||||
|
||||
**Query types (inferred from message content):**
|
||||
|
||||
| Query Pattern | Response Type |
|
||||
| ---------------------------------------------- | -------------------------------------------------------- |
|
||||
| Contains `"ranking"`, `"most quota"`, `"best"` | Providers ranked by remaining quota |
|
||||
| Contains `"free"`, `"suggest"` | Lists free combos or suggests free-tier providers |
|
||||
| Default | Full quota summary with warnings for low-quota providers |
|
||||
|
||||
---
|
||||
| Patrón de consulta | Tipo de respuesta |
|
||||
| ------------------------------------------------ | ---------------------------------------------------------------------------- | --- |
|
||||
| Contiene `"ranking"`, `"mayor cuota"`, `"mejor"` | Proveedores clasificados por cuota restante |
|
||||
| Contiene `"gratis"`, `"sugerir"` | Enumera combinaciones gratuitas o sugiere proveedores de nivel gratuito |
|
||||
| Predeterminado | Resumen completo de cuotas con advertencias para proveedores de cuotas bajas | --- |
|
||||
|
||||
## Task Lifecycle
|
||||
|
||||
|
|
@ -231,19 +216,17 @@ submitted ──→ working ──→ completed
|
|||
──────────→ cancelled
|
||||
```
|
||||
|
||||
| State | Description |
|
||||
| ----------- | ----------------------------------------------------- |
|
||||
| `submitted` | Task created, queued for execution |
|
||||
| `working` | Skill handler is executing |
|
||||
| `completed` | Execution succeeded, artifacts available |
|
||||
| `failed` | Execution failed or task expired (TTL: 5 min default) |
|
||||
| `cancelled` | Cancelled by client via `tasks/cancel` |
|
||||
| Estado | Descripción |
|
||||
| ------------ | ----------------------------------------------------------------------------- |
|
||||
| `enviado` | Tarea creada, en cola para ejecución |
|
||||
| `trabajando` | El manejador de habilidades se está ejecutando |
|
||||
| `completado` | Ejecución exitosa, artefactos disponibles |
|
||||
| `fallido` | La ejecución falló o la tarea expiró (TTL: valor predeterminado de 5 minutos) |
|
||||
| `cancelado` | Cancelado por el cliente a través de `tareas/cancelar` |
|
||||
|
||||
- Terminal states: `completed`, `failed`, `cancelled` (no further transitions)
|
||||
- Expired tasks in `submitted` or `working` are auto-marked as `failed`
|
||||
- Tasks are garbage-collected after 2× TTL
|
||||
|
||||
---
|
||||
- Estados del terminal: "completado", "fallido", "cancelado" (sin más transiciones)
|
||||
- Las tareas caducadas en "enviadas" o "en funcionamiento" se marcan automáticamente como "fallidas"
|
||||
- Las tareas se recolectan como basura después de 2× TTL---
|
||||
|
||||
## Client Examples
|
||||
|
||||
|
|
@ -541,15 +524,12 @@ func main() {
|
|||
|
||||
### 🤖 Use Case 1: Multi-Agent Coding Pipeline
|
||||
|
||||
An orchestrator agent delegates code generation to OmniRoute, then passes the output to a review agent.
|
||||
|
||||
```python
|
||||
def coding_pipeline(task: str):
|
||||
# Step 1: Generate code via OmniRoute A2A
|
||||
code_result = a2a_send("smart-routing", [
|
||||
{"role": "user", "content": f"Write production-quality code: {task}"}
|
||||
], metadata={"model": "auto", "role": "coding"})
|
||||
code = code_result["artifacts"][0]["content"]
|
||||
Un agente orquestador delega la generación de código a OmniRoute y luego pasa el resultado a un agente de revisión.```python
|
||||
def coding_pipeline(task: str): # Step 1: Generate code via OmniRoute A2A
|
||||
code_result = a2a_send("smart-routing", [
|
||||
{"role": "user", "content": f"Write production-quality code: {task}"}
|
||||
], metadata={"model": "auto", "role": "coding"})
|
||||
code = code_result["artifacts"][0]["content"]
|
||||
|
||||
# Step 2: Review the code via OmniRoute A2A (different model)
|
||||
review_result = a2a_send("smart-routing", [
|
||||
|
|
@ -562,13 +542,12 @@ def coding_pipeline(task: str):
|
|||
print(f"Review cost: ${review_result['metadata']['cost_envelope']['actual']}")
|
||||
|
||||
return {"code": code, "review": review}
|
||||
```
|
||||
|
||||
````
|
||||
|
||||
### 💡 Use Case 2: Quota-Aware Agent Swarm
|
||||
|
||||
Multiple agents share quota through OmniRoute, using the quota skill to coordinate.
|
||||
|
||||
```python
|
||||
Varios agentes comparten cuota a través de OmniRoute y utilizan la habilidad de cuota para coordinarse.```python
|
||||
async def quota_aware_agent(agent_name: str, task: str):
|
||||
# Check quota before starting
|
||||
quota = a2a_send("quota-management", [
|
||||
|
|
@ -591,32 +570,30 @@ async def quota_aware_agent(agent_name: str, task: str):
|
|||
print(f"[{agent_name}] Free alternatives: {quota['artifacts'][0]['content']}")
|
||||
|
||||
return result
|
||||
```
|
||||
````
|
||||
|
||||
### 📊 Use Case 3: Real-Time Streaming Dashboard
|
||||
|
||||
A monitoring agent streams responses and displays progress in real-time.
|
||||
|
||||
```typescript
|
||||
Un agente de monitoreo transmite respuestas y muestra el progreso en tiempo real.```typescript
|
||||
async function streamingDashboard(prompt: string) {
|
||||
const response = await fetch(`${BASE_URL}/a2a`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", Authorization: `Bearer ${API_KEY}` },
|
||||
body: JSON.stringify({
|
||||
jsonrpc: "2.0",
|
||||
id: "dash-1",
|
||||
method: "message/stream",
|
||||
params: { skill: "smart-routing", messages: [{ role: "user", content: prompt }] },
|
||||
}),
|
||||
});
|
||||
body: JSON.stringify({
|
||||
jsonrpc: "2.0",
|
||||
id: "dash-1",
|
||||
method: "message/stream",
|
||||
params: { skill: "smart-routing", messages: [{ role: "user", content: prompt }] },
|
||||
}),
|
||||
});
|
||||
|
||||
let totalChunks = 0;
|
||||
const reader = response.body!.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
let totalChunks = 0;
|
||||
const reader = response.body!.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
|
||||
for (const line of decoder.decode(value).split("\n")) {
|
||||
if (line.startsWith("data: ")) {
|
||||
|
|
@ -640,15 +617,15 @@ async function streamingDashboard(prompt: string) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
}
|
||||
|
||||
````
|
||||
|
||||
### 🔁 Use Case 4: Task Polling Pattern
|
||||
|
||||
For long-running tasks, poll the task status instead of waiting synchronously.
|
||||
|
||||
```python
|
||||
Para tareas de larga duración, sondee el estado de la tarea en lugar de esperar sincrónicamente.```python
|
||||
import time
|
||||
|
||||
def poll_task(task_id: str, timeout: int = 60):
|
||||
|
|
@ -678,75 +655,71 @@ def poll_task(task_id: str, timeout: int = 60):
|
|||
"params": {"taskId": task_id},
|
||||
})
|
||||
raise TimeoutError(f"Task {task_id} timed out after {timeout}s")
|
||||
```
|
||||
````
|
||||
|
||||
---
|
||||
|
||||
## Error Codes
|
||||
|
||||
| Code | Constant | Meaning |
|
||||
| ------ | ------------------------ | ---------------------------------------- |
|
||||
| -32700 | — | Parse error (invalid JSON) |
|
||||
| -32600 | `INVALID_REQUEST` | Invalid JSON-RPC request or unauthorized |
|
||||
| -32601 | `METHOD_NOT_FOUND` | Unknown method or skill |
|
||||
| -32602 | `INVALID_PARAMS` | Missing or invalid parameters |
|
||||
| -32603 | `INTERNAL_ERROR` | Skill execution failed |
|
||||
| -32001 | `TASK_NOT_FOUND` | Task ID not found |
|
||||
| -32002 | `TASK_ALREADY_COMPLETED` | Cannot modify a completed task |
|
||||
| -32003 | `UNAUTHORIZED` | Invalid or missing API key |
|
||||
| -32004 | `BUDGET_EXCEEDED` | Request exceeds configured budget |
|
||||
| -32005 | `PROVIDER_UNAVAILABLE` | No available providers |
|
||||
|
||||
---
|
||||
| Código | Constante | Significado |
|
||||
| ------ | ------------------------ | ---------------------------------------------- | --- |
|
||||
| -32700 | — | Error de análisis (JSON no válido) |
|
||||
| -32600 | `INVALID_REQUEST` | Solicitud JSON-RPC no válida o no autorizada |
|
||||
| -32601 | `METHOD_NOT_FOUND` | Método o habilidad desconocida |
|
||||
| -32602 | `INVALID_PARAMS` | Parámetros faltantes o no válidos |
|
||||
| -32603 | `ERROR_INTERNO` | La ejecución de la habilidad falló |
|
||||
| -32001 | `TASK_NOT_FOUND` | ID de tarea no encontrada |
|
||||
| -32002 | `TASK_ALREADY_COMPLETED` | No se puede modificar una tarea completada |
|
||||
| -32003 | `NO AUTORIZADO` | Clave API no válida o faltante |
|
||||
| -32004 | `PRESUPUESTO_EXCEEDED` | La solicitud supera el presupuesto configurado |
|
||||
| -32005 | `PROVIDER_UNAVAILABLE` | No hay proveedores disponibles | --- |
|
||||
|
||||
## Authentication
|
||||
|
||||
All `/a2a` requests require a Bearer token via the `Authorization` header:
|
||||
|
||||
```
|
||||
Todas las solicitudes `/a2a` requieren un token de portador a través del encabezado `Authorization`:```
|
||||
Authorization: Bearer YOUR_OMNIROUTE_API_KEY
|
||||
|
||||
```
|
||||
|
||||
If no API key is configured on the server (`OMNIROUTE_API_KEY` is empty), authentication is bypassed.
|
||||
|
||||
---
|
||||
Si no se configura ninguna clave API en el servidor (`OMNIROUTE_API_KEY` está vacía), se omite la autenticación.---
|
||||
|
||||
## File Structure
|
||||
|
||||
```
|
||||
|
||||
src/lib/a2a/
|
||||
├── taskManager.ts # Task lifecycle (create/update/cancel/list), TTL, cleanup
|
||||
├── taskExecution.ts # Generic task executor with state management
|
||||
├── streaming.ts # SSE stream formatting, heartbeat, chunk/completion events
|
||||
├── routingLogger.ts # Routing decision logger (stats, history, retention)
|
||||
├── taskManager.ts # Task lifecycle (create/update/cancel/list), TTL, cleanup
|
||||
├── taskExecution.ts # Generic task executor with state management
|
||||
├── streaming.ts # SSE stream formatting, heartbeat, chunk/completion events
|
||||
├── routingLogger.ts # Routing decision logger (stats, history, retention)
|
||||
└── skills/
|
||||
├── smartRouting.ts # Smart routing skill (routes via /v1/chat/completions)
|
||||
└── quotaManagement.ts # Quota management skill (natural-language quota queries)
|
||||
├── smartRouting.ts # Smart routing skill (routes via /v1/chat/completions)
|
||||
└── quotaManagement.ts # Quota management skill (natural-language quota queries)
|
||||
|
||||
src/app/a2a/
|
||||
└── route.ts # Next.js API route handler (JSON-RPC 2.0 dispatch)
|
||||
└── route.ts # Next.js API route handler (JSON-RPC 2.0 dispatch)
|
||||
|
||||
open-sse/mcp-server/
|
||||
└── schemas/a2a.ts # Zod schemas (AgentCard, Task, JSON-RPC, SSE events)
|
||||
└── schemas/a2a.ts # Zod schemas (AgentCard, Task, JSON-RPC, SSE events)
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Comparison: MCP vs A2A
|
||||
|
||||
| Feature | MCP Server | A2A Server |
|
||||
| Característica | Servidor MCP | Servidor A2A |
|
||||
| ----------------- | ---------------------------- | ------------------------------------------------- |
|
||||
| **Protocol** | Model Context Protocol | Agent-to-Agent Protocol v0.3 |
|
||||
| **Transport** | stdio / HTTP | HTTP (JSON-RPC 2.0) |
|
||||
| **Discovery** | Tool listing via MCP | `/.well-known/agent.json` |
|
||||
| **Granularity** | 16 individual tools | 2 high-level skills |
|
||||
| **Best for** | IDE agents (Cursor, VS Code) | Multi-agent systems (LangChain, CrewAI) |
|
||||
| **Streaming** | Not supported | SSE via `message/stream` |
|
||||
| **Task tracking** | No | Full lifecycle (submitted → completed) |
|
||||
| **Observability** | Audit log per tool call | Cost envelope + resilience trace + policy verdict |
|
||||
|
||||
---
|
||||
|**Protocolo**| Protocolo de contexto modelo | Protocolo de agente a agente v0.3 |
|
||||
|**Transporte**| estándar / HTTP | HTTP (JSON-RPC 2.0) |
|
||||
|**Descubrimiento**| Listado de herramientas a través de MCP | `/.well-known/agent.json` |
|
||||
|**Granularidad**| 16 herramientas individuales | 2 habilidades de alto nivel |
|
||||
|**Mejor para**| Agentes IDE (Cursor, Código VS) | Sistemas multiagente (LangChain, CrewAI) |
|
||||
|**Transmisión**| No compatible | SSE a través de `mensaje/transmisión` |
|
||||
|**Seguimiento de tareas**| No | Ciclo de vida completo (enviado → completado) |
|
||||
|**Observabilidad**| Registro de auditoría por llamada a herramienta | Sobre de costos + seguimiento de resiliencia + veredicto de política |---
|
||||
|
||||
## Licencia
|
||||
|
||||
Part of [OmniRoute](https://github.com/diegosouzapw/OmniRoute) — MIT License.
|
||||
Parte de [OmniRoute](https://github.com/diegosouzapw/OmniRoute) — Licencia MIT.
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue