API Reference

@aigne/agent-library


AIGNE Logo

GitHub star chart
Open Issues
codecov
NPM Version
Elastic-2.0 licensed

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.

AIGNE Arch

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:

  1. Generating an execution plan based on the objective
  2. Breaking down the plan into steps and tasks
  3. Coordinating the execution of steps and tasks
  4. 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#

Type Parameters#

Type Parameter

Default type

I extends Message

Message

O extends Message

Message

Indexable#

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

Constructors#

Constructor#

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

Creates an OrchestratorAgent instance

Parameters#

Parameter

Type

Description

options

OrchestratorAgentOptions<I, O>

Configuration options for the Orchestrator Agent

Returns#

OrchestratorAgent<I, O>

Overrides#

Agent.constructor

Properties#

tag#

tag: string = "OrchestratorAgent"

Overrides#

Agent.tag

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

I extends Message

O extends Message

Parameters#

Parameter

Type

Description

options

OrchestratorAgentOptions<I, O>

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:

  1. Extract the objective
  2. 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

I

Input message containing the objective

options

AgentInvokeOptions

Agent invocation options

Returns#

Promise<O>

Processing result

Overrides#

Agent.process

Interfaces#

OrchestratorAgentOptions<I, O>#

Configuration options for the Orchestrator Agent

Extends#

Type Parameters#

Type Parameter

Default type

I extends Message

Message

O extends Message

Message

Properties#

Property

Type

Description

maxIterations?

number

Maximum number of iterations to prevent infinite loops Default: 30

tasksConcurrency?

number

Number of concurrent tasks Default: 5

inputKey

string

-