delete_room
Permanently delete a communication room and all its messages. Optionally force deletion even if the room is not closed.
Instructions
Permanently delete a communication room and all its messages
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| roomName | Yes | Name of the communication room to permanently delete. This will remove all messages and data associated with the room. | |
| forceDelete | No | Whether to force delete the room even if it's not closed. Defaults to false. If false, the room must be closed before deletion. If true, will delete the room regardless of status. |
Implementation Reference
- src/tools/CommunicationTools.ts:389-464 (handler)The main handler for the 'delete_room' tool. It normalizes arguments (supporting both snake_case and camelCase), validates via DeleteRoomSchema, checks if the room exists and is closed (or forceDelete is true), terminates associated agents, then calls communicationService.deleteRoom() to permanently remove the room and all its messages. Returns a DeleteRoomResponse with success/error details.
/** * Permanently delete a communication room and all its messages */ async deleteRoom(args: any): Promise<DeleteRoomResponse> { // Map snake_case to camelCase for compatibility const normalizedArgs = { roomName: args.roomName || args.room_name, forceDelete: args.forceDelete || args.force_delete }; const { roomName, forceDelete = false } = DeleteRoomSchema.parse(normalizedArgs); const startTime = performance.now(); try { const room = await this.communicationService.getRoom(roomName); if (!room) { const executionTime = performance.now() - startTime; return createErrorResponse( `Room '${roomName}' not found`, `Room '${roomName}' not found`, 'ROOM_NOT_FOUND' ) as DeleteRoomResponse; } // Check if room is closed or force delete const isClosed = room.roomMetadata?.status === 'closed'; if (!isClosed && !forceDelete) { const executionTime = performance.now() - startTime; return createErrorResponse( `Room '${roomName}' must be closed before deletion. Use force_delete=true to override.`, `Room '${roomName}' must be closed before deletion`, 'ROOM_NOT_CLOSED' ) as DeleteRoomResponse; } // Terminate any remaining agents const agents = await this.agentService.listAgents(room.repositoryPath); const roomAgents = agents.filter(agent => agent.agentMetadata?.roomId === room.id || agent.agentMetadata?.roomName === roomName ); if (roomAgents.length > 0) { for (const agent of roomAgents) { try { await this.agentService.terminateAgent(agent.id); } catch (error: any) { console.warn(`Failed to terminate agent ${agent.id}:`, error); } } } // Delete the room await this.communicationService.deleteRoom(roomName); const executionTime = performance.now() - startTime; return createSuccessResponse( `Room '${roomName}' permanently deleted`, { room_name: roomName, messages_deleted: true, agents_terminated: roomAgents.length }, executionTime ) as DeleteRoomResponse; } catch (error: any) { const executionTime = performance.now() - startTime; return createErrorResponse( 'Failed to delete room', error instanceof Error ? error.message : 'Unknown error occurred', 'DELETE_ROOM_ERROR' ) as DeleteRoomResponse; } } - The DeleteRoomSchema Zod definition specifying the input parameters: roomName (string) and forceDelete (boolean, defaults to false).
export const DeleteRoomSchema = z.object({ roomName: z.string().describe('Name of the communication room to permanently delete. This will remove all messages and data associated with the room.'), forceDelete: z.boolean().default(false).describe('Whether to force delete the room even if it\'s not closed. Defaults to false. If false, the room must be closed before deletion. If true, will delete the room regardless of status.') }); - The DeleteRoomResponseSchema Zod definition specifying the output structure: success, message, timestamp, execution_time_ms, and data containing room_name, messages_deleted, and agents_terminated.
// Delete Room Response export const DeleteRoomResponseSchema = z.object({ success: z.boolean().describe('Whether the room was successfully deleted permanently. True if room and all associated data were removed.'), message: z.string().describe('Human-readable description of the deletion result, including room name and data removal confirmation.'), timestamp: z.string().describe('ISO timestamp string indicating when the room was permanently deleted.'), execution_time_ms: z.number().optional().describe('Time taken to delete the room in milliseconds, including message deletion and agent cleanup.'), data: z.object({ room_name: z.string().describe('Name of the room that was permanently deleted.'), messages_deleted: z.boolean().describe('Whether all messages in the room were successfully deleted from the database.'), agents_terminated: z.number().describe('Number of agents that were terminated as part of the room deletion process.') }).optional().describe('Room deletion details returned when successful, containing room name and confirmation of data removal.') }); - src/tools/CommunicationTools.ts:115-121 (registration)Registration of the 'delete_room' tool within the getTools() method of CommunicationTools class, defining its name, description, input/output schemas, and binding the handler.
{ name: 'delete_room', description: 'Permanently delete a communication room and all its messages', inputSchema: zodToJsonSchema(DeleteRoomSchema), outputSchema: zodToJsonSchema(DeleteRoomResponseSchema), handler: this.deleteRoom.bind(this) }, - The CommunicationService.deleteRoom method which looks up the room by name, delegates to commRepo.deleteRoom() for the actual database deletion, then emits a 'room_closed' event on the eventBus.
async deleteRoom(roomName: string): Promise<void> { const room = await this.commRepo.getRoomByName(roomName); if (!room) { throw new Error(`Room ${roomName} not found`); } await this.commRepo.deleteRoom(roomName); // Emit room closed event await eventBus.emit('room_closed', { roomId: room.name, // Using name as ID since it's the primary key roomName: room.name, timestamp: new Date(), repositoryPath: room.repositoryPath }); } - The CommunicationRepository.deleteRoom method that performs the actual database operations: deletes chat messages, room participants, and the chat room itself in that order using Drizzle ORM.
/** * Delete a room and all its messages by ID */ async deleteRoom(id: string): Promise<boolean> { try { // Delete in proper order: messages -> participants -> room await this.drizzle .delete(chatMessages) .where(eq(chatMessages.roomId, id)) .execute(); // Delete participants await this.drizzle .delete(roomParticipants) .where(eq(roomParticipants.roomId, id)) .execute(); // Delete room const result = await this.drizzle .delete(chatRooms) .where(eq(chatRooms.id, id)) .execute(); return result.changes > 0; } catch (error) { throw new RepositoryError( `Failed to delete room: ${id}`, 'deleteRoom', this.getTableName(), error ); } }