|
| 1 | +# InteractiveAI usecase Agent API |
| 2 | + |
| 3 | +A minimal Flask service that each usecase can drop into their AI agent application. It receives a recommendation request from **InteractiveAI** and returns computed **actions** synchronously. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Features |
| 8 | +- **Single endpoint:** `POST /v1/get_recommendations` |
| 9 | +- **Synchronous:** compute and return actions in the same response |
| 10 | +- **Strict inputs:** `use_case`, `context`, `event` are **required** |
| 11 | +- **Health check:** `GET /v1/healthz` |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## Requirements |
| 16 | +- Python 3.10+ |
| 17 | +- `pip install flask` |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## Run (development) |
| 22 | +```bash |
| 23 | +python app.py |
| 24 | +# Service listens on http://0.0.0.0:8000 |
| 25 | +``` |
| 26 | +> For production, use a proper WSGI server (e.g., gunicorn/uvicorn) and disable `debug`. |
| 27 | +
|
| 28 | +--- |
| 29 | + |
| 30 | +## API |
| 31 | + |
| 32 | +### POST `/v1/get_recommendations` |
| 33 | +**Purpose:** InteractiveAI sends a recommendation request. Your agent computes **actions** and returns them in the response. |
| 34 | + |
| 35 | +**Headers** |
| 36 | +- `Content-Type: application/json` |
| 37 | + |
| 38 | +**Request Body (JSON)** |
| 39 | +- **Required** |
| 40 | + - `use_case` *(string)* — e.g., `Railway`, `Powergrid`, `ATM`. |
| 41 | + - `context` *(object)* — Snapshot/state data from simulator. |
| 42 | + - `event` *(object)* — Trigger info (alarms, alerts, malfunctions, etc.). |
| 43 | +- **Optional** |
| 44 | + - `agent_type` *(string, default: `generic`)* |
| 45 | + - `sim_api` *(object)* — Hints/endpoints if your agent needs to fetch extra simulator data (left to usecase logic). |
| 46 | + |
| 47 | +**Response (200 OK, JSON)** |
| 48 | +- `title` *(string)* |
| 49 | +- `description` *(string)* |
| 50 | +- `use_case` *(string)* |
| 51 | +- `agent_type` *(string)* |
| 52 | +- `actions` *(array of objects)* — **computed by your agent logic** |
| 53 | + |
| 54 | +**Error Responses** |
| 55 | +- `400 Bad Request` → `{"error":"bad_request","message":"...","details":{"missing":[...]}}` |
| 56 | +- `5xx` → Unexpected server errors |
| 57 | + |
| 58 | +--- |
| 59 | + |
| 60 | +### GET `/v1/healthz` |
| 61 | +- Returns `200 OK` with body `ok`. |
| 62 | + |
| 63 | +--- |
| 64 | + |
| 65 | +## Implementation Notes |
| 66 | +- Put your decision logic where the `actions` list is produced in `get_recommendations`. |
| 67 | +- If `sim_api` is present and your use case requires extra simulator data, fetch it before deciding actions (usecase-specific). |
| 68 | +- Security is intentionally omitted for this initial version; it will be added later. |
| 69 | +--- |
| 70 | + |
| 71 | +## File Overview |
| 72 | +- `app.py` |
| 73 | + - `POST /v1/get_recommendations` — main endpoint |
| 74 | + - `GET /v1/healthz` — readiness probe |
| 75 | + - Minimal `400` helper for validation errors |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +## What Partners Must Implement |
| 80 | +- The **decision logic** producing the `actions` array. |
| 81 | +- (Optional) **Simulator fetches** based on `sim_api`. |
| 82 | +- (Later) **Auth, retries, persistence, logging**, and an async callback flow if needed. |
0 commit comments