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. lists tandem_firebase_ai, add it to the command. Its 0.2 needs tandem 0.4.
flutter pub upgrade --major-versions tandem tandem_generatorRun 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., 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 buildThen run dart and fix everything it reports, warnings included.
Match tools by the generated enum
AgentCall., ApprovalRequest. and Calling. 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: still compiles and never matches. dart fails on it with the warning constant_pattern_never_matches_value_type. flutter builds the app anyway.
A comparison such as request. 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/ turn it on. Without that lint, turn it on in analysis_options. or search the app for . compared with a string.
In a string, a value of the generated enum prints as the method's name in snake_case, so 'Running still shows Running . tool. returns that name.
AgentStep., AgentListing and TandemBridge. still take the name as a string, so tests that use them need no change.
Read the thread ID from its value
TandemThread. 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. is a ToolCallId. Read the ID from request..
Read the HTTP status
AgentHttpException. is replaced by status, a ResponseStatus. Read the number from status.:
// 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), .
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.:
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. 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.:
enum ShopTool(@override final String value) implements ToolName {
addItem('add_item');
@override
String toString() => value;
}AgentTool. takes only the arguments. AgentReading, AgentPaths and AgentObjects are no longer exported. AgentComponent. is removed.
Describe the screens again before a bridge call
TandemBridge. and ext. 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 .
In a test or a script, call TandemBridge. or ext. 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.