createTaskCreateTool function

Tool<JsonMap, String> createTaskCreateTool(
  1. Genkit ai, {
  2. required ToolRuntime runtime,
})

Builds the tool that creates a session task.

Implementation

Tool<JsonMap, String> createTaskCreateTool(
  Genkit ai, {
  required ToolRuntime runtime,
}) {
  return defineTextTool(
    ai,
    runtime: runtime,
    name: 'task_create',
    description: _description,
    properties: <String, Object?>{
      'subject': stringProperty('Brief imperative title.'),
      'description': stringProperty('What needs to be done, with enough detail to verify it.'),
      'activeForm': stringProperty('Present continuous form, e.g. "Running tests".'),
      'metadata': <String, Object?>{'type': 'object', 'description': 'Optional extra data attached to the task.'},
    },
    required: <String>['subject', 'description'],
    run: (input) async {
      final task = runtime.createTask(
        subject: requireString(input, 'subject').trim(),
        description: requireString(input, 'description').trim(),
        activeForm: readString(input, 'activeForm')?.trim(),
        metadata: readJsonMap(input, 'metadata'),
      );
      runtime.startTool('task_create', '#${task.id} ${task.subject}');
      return jsonEncode(<String, Object?>{'task': task.toJson()});
    },
  );
}