taskTool function
Creates the task tool bound to config (omp's TaskTool).
Implementation
AgentTool taskTool({required TaskToolConfig config}) {
final registry = config.executor.registry;
final executor = config.executor;
final a2aNames = [
for (final name in config.a2aManager?.servers.keys ?? const <String>[])
'### a2a:$name (REMOTE)\n'
'${config.a2aManager![name]!.config.url}',
];
final description = taskToolDescriptionPrompt
.replaceAll('{{defaultAgent}}', defaultTaskAgentName)
.replaceAll(
'{{agents}}',
[
registry.agents
.map(
(agent) =>
'### ${agent.name}${agent.readOnly ? ' (READ-ONLY)' : ''}\n'
'${agent.description}',
)
.join('\n'),
if (a2aNames.isNotEmpty) ...a2aNames,
].join('\n'),
);
return AgentTool(
name: taskToolName,
label: 'task',
tier: ApprovalTier.exec,
description: description,
parameters: const {
'type': 'object',
'properties': {
'context': {
'type': 'string',
'description':
'Shared background (project state, constraints, contracts) '
'rendered into every spawned subagent\'s system prompt',
},
'tasks': {
'type': 'array',
'description': 'One subagent per item',
'items': {
'type': 'object',
'properties': {
'name': {
'type': 'string',
'description':
'Stable id base ([A-Za-z0-9_-]); uniquified per session',
},
'agent': {
'type': 'string',
'description':
'Agent type for this item (see the tool description); '
'omit for the general-purpose worker',
},
'task': {
'type': 'string',
'description':
'Complete, self-contained instructions for the subagent',
},
'outputSchema': {
'description':
'JSON Schema the subagent\'s final output must satisfy; '
'invalid output gets one fix retry, then the item fails',
},
},
'required': ['task'],
},
},
'background': {
'type': 'boolean',
'description':
'Run items as background jobs and return job ids immediately '
'(default: host configuration)',
},
},
'required': ['context', 'tasks'],
},
execute: (arguments, cancelToken, onUpdate) async {
final items = _parseItems(arguments, registry);
final context = (arguments['context'] as String).trim();
final background =
(arguments['background'] as bool?) ?? config.defaultBackground;
return background
? _spawnBackground(config, executor, items, context, cancelToken)
: _runBlocking(
config,
executor,
items,
context,
cancelToken,
onUpdate,
);
},
);
}