> 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/dart-flutter.md). Agents can also search and read this documentation through its [MCP server](https://dnotifier.gitbook.io/product-docs/~gitbook/mcp).

# Dart / Flutter

{% 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

```dart
import 'package:dnotifier/dnotifier.dart';

final notifier = DNotifier(
  appId: Platform.environment['DNOTIFIER_APP_ID']!,
  secret: Platform.environment['DNOTIFIER_SECRET']!,
  userId: 'user-123',
  transport: 'http',
);
await notifier.connect();

final agent = defineAgent(
  name: 'support',
  instructions: 'Help the user. Remember details they already shared.',
  provider: 'open_ai',
  model: 'gpt-4o',
  tools: [/* your tools */],
);

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

final sessionId = first['sessionId'] as String; // save this for follow-ups

final followUp = await notifier.runAgent(
  agent,
  input: 'Can you repeat the order number?',
  sessionId: sessionId,
);

print(followUp['output']);
print('${followUp['sessionId']} ${followUp['executionId']} ${followUp['checkpointId']}');
```

## Retry after failure

```dart
Future<Map<String, dynamic>> runWithRetry(
  Agent agent,
  dynamic input,
  String sessionId,
) async {
  try {
    return await notifier.runAgent(
      agent,
      input: input,
      sessionId: sessionId,
    );
  } catch (err) {
    print('first attempt failed: $err');
    return await notifier.runAgent(
      agent,
      input: input,
      sessionId: sessionId,
      mode: 'retry',
    );
  }
}

final result = await runWithRetry(
  agent,
  'Call the booking tool, then confirm.',
  'booking-session-1',
);
```

## Replay from a checkpoint

```dart
await notifier.runAgent(
  agent,
  sessionId: 'booking-session-1',
  fromCheckpointId: previous['checkpointId'] as String,
  mode: 'replay',
);
```

## Workflow with session continuity

```dart
final workflow = Workflow(
  name: 'fulfill-order',
  observability: true,
  entry: (ctx) async {
    final attempts = (ctx.state['attempts'] as int?) ?? 0;
    ctx.state['attempts'] = attempts + 1;
    return ctx.runAgent('support');
  },
)..registerAgent('support', agent);

final first = await notifier.runWorkflow(
  workflow: workflow,
  input: {'orderId': '1001'},
  sessionId: 'order-1001',
);

final retry = await notifier.runWorkflow(
  workflow: workflow,
  input: {'orderId': '1001'},
  sessionId: 'order-1001',
  mode: 'retry',
);
```

## In-memory checkpointer (tests / demos)

```dart
final checkpointer = MemoryCheckpointer();

await notifier.runAgent(
  agent,
  input: 'Remember that my plan is Pro.',
  sessionId: 'demo',
  checkpointer: checkpointer,
);

await notifier.runAgent(
  agent,
  input: 'What plan am I on?',
  sessionId: 'demo',
  checkpointer: checkpointer,
);
```

## Options reference

| Option             | Type                                             | Description                                      |
| ------------------ | ------------------------------------------------ | ------------------------------------------------ |
| `sessionId`        | `String?`                                        | Continue this session’s memory                   |
| `checkpointer`     | `MemoryCheckpointer` / remote / custom / `false` | Store override; `false` disables                 |
| `resume`           | `bool?`                                          | Continue from latest checkpoint                  |
| `mode`             | `String?`                                        | `"run"` \| `"resume"` \| `"retry"` \| `"replay"` |
| `fromCheckpointId` | `String?`                                        | Target checkpoint for resume/retry/replay        |

## 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)
