# migrate_legacy_state

> **Function** in `deepagents_code`

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

Move legacy state entries from `config_dir` into `state_dir`.

Idempotent: each entry is skipped when the destination already exists
(the migration ran on a prior invocation) or when the source does not
exist (nothing to move). Errors on individual entries are logged and
swallowed so a single unmovable file does not block the rest.

## Signature

```python
migrate_legacy_state(
    *,
    config_dir: Path = DEFAULT_CONFIG_DIR,
    state_dir: Path = DEFAULT_STATE_DIR,
) -> None
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `config_dir` | `Path` | No | Directory holding legacy state. Defaults to `~/.deepagents/`. (default: `DEFAULT_CONFIG_DIR`) |
| `state_dir` | `Path` | No | Destination directory for state files. Defaults to `~/.deepagents/.state/`. (default: `DEFAULT_STATE_DIR`) |

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/d1c6946218b4f0f86ab7b02b6bb6af1e4b75cede/libs/code/deepagents_code/state_migration.py#L56)