agents
About 308 wordsAbout 1 min
2025-09-09
Overview
The Agents API provides interfaces and classes for creating, managing, and interacting with individual agent instances in the RWKV Agent Kit ecosystem.
Classes
Agent
Base class representing an individual agent.
Constructor
constructor(config: AgentConfig)Properties
id: string- Unique identifier for the agentname: string- Human-readable name of the agentstatus: AgentStatus- Current status of the agentconfig: AgentConfig- Agent configuration
Methods
start()
Starts the agent and makes it ready to receive messages.
start(): Promise<void>stop()
Stops the agent and cleans up resources.
stop(): Promise<void>sendMessage()
Sends a message to the agent.
sendMessage(message: string): Promise<AgentResponse>Parameters:
message: The message to send to the agent
Returns:
Promise<AgentResponse>: The agent's response
getHistory()
Retrieves the conversation history.
getHistory(): ConversationHistoryReturns:
ConversationHistory: The conversation history
clearHistory()
Clears the conversation history.
clearHistory(): voidSpecializedAgent
Extended agent class with specialized capabilities.
Methods
executeTask()
Executes a specific task.
executeTask(task: Task): Promise<TaskResult>addTool()
Adds a tool to the agent's toolkit.
addTool(tool: Tool): voidremoveTool()
Removes a tool from the agent's toolkit.
removeTool(toolName: string): booleanEnums
AgentStatus
enum AgentStatus {
IDLE = 'idle',
BUSY = 'busy',
ERROR = 'error',
STOPPED = 'stopped'
}Types
AgentResponse
interface AgentResponse {
content: string;
timestamp: Date;
metadata?: Record<string, any>;
}ConversationHistory
interface ConversationHistory {
messages: HistoryMessage[];
totalCount: number;
}HistoryMessage
interface HistoryMessage {
role: 'user' | 'agent';
content: string;
timestamp: Date;
}Task
interface Task {
id: string;
type: string;
parameters: Record<string, any>;
priority?: number;
}TaskResult
interface TaskResult {
success: boolean;
result?: any;
error?: string;
executionTime: number;
}Example Usage
import { Agent, AgentStatus } from 'rwkv-agent-kit';
const agent = new Agent({
name: 'Assistant',
modelPath: './models/rwkv-model.bin'
});
await agent.start();
const response = await agent.sendMessage('Hello, how are you?');
console.log(response.content);
const history = agent.getHistory();
console.log(`Total messages: ${history.totalCount}`);