@aigne/agent-library
Collection of agent libraries for AIGNE Framework, providing pre-built agent implementations.
Introduction#
@aigne/agent-library
is a collection of agent libraries for AIGNE Framework, providing pre-built agent implementations for developers. The library is built on top of @aigne/core, extending the core functionality to simplify complex workflow orchestration.
Features#
- Orchestrator Agent: Provides OrchestratorAgent implementation for coordinating workflows between multiple agents
- Task Concurrency: Supports parallel execution of multiple tasks to improve processing efficiency
- Planning & Execution: Automatically generates execution plans and executes them step by step
- Result Synthesis: Intelligently synthesizes results from multiple steps and tasks
- TypeScript Support: Complete type definitions providing an excellent development experience
Installation#
Using npm#
npm install @aigne/agent-library @aigne/core
Using yarn#
yarn add @aigne/agent-library @aigne/core
Using pnpm#
pnpm add @aigne/agent-library @aigne/core
Basic Usage#
import { OrchestratorAgent } from "@aigne/agent-library/orchestrator";
import { AIGNE } from "@aigne/core";
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
// Create AI model instance
const model = new OpenAIChatModel({
apiKey: process.env.OPENAI_API_KEY,
model: "gpt-4-turbo",
});
// Create AIGNE
const aigne = new AIGNE({ model });
// Create orchestrator agent
const orchestrator = new OrchestratorAgent({
name: "MainOrchestrator",
instructions:
"You are a task orchestrator responsible for coordinating multiple specialized agents to complete complex tasks.",
// Configure sub-agents and tools...
});
// Execute orchestration task
const result = await aigne.invoke(
orchestrator,
"Analyze this article and generate a summary and keywords",
);
console.log(result);
Provided Agent Types#
The library currently provides one specialized agent implementation:
- Orchestrator Agent (OrchestratorAgent): Responsible for coordinating work between multiple agents and managing complex workflows. It can automatically plan task steps, distribute and execute tasks across multiple agents, and finally synthesize the results.
Advanced Usage#
Creating an Orchestration Workflow#
import { OrchestratorAgent } from "@aigne/agent-library/orchestrator";
import { AIAgent, AIGNE } from "@aigne/core";
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
const model = new OpenAIChatModel({
apiKey: process.env.OPENAI_API_KEY,
model: "gpt-4-turbo",
});
// Create specialized sub-agents
const researchAgent = AIAgent.from({
name: "Researcher",
instructions:
"You are a professional researcher responsible for collecting and analyzing information.",
outputKey: "research",
});
const writerAgent = AIAgent.from({
name: "Writer",
instructions:
"You are a professional writer responsible for creating high-quality content.",
outputKey: "content",
});
const editorAgent = AIAgent.from({
name: "Editor",
instructions:
"You are a strict editor responsible for checking content quality and formatting.",
outputKey: "edited",
});
// Create orchestrator agent
const orchestrator = new OrchestratorAgent({
name: "WorkflowOrchestrator",
instructions:
"You are responsible for coordinating research, writing, and editing processes.",
skills: [researchAgent, writerAgent, editorAgent],
// Optional configuration
maxIterations: 30, // Maximum number of iterations
tasksConcurrency: 5, // Task concurrency
});
// Use the orchestrator agent
const aigne = new AIGNE({ model });
const result = await aigne.invoke(
orchestrator,
"Applications of artificial intelligence in healthcare",
);
console.log(result);
License#
Elastic-2.0
Classes#
OrchestratorAgent<I, O>#
Orchestrator Agent Class
This Agent is responsible for:
- Generating an execution plan based on the objective
- Breaking down the plan into steps and tasks
- Coordinating the execution of steps and tasks
- Synthesizing the final result
Workflow:
- Receives input objective
- Uses planner to create execution plan
- Executes tasks and steps according to the plan
- Synthesizes final result through completer
Extends#
Agent
<I
,O
>
Type Parameters#
Type Parameter | Default type |
---|---|
| |
|
Indexable#
[key
: symbol
]: () => string
| () => Promise
<void
>
Constructors#
Constructor#
new OrchestratorAgent<
I
,O
>(options
):OrchestratorAgent
<I
,O
>
Creates an OrchestratorAgent instance
Parameters#
Parameter | Type | Description |
---|---|---|
|
| Configuration options for the Orchestrator Agent |
Returns#
OrchestratorAgent
<I
, O
>
Overrides#
Properties#
tag#
tag:
string
="OrchestratorAgent"
Overrides#
inputKey#
inputKey:
string
maxIterations?#
optional
maxIterations:number
Maximum number of iterations Prevents infinite execution loops
tasksConcurrency?#
optional
tasksConcurrency:number
Number of concurrent tasks Controls how many tasks can be executed simultaneously
Methods#
from()#
static
from<I
,O
>(options
):OrchestratorAgent
<I
,O
>
Factory method to create an OrchestratorAgent instance
Type Parameters#
Type Parameter |
---|
|
|
Parameters#
Parameter | Type | Description |
---|---|---|
|
| Configuration options for the Orchestrator Agent |
Returns#
OrchestratorAgent
<I
, O
>
A new OrchestratorAgent instance
process()#
process(
input
,options
):Promise
<O
>
Process input and execute the orchestrator workflow
Workflow:
- Extract the objective
- Loop until plan completion or maximum iterations: a. Generate/update execution plan b. If plan is complete, synthesize result c. Otherwise, execute steps in the plan
Parameters#
Parameter | Type | Description |
---|---|---|
|
| Input message containing the objective |
| Agent invocation options |
Returns#
Promise
<O
>
Processing result
Overrides#
Interfaces#
OrchestratorAgentOptions<I, O>#
Configuration options for the Orchestrator Agent
Extends#
AgentOptions
<I
,O
>
Type Parameters#
Type Parameter | Default type |
---|---|
| |
|
Properties#
Property | Type | Description |
---|---|---|
|
| Maximum number of iterations to prevent infinite loops Default: 30 |
|
| Number of concurrent tasks Default: 5 |
|
| - |