# get_most_recent

> **Function** in `deepagents_code`

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

Get the most recent thread, optionally agent-filtered and/or excluding a thread.

## Signature

```python
get_most_recent(
    agent_name: str | None = None,
    *,
    exclude_thread_id: str | None = None,
) -> str | None
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `agent_name` | `str \| None` | No | Return only threads created by this agent. (default: `None`) |
| `exclude_thread_id` | `str \| None` | No | Ignore this thread when selecting the most recent one. (default: `None`) |

## Returns

`str | None`

Most recent thread ID, or `None` if no matching threads exist.

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/3812967c84d90619848f3185f22470204fc88bd8/libs/code/deepagents_code/sessions.py#L1356)