agents function
Creates a middleware ref that enables sub-agent delegation.
For every agent name listed the middleware injects a dedicated delegation
tool (e.g. delegate_to_researcher) whose description is auto-discovered
from the agent's registry metadata. A <sub-agents> block is appended to
the system prompt listing the available agents and their descriptions.
With async set, delegation tools additionally accept a background flag,
and the check_background_tasks / wait_for_background_tasks /
abort_background_tasks tools are added for collecting background results.
Implementation
@experimental
GenerateMiddlewareRef<AgentsOptions> agents({
required List<String> agents,
String? toolPrefix,
int? maxDelegations,
int? historyLength,
String? artifactStrategy,
bool? async,
}) {
return middlewareRef(
name: 'agents',
config: AgentsOptions(
agents: agents,
toolPrefix: toolPrefix,
maxDelegations: maxDelegations,
historyLength: historyLength,
artifactStrategy: artifactStrategy,
async: async,
),
);
}