From e9c91128952456741509d701f934d24b24d5efc0 Mon Sep 17 00:00:00 2001 From: Khushal Jethava Date: Fri, 24 Jan 2025 15:43:40 +0530 Subject: [PATCH] feat(Added Delete endpoint and API doc): --- API.md | 152 +++++++++++++++++++++++++++++++ local_setup/quickstart_server.py | 16 ++++ 2 files changed, 168 insertions(+) create mode 100644 API.md diff --git a/API.md b/API.md new file mode 100644 index 0000000..1d81b69 --- /dev/null +++ b/API.md @@ -0,0 +1,152 @@ +# Bolna API Documentation + +## Endpoints + +### Get Agent +Retrieves an agent's information by agent id. + +**Endpoint:** `GET /agent/{agent_id}` + +**Parameters:** +- `agent_id` (path) - string, required: Unique identifier of the agent + +### Create Agent +Creates a new agent with specified configuration. + +**Endpoint:** `POST /agent` + +**Request Body:** +```json +{ +{ + "agent_config": { + "agent_name": "Alfred", + "agent_type": "other", + "agent_welcome_message": "How are you doing Bruce?", + "tasks": [ + { + "task_type": "conversation", + "toolchain": { + "execution": "parallel", + "pipelines": [ + [ + "transcriber", + "llm", + "synthesizer" + ] + ] + }, + "tools_config": { + "input": { + "format": "wav", + "provider": "twilio" + }, + "llm_agent": { + "agent_type": "simple_llm_agent", + "agent_flow_type": "streaming", + "routes": null, + "llm_config": { + "agent_flow_type": "streaming", + "provider": "openai", + "request_json": true, + "model": "gpt-4o-mini" + } + }, + "output": { + "format": "wav", + "provider": "twilio" + }, + "synthesizer": { + "audio_format": "wav", + "provider": "elevenlabs", + "stream": true, + "provider_config": { + "voice": "George", + "model": "eleven_turbo_v2_5", + "voice_id": "JBFqnCBsd6RMkjVDRZzb" + }, + "buffer_size": 100.0 + }, + "transcriber": { + "encoding": "linear16", + "language": "en", + "provider": "deepgram", + "stream": true + } + }, + "task_config": { + "hangup_after_silence": 30.0 + } + } + ] + }, + "agent_prompts": { + "task_1": { + "system_prompt": "Why Do We Fall, Sir? So That We Can Learn To Pick Ourselves Up." + } + } +} + + + +} +``` + +**Response:** +```json +200 OK +{ + "agent_id": "uuid-string", + "state": "created" +} +``` + +### Edit Agent +Updates an existing agent's configuration. + +**Endpoint:** `PUT /agent/{agent_id}` + +**Parameters:** +- `agent_id` (path) - string, required: Unique identifier of the agent + +**Request Body:** +Same as Create Agent endpoint + + +### Delete Agent +Deletes an agent from the system. + +**Endpoint:** `DELETE /agent/{agent_id}` + +**Parameters:** +- `agent_id` (path) - string, required: Unique identifier of the agent + +**Response:** +```json +200 OK +{ + "agent_id": "string", + "state": "deleted" +} +``` + + +### Get All Agents +Retrieves all agents from the system. + +**Endpoint:** `GET /all` + +**Response:** +```json +200 OK +{ + "agents": [ + { + "agent_id": "string", + "data": { + // Agent configuration object + } + } + ] +} +``` \ No newline at end of file diff --git a/local_setup/quickstart_server.py b/local_setup/quickstart_server.py index 0a18f1d..fa4de69 100644 --- a/local_setup/quickstart_server.py +++ b/local_setup/quickstart_server.py @@ -132,6 +132,22 @@ async def edit_agent(agent_id: str, agent_data: CreateAgentPayload = Body(...)): logger.error(f"Error updating agent {agent_id}: {e}", exc_info=True) raise HTTPException(status_code=500, detail="Internal server error") +@app.delete("/agent/{agent_id}") +async def delete_agent(agent_id: str): + """Deletes an agent by ID.""" + try: + agent_exists = await redis_client.exists(agent_id) + if not agent_exists: + raise HTTPException(status_code=404, detail="Agent not found") + + await redis_client.delete(agent_id) + return {"agent_id": agent_id, "state": "deleted"} + + except Exception as e: + logger.error(f"Error deleting agent {agent_id}: {e}", exc_info=True) + raise HTTPException(status_code=500, detail="Internal server error") + + @app.get("/all") async def get_all_agents(): """Fetches all agents stored in Redis."""