> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/checkpoints/python.md).

# Python

{% hint style="info" %}
Concepts and use cases: [Checkpoints, sessions & resume](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/checkpoints.md)
{% endhint %}

## Multi-turn agent

```python
import os
from dnotifier import DNotifier, define_agent

notifier = DNotifier(
    app_id=os.environ["DNOTIFIER_APP_ID"],
    secret=os.environ["DNOTIFIER_SECRET"],
    user_id="user-123",
    transport="http",
)
await notifier.connect()

agent = define_agent(
    name="support",
    instructions="Help the user. Remember details they already shared.",
    provider="open_ai",
    model="gpt-4o",
    tools=[...],  # your tools
)

# Pass your own session_id, or omit it and read result["sessionId"] after the first run.
first = await notifier.run_agent(
    agent,
    input="I need help with order 991.",
    checkpointer="memory",  # SDK creates sessionId when you don't pass one
)

session_id = first["sessionId"]  # save this for follow-ups

follow_up = await notifier.run_agent(
    agent,
    input="Can you repeat the order number?",
    session_id=session_id,
)

print(follow_up.get("output"))
print(follow_up.get("sessionId"), follow_up.get("executionId"), follow_up.get("checkpointId"))
```

## Retry after failure

```python
async def run_with_retry(agent, input_text, session_id):
    try:
        return await notifier.run_agent(
            agent,
            input=input_text,
            session_id=session_id,
        )
    except Exception as err:
        print("first attempt failed:", err)
        return await notifier.run_agent(
            agent,
            input=input_text,
            session_id=session_id,
            mode="retry",
        )

result = await run_with_retry(
    agent,
    "Call the booking tool, then confirm.",
    "booking-session-1",
)
```

## Replay from a checkpoint

```python
await notifier.run_agent(
    agent,
    session_id="booking-session-1",
    from_checkpoint_id=previous["checkpointId"],
    mode="replay",
)
```

## Workflow with session continuity

```python
from dnotifier import Workflow

async def entry(ctx):
    ctx.state["attempts"] = ctx.state.get("attempts", 0) + 1
    return await ctx.run_agent("support")

workflow = Workflow(
    name="fulfill-order",
    observability=True,
    entry=entry,
).register_agents({"support": agent})

first = await notifier.run_workflow(
    workflow=workflow,
    input_data={"orderId": "1001"},
    session_id="order-1001",
)

retry = await notifier.run_workflow(
    workflow=workflow,
    input_data={"orderId": "1001"},
    session_id="order-1001",
    mode="retry",
)
```

## In-memory checkpointer (tests / demos)

```python
from dnotifier import MemoryCheckpointer

checkpointer = MemoryCheckpointer()

await notifier.run_agent(
    agent,
    input="Remember that my plan is Pro.",
    session_id="demo",
    checkpointer=checkpointer,
)

await notifier.run_agent(
    agent,
    input="What plan am I on?",
    session_id="demo",
    checkpointer=checkpointer,
)
```

## Options reference

| Option               | Type                                             | Description                               |
| -------------------- | ------------------------------------------------ | ----------------------------------------- |
| `session_id`         | `str`                                            | Continue this session’s memory            |
| `checkpointer`       | `"memory"` \| `"remote"` \| object \| `False`    | Store override; `False` disables          |
| `resume`             | `bool`                                           | Continue from latest checkpoint           |
| `mode`               | `"run"` \| `"resume"` \| `"retry"` \| `"replay"` | Explicit run mode                         |
| `from_checkpoint_id` | `str`                                            | Target checkpoint for resume/retry/replay |

CamelCase aliases such as `sessionId` / `fromCheckpointId` are also accepted where the SDK already supports them.

## Next steps

* [Checkpoints overview](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/checkpoints.md)
* [Run a workflow](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/run-workflow.md)
* [Workflow observability](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/observability.md)
