# generate_thread_name

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/thread_titles/generate_thread_name)

Generate a safe name using the selected model without conversation callbacks.

Cancellation waits for model initialization, which can update process-wide
provider settings, even if the generation timeout has expired.

## Signature

```python
generate_thread_name(
    model_spec: str,
    messages: Sequence[BaseMessage],
    *,
    thread_id: str | None = None,
    model_params: dict[str, object] | None = None,
    initialization_lock: asyncio.Lock | None = None,
) -> str
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `model_spec` | `str` | Yes | Configured provider/model specification. |
| `messages` | `Sequence[BaseMessage]` | Yes | Conversation to name; only user and assistant text is sent. |
| `thread_id` | `str \| None` | No | Thread that owns the request's usage for cost accounting. (default: `None`) |
| `model_params` | `dict[str, object] \| None` | No | Active conversation model overrides when inheriting its model, including connection settings such as `base_url`. (default: `None`) |
| `initialization_lock` | `asyncio.Lock \| None` | No | Excludes environment mutations while the model factory runs, including cancellation cleanup. Released before the model request. (default: `None`) |

## Returns

`str`

A single-line name of at most 50 characters.

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/6a8d452d70f9bcb978e6bd44831dda093ecbe928/libs/code/deepagents_code/thread_titles.py#L98)