Skip to content

Dart Minimal App

This example is a good first step for validating the SDK capability layer without depending on Flutter UI.

If you are using an AI coding tool, treat this page more like reference truth than a long tutorial.
If the generated Dart integration disagrees with the docs, come back here and compare against the minimal skeleton first.

text
Use the AgentOS Dart minimal example as the reference shape and generate a minimal integration in my project that stays as close to that structure as possible.

Requirements:
- Use agentos_sdk
- Register the bundle first
- Then call modelkit.chat.create for one minimal message request
- Preserve the example order and code skeleton as much as possible
- If a model name is needed, prefer listModels() or explicitly explain the fallback choice

Example code

Source example: agentos-sdk-dart/example/agentos_sdk_dart_example.dart

dart
import 'package:agentos_sdk/agentos_sdk.dart';

Future<void> main() async {
  final sdk = AgentOSSDK(baseUrl: 'http://127.0.0.1:8888');

  await sdk.agentos.registerBundle(
    bundleId: 'com.example.minimal.dart',
    appGroupId: 'com.example.minimal',
  );

  final models = await sdk.modelkit.listModelsByTask(ModelTask.chat);

  final completion = await sdk.modelkit.chat.create(
    model: models.first.id,
    messages: <OpenAIChatCompletionChoiceMessageModel>[
      OpenAIChatCompletionChoiceMessageModel(
        role: OpenAIChatMessageRole.user,
        content: <OpenAIChatCompletionChoiceMessageContentItemModel>[
          OpenAIChatCompletionChoiceMessageContentItemModel.text(
            'Say hello from the Dart minimal app.',
          ),
        ],
      ),
    ],
  );

  print(completion.choices.first.message.content?.first.text);
}

How to run it

bash
dart pub add agentos_sdk
dart run bin/app.dart

What you should see

  • bundle registration succeeds without context or auth errors
  • the terminal prints at least one visible text reply from the model
  • the capability layer works before any Flutter UI or ChatKit integration is added

Best used when

  • you want to confirm the gateway address and model configuration first
  • you want to validate Dart types and dependency setup first
  • you want to verify the low-level request path before moving on to Flutter or ChatKit

AI mistakes to watch for

  • Skipping registerBundle(...) and assuming call context already exists
  • Mixing the responsibilities of chatkit_dart and agentos_sdk
  • Introducing Flutter UI abstractions before validating the minimal capability path
  • Hardcoding an unknown model value instead of checking available models first

Manual verification checklist

  • Does the structure still look like SDK init -> registerBundle -> chat.create?
  • Does it print at least one visible model response?
  • Does it validate the capability layer before deciding whether ChatKit is needed?