Upgrade from 0.3

What an app on Tandem 0.3 changes to build on 0.4.0.

Move tandem and tandem_generator to 0.4. When pubspec.yaml lists tandem_firebase_ai, add it to the command. Its 0.2 needs tandem 0.4.

flutter pub upgrade --major-versions tandem tandem_generator

Run the generator again. For each class with @TandemAgent() that lists methods, it now also writes an enum of them, such as OrderCubitTool. A method named like a reserved word or a name the enum already uses, such as _switch, index or String, gets a trailing underscore there: OrderCubitTool.switch_, which the agent still calls switch. One whose name starts with a digit after its underscores gets a leading $: _2fa gives $2fa, which the agent still calls 2fa. The build fails and asks you to rename one name when two methods would become the same member, or when the class's library already declares the enum's name, such as a class NameTool next to Name.

dart run build_runner build

Then run dart analyze and fix everything it reports, warnings included.

Match tools by the generated enum

AgentCall.tool, ApprovalRequest.tool and Calling.tool are a ToolName. Match them with a value of the generated enum:

// 0.3
AgentCall(tool: 'place_order', :final result) => 'Placed order $result.',
// 0.4
AgentCall(tool: OrderCubitTool.placeOrder, :final result) =>
  'Placed order $result.',

A 0.3 pattern such as AgentCall(tool: 'place_order') still compiles and never matches. dart analyze fails on it with the warning constant_pattern_never_matches_value_type. flutter run builds the app anyway.

A comparison such as request.tool == 'place_order' is always false for the same reason. Only the lint unrelated_type_equality_checks reports it, as an info, and flutter_lints and package:lints/core turn it on. Without that lint, turn it on in analysis_options.yaml or search the app for .tool compared with a string.

In a string, a value of the generated enum prints as the method's name in snake_case, so 'Running $tool…' still shows Running place_order…. tool.value returns that name.

AgentStep.callTool, AgentListing and TandemBridge.call still take the name as a string, so tests that use them need no change.

Read the thread ID from its value

TandemThread.id is a ThreadId:

// 0.3
final threadId = session.thread.id;
// 0.4
final threadId = session.thread.id.value;

Build approval requests from a map

The ApprovalRequest() constructor for tests and previews takes arguments as a map and is no longer const. It picks its own toolCallId:

// 0.3
const request = ApprovalRequest(
  toolCallId: 'call-1',
  tool: 'place_order',
  description: 'Places the order exactly as it is on the screen.',
  argumentsJson: '{}',
);
// 0.4
final request = ApprovalRequest(
  tool: OrderCubitTool.placeOrder,
  description: 'Places the order exactly as it is on the screen.',
  arguments: {},
);

request.toolCallId is a ToolCallId. Read the ID from request.toolCallId.value.

Read the HTTP status

AgentHttpException.statusCode is replaced by status, a ResponseStatus. Read the number from status.code:

// 0.3
AgentHttpException(:final statusCode) => 'The agent answered $statusCode',
// 0.4
AgentHttpException(:final status) => 'The agent answered ${status.code}',

A test builds the exception with AgentHttpException(ResponseStatus(500), body).

Replace the on-device agent

OnDeviceAgent, OnDeviceAvailability and OnDeviceErrorCode are removed, and tandem no longer has native code. An app with its own backend passes the backend's URL as agent:, or an HttpAgentConnection as connection:. An app without one connects the screen to Firebase AI Logic with FirebaseConnection from tandem_firebase_ai in place of OnDeviceAgent.apple():

  final connection = FirebaseConnection(
    firebase: FirebaseAI.googleAI(),
    model: model,
    instructions:
        'Help the user prepare their order. '
        'Describe the result after each change. '
        'Only place an order when the user asks you to.',
  );

Initialize Firebase and App Check first, create the connection outside build, and pass it to TandemScope.connected as connection:.

Name tools in a schema written by hand

An AgentSchema written without tandem_generator declares its own enum that implements ToolName and passes its values as AgentTool.name:

enum ShopTool(@override final String value) implements ToolName {
  addItem('add_item');

  @override
  String toString() => value;
}

AgentTool.read(arguments) takes only the arguments. AgentReading, AgentPaths and AgentObjects are no longer exported. AgentComponent.property is removed.

Describe the screens again before a bridge call

TandemBridge.call and ext.tandem.call refuse a context that no open screen keeps, such as one of a closed screen. In 0.3 such a call went to the front screen. Now it answers refused with the reason No open screen keeps the context ….

In a test or a script, call TandemBridge.describe() or ext.tandem.describe again and pass the new context of the screen you mean. A call without paths can leave context out and go to the front screen. A coding agent that follows the tandem-coding-agent skill of 0.4 describes again after the refusal.