agents function

  1. @experimental
GenerateMiddlewareRef<AgentsOptions> agents({
  1. required List<String> agents,
  2. String? toolPrefix,
  3. int? maxDelegations,
  4. int? historyLength,
  5. String? artifactStrategy,
  6. bool? async,
})

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,
    ),
  );
}