flutter_agentic_graph 0.1.0 copy "flutter_agentic_graph: ^0.1.0" to clipboard
flutter_agentic_graph: ^0.1.0 copied to clipboard

Stateful agent graphs for Flutter — nodes, conditional edges, cycles, checkpointing, and human-in-the-loop. LangGraph-style orchestration for flutter_agentic.

example/main.dart

// Example: a draft → review loop with a human approval gate.
//
// Run-through of the core flutter_agentic_graph concepts: shared state,
// cycles via conditional edges, checkpointing, and human-in-the-loop.
// ignore_for_file: avoid_print
import 'package:flutter_agentic_graph/flutter_agentic_graph.dart';

Future<void> main() async {
  final graph = StateGraph(reducers: {'log': Reducers.append})
    ..addNode('draft', (state, ctx) async {
      final attempt = (state['attempts'] as int? ?? 0) + 1;
      return {'draft': 'Draft v$attempt', 'attempts': attempt, 'log': 'drafted v$attempt'};
    })
    ..addNode('review', (state, ctx) async {
      return {'approved': (state['attempts'] as int) >= 2, 'log': 'reviewed'};
    })
    ..addNode('confirm', (state, ctx) {
      // Dynamic human-in-the-loop: pause until the user answers.
      final answer = ctx.resumeValue;
      if (answer == null) ctx.interrupt('Publish "${state['draft']}"?');
      return {'published': answer == true, 'log': 'confirmed'};
    })
    ..setEntryPoint('draft')
    ..addEdge('draft', 'review')
    ..addConditionalEdge(
        'review', (s) => s['approved'] == true ? 'confirm' : 'draft')
    ..addEdge('confirm', StateGraph.end);

  final app = graph.compile(
    checkpointer: MemoryCheckpointer(),
    recursionLimit: 10,
  );

  var result = await app.invoke({}, threadId: 'demo', onEvent: print);

  if (result is GraphInterrupted) {
    print('Agent asks: ${result.payload}');
    result = await app.resume('demo', resumeValue: true);
  }

  final done = result as GraphComplete;
  print('Published: ${done.state['published']} after ${done.steps} steps');
  print('Trail: ${done.state['log']}');
}
1
likes
0
points
195
downloads

Publisher

verified publisherinlayad.com

Weekly Downloads

Stateful agent graphs for Flutter — nodes, conditional edges, cycles, checkpointing, and human-in-the-loop. LangGraph-style orchestration for flutter_agentic.

Repository (GitHub)
View/report issues

Topics

#flutter #ai #agent #graph #orchestration

License

unknown (license)

Dependencies

flutter, flutter_agentic

More

Packages that depend on flutter_agentic_graph