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 |
---|---|---|
|
| 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. |
|
| 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#
Agent
<I
,O
>
Type Parameters#
Type Parameter |
---|
|
|
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 |
---|---|---|
|
| Configuration options for the TeamAgent |
Returns#
TeamAgent
<I
, O
>
Overrides#
Properties#
tag#
tag:
string
="TeamAgent"
Overrides#
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: keyofI
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 |
---|
|
|
Parameters#
Parameter | Type | Description |
---|---|---|
|
| 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 |
---|---|---|
|
| The message to process |
| The invocation options |
Returns#
PromiseOrValue
<AgentProcessResult
<O
>>
A stream of message chunks that collectively form the response
Overrides#
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 |
---|---|---|
| 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. | |
|
| 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: - |
|
| 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 |
|
| Controls the behavior when maximum iterations are reached without approval. When set to |
TeamAgentOptions<I, O>#
Configuration options for creating a TeamAgent.
These options extend the base AgentOptions and add team-specific settings.
Extends#
AgentOptions
<I
,O
>
Type Parameters#
Type Parameter |
---|
|
|
Properties#
Property | Type | Description |
---|---|---|
| The method to process the agents in the team. Default | |
| 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 | |
| keyof | 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 |
|
| The maximum number of concurrent operations when processing array items with |
|
| Controls whether to merge the output from each iteration back into the array items for subsequent iterations when using |
|
| Controls whether to include output from all intermediate steps in sequential processing. See TeamAgent.includeAllStepsOutput for detailed documentation Default |
Variables#
DEFAULT_REFLECTION_MAX_ITERATIONS#
const
DEFAULT_REFLECTION_MAX_ITERATIONS:3
=3