> 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/build-workflow/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

Compose agents into a **workflow** with an `entry` function and `registerAgents`.

## Intent router workflow

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

Future<dynamic> intentRouterEntry(WorkflowContext ctx) async {
  final intentResult = await ctx.runAgent('intent-agent');
  final intent = (intentResult is Map ? intentResult['intent'] : null) ?? 'general';
  ctx.state['intent'] = intent;

  if (intent == 'search') {
    final input = ctx.input;
    final query = input is String
        ? input
        : (input is Map ? (input['query'] ?? input['text'] ?? '').toString() : input.toString());

    final hits = await ctx.search(
      query: query,
      limit: 10,
      minSimilarity: 0.3,
      filterbySource: 'help-center',
      label: 'Semantic search',
    );
    ctx.state['searchResults'] = hits;
    return {'branch': 'search', 'intent': intentResult, 'hits': hits};
  }

  final enrichedInput = {
    'question': ctx.input is String ? ctx.input : ctx.input,
    'intentMeta': intentResult,
  };
  final generalResult = await ctx.runAgent('general-agent', input: enrichedInput);

  return {'branch': 'general', 'intent': intentResult, 'answer': generalResult};
}

final intentRouterWorkflow = Workflow(
  name: 'support-intent-router',
  description: 'Classify intent then search or general chat',
  observability: true,
  entry: intentRouterEntry,
)
  ..registerAgents({
    'intent-agent': intentAgent,
    'general-agent': generalAgent,
  });
```

## Blog pipeline workflow (sequential)

```dart
final blogArticleWorkflow = Workflow(
  name: 'blog-article-writer',
  description: 'Create, refine, and optimize a blog post',
  observability: true,
  entry: (ctx) async {
    final brief = ctx.input as Map<String, dynamic>;
    ctx.state['blogBrief'] = brief;

    final creation = await ctx.runAgent('content-creator');
    ctx.state['stage'] = 'content_creation';

    final clarity = await ctx.runAgent(
      'clarity-editor',
      input: {'content': (creation as Map)['content']},
    );
    ctx.state['stage'] = 'clarity';

    final seo = await ctx.runAgent(
      'seo-optimizer',
      input: {
        'content': (clarity as Map)['content'],
        'topic': brief['topic'],
        'keywords': brief['keywords'],
      },
    );
    ctx.state['stage'] = 'seo';

    return {
      'article': seo['content'],
      'seo': {
        'metaTitle': seo['metaTitle'],
        'metaDescription': seo['metaDescription'],
        'slug': seo['slug'],
        'keywords': seo['keywords'],
      },
    };
  },
)
  ..registerAgents({
    'content-creator': contentCreatorAgent,
    'clarity-editor': clarityEditorAgent,
    'seo-optimizer': seoOptimizerAgent,
  });
```

## Parallel pipeline (`runAgents`)

```dart
Future<dynamic> blogArticleParallelEntry(WorkflowContext ctx) async {
  final brief = ctx.input as Map<String, dynamic>;
  ctx.state['blogBrief'] = brief;

  final planning = await ctx.runAgents([
    {'name': 'outline-planner'},
    {'name': 'keyword-researcher'},
  ]);
  final outlinePlan = (planning['results'] as List)[0] as Map;
  final keywordResearch = (planning['results'] as List)[1] as Map;

  final creation = await ctx.runAgent(
    'content-creator',
    input: {
      ...brief,
      'outline': outlinePlan['outline'],
      'keywords': keywordResearch['keywords'],
    },
  );

  final refinement = await ctx.runAgents([
    {
      'name': 'clarity-editor',
      'input': {'content': (creation as Map)['content']},
    },
    {
      'name': 'seo-optimizer',
      'input': {
        'content': creation['content'],
        'topic': brief['topic'],
      },
    },
  ]);
  final clarity = (refinement['results'] as List)[0] as Map;
  final seo = (refinement['results'] as List)[1];
  return {'article': clarity['content'], 'seo': seo};
}
```

See [**Parallel agents & shared state**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/step-graph.md) for more patterns.

## Learn more

* [**Parallel agents & shared state**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/step-graph.md)
* [**Run a workflow**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/run-workflow/dart-flutter.md)
* [**Example: Multi-agent pipeline**](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/example-multi-agent/dart-flutter.md)
