Skip to main content

tandem_generator 0.2.1 copy "tandem_generator: ^0.2.1" to clipboard
tandem_generator: ^0.2.1 copied to clipboard

Generates the code behind a Tandem agent list: the names, doc comments and JSON Schemas of what a class lets the agent see and call.

example/example.md

A Cubit with @TandemAgent() lists what the agent sees and calls. It is the order form of the README of tandem:

@TandemAgent()
class OrderCubit({required final Orders orders})
    extends Cubit<OrderState>
    with _$OrderCubit {
  this : super(.new(draft: .empty));

  @override
  List<AgentCapability> get agentCapabilities => [
    .sees(draft),
    .calls(setQuantity),
    if (draft.lines.isNotEmpty) .callsWithApproval(placeOrder),
  ];

  @override
  Stream<Object?> get changes => stream;

  /// The order as the user sees it on the screen.
  OrderDraft get draft => state.draft;

  /// Sets how many pieces of [sku] the order has.
  void setQuantity(String sku, int quantity) =>
      emit(.new(draft: draft.withQuantity(sku, quantity)));

  /// Places the order exactly as it is on the screen.
  Future<OrderId> placeOrder() => orders.place(draft);
}

dart run build_runner build writes the _$OrderCubit mixin into order_cubit.g.dart. Its agentSchema gives each .sees its name, doc comment and JSON:

        AgentView.of(
          () => surface.draft,
          'draft',
          'The order as the user sees it on the screen.',
          (draft) => {
            'lines': [
              for (final item in draft.lines)
                {'sku': item.sku, 'quantity': item.quantity},
            ],
          },
        ),

And each method its name in snake_case, doc comment, JSON Schema and a call with the agent's arguments:

        AgentTool(
          surface.setQuantity,
          name: 'set_quantity',
          description: 'Sets how many pieces of [sku] the order has.',
          parameters: const {
            'type': 'object',
            'properties': {
              'sku': {'type': 'string'},
              'quantity': {'type': 'integer'},
            },
            'required': ['sku', 'quantity'],
          },
          invoke: (args) {
            surface.setQuantity(args.read('sku'), args.read('quantity'));
            return null;
          },
        ),

How an app uses it, from the scope to the chat: the example of tandem and its README.

1
likes
0
points
1.02k
downloads

Publisher

verified publisherleancode.co

Weekly Downloads

Generates the code behind a Tandem agent list: the names, doc comments and JSON Schemas of what a class lets the agent see and call.

Repository (GitHub)
View/report issues

Topics

#ai #agent #codegen #build-runner #json-schema

License

unknown (license)

Dependencies

analyzer, build, build_config, source_gen

More

Packages that depend on tandem_generator