Used to check for browser translation.
用于检测浏览器翻译。
ブラウザの翻訳を検出する
API Reference

agents/team-agent


Enumerations#

ProcessMode#

Defines the processing modes available for a TeamAgent.

The processing mode determines how the agents within a team are executed and how their outputs are combined.

Enumeration Members#

Enumeration Member

Value

Description

sequential

"sequential"

Process the agents one by one, passing the output of each agent to the next. In sequential mode, agents execute in order, with each agent receiving the combined output from all previous agents as part of its input.

parallel

"parallel"

Process all agents in parallel, merging the output of all agents. In parallel mode, all agents execute simultaneously, each receiving the same initial input. Their outputs are then combined based on output key ownership.

Classes#

TeamAgent<I, O>#

TeamAgent coordinates a group of agents working together to accomplish tasks.

A TeamAgent manages a collection of agents (its skills) and orchestrates their execution according to a specified processing mode. It provides mechanisms for agents to work either sequentially (one after another) or in parallel (all at once), with appropriate handling of their outputs.

TeamAgent is particularly useful for:

  • Creating agent workflows where output from one agent feeds into another
  • Executing multiple agents simultaneously and combining their results
  • Building complex agent systems with specialized components working together

Example#

Here's an example of creating a sequential TeamAgent:

const translatorAgent = FunctionAgent.from({
name: "translator",
process: (input: Message) => ({
translation: `${input.text} (translation)`,
}),
});

const formatterAgent = FunctionAgent.from({
name: "formatter",
process: (input: Message) => ({
formatted: `[formatted] ${input.translation || input.text}`,
}),
});

// Create a sequential TeamAgent with specialized agents
const teamAgent = TeamAgent.from({
name: "sequential-team",
mode: ProcessMode.sequential,
skills: [translatorAgent, formatterAgent],
});

const result = await teamAgent.invoke({ text: "Hello world" });

console.log(result);
// Expected output: {
// formatted: "[formatted] Hello world (translation)"
// }

Extends#

Type Parameters#

Type Parameter

I extends Message

O extends Message

Indexable#

[key: symbol]: () => string | () => Promise<void>

Constructors#

Constructor#

new TeamAgent<I, O>(options): TeamAgent<I, O>

Create a new TeamAgent instance.

Parameters#

Parameter

Type

Description

options

TeamAgentOptions<I, O>

Configuration options for the TeamAgent

Returns#

TeamAgent<I, O>

Overrides#

Agent.constructor

Properties#

tag#

tag: string = "TeamAgent"

Overrides#

Agent.tag

mode#

mode: ProcessMode

The processing mode that determines how agents in the team are executed.

This can be either sequential (one after another) or parallel (all at once).

reflection?#

optional reflection: ReflectionMode & Required<Pick<ReflectionMode, "maxIterations">>

The reflection mode configuration with guaranteed maxIterations value.

This is the internal representation after processing the user-provided reflection configuration, ensuring that maxIterations always has a value (defaulting to DEFAULT_REFLECTION_MAX_ITERATIONS if not specified).

iterateOn?#

optional iterateOn: keyof I

The input field key to iterate over when processing array inputs.

When set, this property enables the TeamAgent to process array values iteratively, where each array element is processed individually through the team's agent workflow. The accumulated results are returned via streaming response chunks.

See#

TeamAgentOptions.iterateOn for detailed documentation

concurrency#

concurrency: number

The maximum number of concurrent operations when processing array items.

This property controls the concurrency level for iterative processing when iterateOn is used. It determines how many array elements are processed simultaneously.

See#

TeamAgentOptions.concurrency for detailed documentation

Default#
1;
iterateWithPreviousOutput?#

optional iterateWithPreviousOutput: boolean

Controls whether to merge the output from each iteration back into the array items for subsequent iterations when using iterateOn.

See#

TeamAgentOptions.iterateWithPreviousOutput for detailed documentation

Default#
false;
includeAllStepsOutput?#

optional includeAllStepsOutput: boolean

Controls whether to include output from all intermediate steps in sequential processing.

When true, yields output chunks from every agent in the sequential chain. When false, only yields output from the final agent.

Only affects sequential processing mode. Useful for debugging and monitoring multi-step agent workflows.

Default#
false;

Methods#

from()#

static from<I, O>(options): TeamAgent<I, O>

Create a TeamAgent from the provided options.

Type Parameters#

Type Parameter

I extends Message

O extends Message

Parameters#

Parameter

Type

Description

options

TeamAgentOptions<I, O>

Configuration options for the TeamAgent

Returns#

TeamAgent<I, O>

A new TeamAgent instance

Examples#

Here's an example of creating a sequential TeamAgent:

const translatorAgent = FunctionAgent.from({
name: "translator",
process: (input: Message) => ({
translation: `${input.text} (translation)`,
}),
});

const formatterAgent = FunctionAgent.from({
name: "formatter",
process: (input: Message) => ({
formatted: `[formatted] ${input.translation || input.text}`,
}),
});

// Create a sequential TeamAgent with specialized agents
const teamAgent = TeamAgent.from({
name: "sequential-team",
mode: ProcessMode.sequential,
skills: [translatorAgent, formatterAgent],
});

const result = await teamAgent.invoke({ text: "Hello world" });

console.log(result);
// Expected output: {
// formatted: "[formatted] Hello world (translation)"
// }

Here's an example of creating a parallel TeamAgent:

const googleSearch = FunctionAgent.from({
name: "google-search",
process: (input: Message) => ({
googleResults: `Google search results for ${input.query}`,
}),
});

const braveSearch = FunctionAgent.from({
name: "brave-search",
process: (input: Message) => ({
braveResults: `Brave search results for ${input.query}`,
}),
});

const teamAgent = TeamAgent.from({
name: "parallel-team",
mode: ProcessMode.parallel,
skills: [googleSearch, braveSearch],
});

const result = await teamAgent.invoke({ query: "AI news" });

console.log(result);
// Expected output: {
// googleResults: "Google search results for AI news",
// braveResults: "Brave search results for AI news"
// }
process()#

process(input, options): PromiseOrValue<AgentProcessResult<O>>

Process an input message by routing it through the team's agents.

Depending on the team's processing mode, this will either:

  • In sequential mode: Pass input through each agent in sequence, with each agent receiving the combined output from previous agents
  • In parallel mode: Process input through all agents simultaneously and combine their outputs
Parameters#

Parameter

Type

Description

input

I

The message to process

options

AgentInvokeOptions

The invocation options

Returns#

PromiseOrValue<AgentProcessResult<O>>

A stream of message chunks that collectively form the response

Overrides#

Agent.process

Interfaces#

ReflectionMode#

Configuration for reflection mode processing in TeamAgent.

Reflection mode enables iterative refinement of agent outputs through a review process. The team agent will repeatedly process the input and have a reviewer agent evaluate the output until it meets approval criteria or reaches the maximum iteration limit.

This is particularly useful for:

  • Quality assurance workflows where outputs need validation
  • Iterative improvement processes where initial results can be refined
  • Self-correcting agent systems that learn from feedback

Properties#

Property

Type

Description

reviewer

Agent

The agent responsible for reviewing and providing feedback on the team's output. The reviewer agent receives the combined output from the team's processing and should provide feedback or evaluation that can be used to determine whether the output meets the required standards.

isApproved

string | (output) => unknown

Function or field name that determines whether the reviewer's output indicates approval. This can be either: - A function that receives the reviewer agent's output message and should return: - true or truthy value: The output is approved and processing should stop - false or falsy value: The output needs improvement and another iteration should run - A string representing a field name in the reviewer's output message to check for approval When using a function, it can be synchronous or asynchronous, allowing for complex approval logic including external validation, scoring systems, or human-in-the-loop approval. When using a string, the specified field in the reviewer's output will be evaluated for truthiness to determine approval status. Param The message output from the reviewer agent (when using function form)

maxIterations?

number

Maximum number of reflection iterations before giving up. This prevents infinite loops when the approval criteria cannot be met. If the maximum iterations are reached without approval, the process will throw an error indicating the reflection failed to converge. Default 3

returnLastOnMaxIterations?

boolean

Controls the behavior when maximum iterations are reached without approval. When set to true, the TeamAgent will return the last generated output instead of throwing an error when the maximum number of reflection iterations is reached without the reviewer's approval. When set to false or undefined, the TeamAgent will throw an error indicating that the reflection process failed to converge within the maximum iteration limit. This option is useful for scenarios where: - You want to get the best available result even if it's not perfect - The approval criteria might be too strict for the given context - You prefer graceful degradation over complete failure - You want to implement custom error handling based on the returned result Default false


TeamAgentOptions<I, O>#

Configuration options for creating a TeamAgent.

These options extend the base AgentOptions and add team-specific settings.

Extends#

Type Parameters#

Type Parameter

I extends Message

O extends Message

Properties#

Property

Type

Description

mode?

ProcessMode

The method to process the agents in the team. Default {ProcessMode.sequential}

reflection?

ReflectionMode

Configuration for reflection mode processing. When enabled, the TeamAgent will use an iterative refinement process where: 1. The team processes the input normally 2. A reviewer agent evaluates the output 3. If not approved, the process repeats with the previous output as context 4. This continues until approval or maximum iterations are reached This enables self-improving agent workflows that can iteratively refine their outputs based on feedback from a specialized reviewer agent. See ReflectionMode for detailed configuration options

iterateOn?

keyof I

Specifies which input field should be treated as an array for iterative processing. When this property is set, the TeamAgent will iterate over the array values in the specified input field, processing each element individually through the team's agents. The results from each iteration are accumulated and returned as a streaming response. This is particularly useful for batch processing scenarios where you need to apply the same agent workflow to multiple similar data items. Remarks - The specified field must contain an array or array-like value - Each array element should be an object that can be merged with the base input - Non-array values will be treated as single-element arrays - The processing results are streamed incrementally as each iteration completes

concurrency?

number

The maximum number of concurrent operations when processing array items with iterateOn. This property controls how many array elements are processed simultaneously when iterating over an array field. A higher concurrency value allows for faster parallel processing but may consume more resources. Remarks - Only applies when iterateOn is specified - Cannot be used together with iterateWithPreviousOutput (concurrency > 1) - Uses a queue-based approach to limit concurrent operations - Each concurrent operation processes one array element through the entire agent workflow Default 1

iterateWithPreviousOutput?

boolean

Controls whether to merge the output from each iteration back into the array items for subsequent iterations when using iterateOn. When set to true, the output from processing each array element is merged back into that element, making it available for the next iteration. This creates a cumulative effect where each iteration builds upon the results of previous ones. When set to false or undefined, each array element is processed independently without any cross-iteration data sharing. This is particularly useful for scenarios where: - You need to progressively enrich data across iterations - Later iterations depend on the results of earlier ones - You want to build a chain of transformations on array data Default false

includeAllStepsOutput?

boolean

Controls whether to include output from all intermediate steps in sequential processing. See TeamAgent.includeAllStepsOutput for detailed documentation Default false

Variables#

DEFAULT_REFLECTION_MAX_ITERATIONS#

const DEFAULT_REFLECTION_MAX_ITERATIONS: 3 = 3