tools property
Middleware can act as a "kit" by providing tools directly.
These tools will be added to the tool list of the generate call.
Implementation
@override
List<Tool> get tools {
final tools = <Tool>[];
for (final agentName in _agentNames) {
final toolName = _makeToolName(_prefix, agentName);
final description = 'Delegates a task to the "$agentName" sub-agent.';
if (_async) {
tools.add(
Tool<AsyncDelegateInput, AgentDelegationResult>(
name: toolName,
description: description,
inputSchema: AsyncDelegateInput.$schema,
outputSchema: AgentDelegationResult.$schema,
fn: (input, _) async => .response(
input.background == true
? await _launchDelegation(agentName, input.task, input.name)
: await _runDelegation(agentName, input.task, input.name),
),
),
);
} else {
tools.add(
Tool<DelegateInput, AgentDelegationResult>(
name: toolName,
description: description,
inputSchema: DelegateInput.$schema,
outputSchema: AgentDelegationResult.$schema,
fn: (input, _) async => .response(
await _runDelegation(agentName, input.task, input.name),
),
),
);
}
}
if (_async) tools.addAll(_backgroundTaskTools());
// The continue tool is always registered when agents are configured. Go
// registers it only when a sub-agent may be server-managed, but that needs
// async agent resolution the synchronous `tools` getter cannot do here, so
// it is registered unconditionally and refuses gracefully for a
// client-managed handle.
tools.add(_continueTool());
return tools;
}