Agents
What is an Agent?
An agent is an autonomous entity designed to:
- Execute specific tasks
- Make independent decisions
- Interact with other agents
Consider an agent as a specialized team member, equipped with unique skills and designated responsibilities. Agents can assume various roles such as 'Developer', 'Tester', or 'Project Manager', each playing a crucial part in achieving the team's collective objectives.
Creating an Agent
To create an agent, you start by initializing an instance of the Agent
class with the necessary properties. Here's how you can do it:
import { Agent } from 'kaibanjs';
const searchAgent = new Agent({
name: 'Scout',
role: 'Information Gatherer',
goal: 'Find up-to-date information about the given sports query.',
background: 'Research',
tools: [searchTool],
});
Agent Attributes
name
A descriptive or friendly identifier for easier recognition of the agent.
- Type: String
- Example: Jonh Smith
role
Defines the agent's function within the team, determining the kind of tasks it is best suited for.
- Type: String
- Example: Coordinator
goal
Specifies the individual objective the agent aims to achieve, guiding its decision-making process.
- Type: String
- Example: Achieve sales target
background
Provides context that enriches the agent's role and goal, enhancing interaction and collaboration dynamics.
- Type: String
- Example: Has extensive experience in market analysis and strategic planning
tools
(optional)
A set of capabilities or functions the agent can use, initialized with a default empty list.
- Type: Array of
Tool
objects. - Example: [SearchTool, CalculatorTool, etc]
- Default: []
llmConfig
(optional)
Configures the underlying language model used by the agent.
- Type: Object
/**
*
* @property {('openai' | 'google' | 'anthropic' | 'mistral')} provider - The provider of the language model, defaults to "openai".
* @property {string} model - Specific language model to use, defaults to "gpt-4o-mini".
* @property {number} maxRetries - Number of retries for calling the model, defaults to 1.
*
*/
{
provider: "openai", // Default provider
model: "gpt-4o-mini", // Default model
maxRetries: 1 // Default number of retries
};
Note: All properties within llmConfig
are passed to the language model constructor using the Langchain standard. For detailed information on how these properties are utilized, refer to the Langchain Model Constructor Documentation.
maxIterations
(optional)
Specifies the maximum number of iterations the agent is allowed to perform before stopping, controlling execution length and preventing infinite loops.
- Type: Integer
- Example: 25, 50, etc
- Default:
10
forceFinalAnswer
Controls whether the agent should deliver a final answer as it approaches the maximum number of allowed iterations. This is useful in scenarios where the agent has a satisfactory answer but might otherwise continue refining it.
- Type: Boolean
- Example:
false
- Default:
true
status
Indicates the current operational state of the agent. This property is read-only and provides insights into the agent's lifecycle within tasks.
- Type: Enum (Read-only)
- Example: [INITIAL, THINKING, EXECUTING_ACTION, etc]
- Enum Defined At: Agent Status Definitions
id
A unique identifier for the agent, autogenerated by the system. This property is read-only.
- Type: String (Read-only)
- Example:
"579db4dd-deea-4e09-904d-a436a38e65cf"
Conclusion
Agents are the building blocks of the KaibanJS framework. By understanding how to define and interact with agents, you can create sophisticated AI systems that leverage the power of collaborative intelligence.
Is there something unclear or quirky in the docs? Maybe you have a suggestion or spotted an issue? Help us refine and enhance our documentation by submitting an issue on GitHub. We’re all ears!