create_new_assistant_thread
Create persistent conversation threads with custom names and descriptions for organized, reusable interactions with OpenAI assistants.
Instructions
Creates a new, persistent conversation thread with a user-defined name and description for easy identification and reuse. These threads are stored in OpenAI's servers and are not deleted unless the user deletes them, which means you can re-use them for future conversations. Additionally, the thread name and description are stored in the local database, which means you can list them and update them later.
Think how you can utilize threads in your particular use case.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| description | No |
Implementation Reference
- mcp_simple_openai_assistant/app.py:41-62 (handler)MCP tool 'create_new_assistant_thread' handler function, registered via @app.tool decorator. It checks for initialized manager, calls the core AssistantManager method, and returns a success message with thread ID or raises ToolError on failure.@app.tool( annotations={"title": "Create New Assistant Thread", "readOnlyHint": False} ) async def create_new_assistant_thread( name: str, description: Optional[str] = None ) -> str: """ Creates a new, persistent conversation thread with a user-defined name and description for easy identification and reuse. These threads are stored in OpenAI's servers and are not deleted unless the user deletes them, which means you can re-use them for future conversations. Additionally, the thread name and description are stored in the local database, which means you can list them and update them later. Think how you can utilize threads in your particular use case. """ if not manager: raise ToolError("AssistantManager not initialized.") try: thread = await manager.create_new_assistant_thread(name, description) return f"Created new thread '{name}' with ID: {thread.id}" except Exception as e: raise ToolError(f"Failed to create thread: {e}")
- Core helper method in AssistantManager class that creates a new OpenAI thread with user-provided metadata and persists the thread details (ID, name, description) to the local ThreadStore database.async def create_new_assistant_thread( self, name: str, description: Optional[str] = None ) -> Thread: """Creates a new, persistent conversation thread.""" metadata = { "name": name, "description": description or "" } thread = self.client.beta.threads.create(metadata=metadata) self.thread_store.add_thread(thread.id, name, description) return thread
- Supporting utility in ThreadStore class that inserts the new thread record into the local SQLite database, including current timestamp for last_used_at.def add_thread(self, thread_id: str, name: str, description: str | None) -> int: """Adds a new thread record to the database. Args: thread_id: The unique identifier for the thread from OpenAI. name: A user-defined name for the thread. description: A user-defined description for the thread. Returns: The row ID of the newly inserted thread. """ conn = self._get_connection() cursor = conn.cursor() cursor.execute(""" INSERT INTO threads (thread_id, name, description, last_used_at) VALUES (?, ?, ?, ?) """, (thread_id, name, description, datetime.now(timezone.utc))) conn.commit() return cursor.lastrowid