> ## Documentation Index
> Fetch the complete documentation index at: https://docs.braviloai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent - Query with Routing

Envía un mensaje a un agente con **routing automático**. Si hay triggers configurados, Bravilo detecta el agente correcto según el contexto y redirige la conversación.

### Streaming

Cuando `streaming` está habilitado, el endpoint devuelve un stream `text/event-stream` con eventos SSE:

```js theme={null}
import { fetchEventSource } from '@microsoft/fetch-event-source';

const ctrl = new AbortController();

await fetchEventSource(`https://app.braviloai.com/api/agents/${agentId}/query-with-routing`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
signal: ctrl.signal,
body: JSON.stringify({
query: 'Hola, quiero saber el estado de mi pedido #1234',
streaming: true,
conversationId,
}),
onmessage: (event) => {
if (event.event === 'routing') {
console.log('Routing:', JSON.parse(event.data));
} else if (event.event === 'answer') {
console.log('Chunk:', event.data);
} else if (event.data === '[DONE]') {
ctrl.abort();
},
});
```


## OpenAPI

````yaml POST /agents/{id}/query-with-routing
openapi: 3.0.1
info:
  title: Bravilo AI.ai - API OpenAPI specifications
  description: ''
  termsOfService: http://braviloai.com/terms
  contact:
    email: support@braviloai.com
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  version: 1.0.0
servers:
  - url: https://app.braviloai.com/api
security:
  - bearerAuth: []
tags:
  - name: agents
  - name: datastores
  - name: datasources
paths:
  /agents/{id}/query-with-routing:
    post:
      tags:
        - agents
      summary: Chat con routing automático de agente
      parameters:
        - in: path
          name: id
          schema:
            type: string
          required: true
          description: ID del agente
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                query:
                  type: string
                  description: Mensaje del usuario
                conversationId:
                  type: string
                streaming:
                  type: boolean
                  default: true
                channel:
                  type: string
                  default: dashboard
                machineId:
                  type: string
                fromUrl:
                  type: string
              required:
                - query
      responses:
        '200':
          description: Respuesta del agente o stream SSE
        '403':
          description: Access denied
        '404':
          description: Agent not found
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````