에이전트
Astreus 문서에서 에이전트에 대해 알아보고, 에이전트 시스템을 구축하기 위한 설정 안내, API 패턴, 실용적인 예제를 확인하세요. 안정적인 Astreus 에이전트 시스템을 구축하는 데 필요한 설정 패턴, API, 실용적인 예제를 알아보세요.
모듈형 기능과 데코레이터 기반 구성을 갖춘 핵심 AI 엔티티
Overview
에이전트는 Astreus의 기본 빌딩 블록입니다. 메모리, 도구, 지식 베이스, 비전 처리 같은 설정 가능한 기능을 통해 지능적인 대화 기능을 제공합니다. 각 에이전트는 자체 컨텍스트, 메모리, 특화된 기능을 갖추고 독립적으로 동작합니다.
Creating an Agent
Astreus에서 에이전트를 만드는 방법은 간단합니다.
import { Agent } from '@astreus-ai/astreus';
const agent = await Agent.create({
name: 'MyAssistant', // Unique name for the agent
model: 'gpt-4o', // LLM model to use
systemPrompt: 'You are a helpful assistant', // Custom instructions
memory: true // Enable persistent memory
});Choosing the LLM Model
Astreus는 여러 LLM 프로바이더를 기본으로 지원합니다.
const agent = await Agent.create({
name: 'MyAssistant',
model: 'gpt-4.5' // Set model here. Latest: 'gpt-4.5', 'claude-sonnet-4-20250514', 'gemini-2.5-pro', 'deepseek-r1'
});Agent Attributes
에이전트는 다양한 속성을 통해 동작을 커스터마이즈할 수 있습니다.
Core Attributes
interface AgentConfig {
name: string; // Unique identifier for the agent
description?: string; // Agent description
model?: string; // LLM model to use (default: 'gpt-4o-mini')
embeddingModel?: string; // Specific model for embeddings (auto-detected)
visionModel?: string; // Specific model for vision (auto-detected)
temperature?: number; // Control response randomness (0-1, default: 0.7)
maxTokens?: number; // Maximum response length (default: 2000)
systemPrompt?: string; // Custom system instructions
memory?: boolean; // Enable persistent memory (default: false)
knowledge?: boolean; // Enable knowledge base access (default: false)
vision?: boolean; // Enable image processing (default: false)
useTools?: boolean; // Enable tool/plugin usage (default: true)
autoContextCompression?: boolean; // Enable smart context management (default: false)
maxContextLength?: number; // Token limit before compression (default: 8000)
preserveLastN?: number; // Recent messages to keep uncompressed (default: 3)
compressionRatio?: number; // Target compression ratio (default: 0.3)
compressionStrategy?: 'summarize' | 'selective' | 'hybrid'; // Algorithm (default: 'hybrid')
debug?: boolean; // Enable debug logging (default: false)
subAgents?: IAgent[]; // Sub-agents for delegation and coordination
}RunOptions
run() 메서드에 사용하는 옵션입니다.
interface RunOptions {
model?: string; // Override the agent's model
temperature?: number; // Override temperature
maxTokens?: number; // Override max tokens
stream?: boolean; // Enable streaming response
useTools?: boolean; // Enable/disable tools for this request
onChunk?: (chunk: string) => void; // Callback for streaming chunks
}AskOptions
ask() 메서드에 사용하는 옵션입니다 (RunOptions를 확장하여 추가 기능을 제공합니다).
interface AskOptions {
model?: string; // Override the agent's model
temperature?: number; // Override temperature
maxTokens?: number; // Override max tokens
stream?: boolean; // Enable streaming response
useTools?: boolean; // Enable/disable tools for this request
onChunk?: (chunk: string) => void; // Callback for streaming chunks
timeout?: number; // Timeout in milliseconds for sub-agent execution
// Sub-agent options
useSubAgents?: boolean; // Enable sub-agent delegation
delegation?: 'auto' | 'manual' | 'sequential'; // Delegation strategy
taskAssignment?: Record<string, string>; // agentId -> task mapping
coordination?: 'parallel' | 'sequential'; // Sub-agent coordination mode
contextIsolation?: 'isolated' | 'shared' | 'merge'; // Context handling between agents
// Attachments
attachments?: Array<{
type: 'image' | 'pdf' | 'text' | 'markdown' | 'code' | 'json' | 'file';
path: string;
name?: string;
language?: string; // For code files
}>;
// Temporary MCP servers for this request
mcpServers?: Array<{
name: string;
command?: string;
args?: string[];
url?: string;
cwd?: string;
}>;
// Temporary plugins for this request
plugins?: Array<{
plugin: {
name: string;
version: string;
description?: string;
tools?: Array<{
name: string;
description: string;
parameters: Record<string, {
name: string;
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
description: string;
required?: boolean;
}>;
handler: (params: Record<string, unknown>) => Promise<{
success: boolean;
data?: unknown;
error?: string;
}>;
}>;
};
config?: Record<string, string | number | boolean | null>;
}>;
}Example with All Attributes
// Create sub-agents first
const researcher = await Agent.create({
name: 'ResearchAgent',
systemPrompt: 'You are an expert researcher who gathers comprehensive information.'
});
const writer = await Agent.create({
name: 'WriterAgent',
systemPrompt: 'You create engaging, well-structured content.'
});
const fullyConfiguredAgent = await Agent.create({
name: 'AdvancedAssistant',
description: 'Multi-purpose AI assistant',
model: 'gpt-4o',
embeddingModel: 'text-embedding-3-small', // Optional: specific embedding model
visionModel: 'gpt-4o', // Optional: specific vision model
temperature: 0.7,
maxTokens: 2000,
systemPrompt: 'You are an expert software architect...',
memory: true,
knowledge: true,
vision: true,
useTools: true,
autoContextCompression: true,
maxContextLength: 6000, // Compress at 6000 tokens
preserveLastN: 4, // Keep last 4 messages
compressionRatio: 0.4, // 40% compression target
compressionStrategy: 'hybrid', // Use hybrid strategy
debug: true, // Enable debug logging
subAgents: [researcher, writer] // Add sub-agents for delegation
});Agent Methods
Conversation Methods
// Simple conversation - returns response string
const response = await agent.ask('What is TypeScript?');
// With options
const response = await agent.ask('Analyze this image', {
temperature: 0.5,
attachments: [{ type: 'image', path: './screenshot.png' }],
mcpServers: [{ name: 'search', command: 'npx', args: ['-y', '@anthropic/mcp-search'] }],
useSubAgents: true,
delegation: 'auto',
coordination: 'sequential'
});
// Alternative: run() method (simpler, no sub-agent support)
const response = await agent.run('Hello world');Static Methods
// Find agent by ID
const agent = await Agent.findById('550e8400-e29b-41d4-a716-446655440000');
// Find agent by name
const agent = await Agent.findByName('MyAssistant');
// List all agents with pagination
const agents = await Agent.list({
limit: 10,
offset: 0,
initialize: false // Whether to initialize agents (default: false for performance)
});Lifecycle Methods
// Update agent configuration dynamically
await agent.update({
temperature: 0.8,
maxTokens: 3000
});
// Update model at runtime (synchronous)
agent.updateModel('gpt-4o');
// Clear all memory and context
const result = await agent.clearAll();
// Returns: { memoriesCleared: number, contextCleared: boolean }
// Clear session messages (free memory) - synchronous
agent.clearSessionMessages();
// Graceful cleanup and resource disposal
await agent.destroy();
// Delete agent from database
await agent.delete();Context Management Methods
// Get all context messages
const messages = agent.getContext();
// Returns: ContextMessage[]
// Get context messages (alternative)
const messages = agent.getContextMessages();
// Returns: ContextMessage[]
// Get context window information
const window = agent.getContextWindow();
// Returns: ContextWindow { messages, totalTokens, maxTokens, utilizationPercent }
// Analyze current context
const analysis = agent.analyzeContext();
// Returns: ContextAnalysis { tokenCount, messageCount, roleDistribution, ... }
// Manually compress context
const result = await agent.compressContext();
// Returns: CompressionResult { originalMessageCount, compressedMessageCount, ... }
// Clear context (with optional memory sync)
await agent.clearContext({ syncWithMemory: true });
// Export context as JSON string
const exported = agent.exportContext();
// Import context from JSON string
agent.importContext(exported);
// Generate context summary
const summary = await agent.generateContextSummary();
// Returns: ContextSummary
// Update context model (synchronous)
agent.updateContextModel('gpt-4o');
// Search context messages with filters
const results = agent.searchContext({
query: 'search term',
graphId: 'graph-uuid',
taskId: 'task-uuid',
sessionId: 'session-uuid',
role: 'user', // 'user' | 'assistant' | 'system'
limit: 10
});
// Load graph-specific context from memory
await agent.loadGraphContext(
'graph-uuid', // graphId
100, // limit (default: 100)
false // isolated - if true, only graph-specific memories (default: false)
);Utility Getters
agent.id // Agent UUID
agent.name // Agent name
agent.config // Full configuration object
agent.hasMemory() // Check if memory is enabled
agent.hasKnowledge() // Check if knowledge base is enabled
agent.hasVision() // Check if vision is enabled
agent.canUseTools() // Check if tools are enabled
agent.getId() // Get agent ID
agent.getName() // Get agent name
agent.getDescription() // Get agent description (returns string | null)
agent.getModel() // Get current model
agent.getTemperature() // Get temperature setting
agent.getMaxTokens() // Get max tokens setting
agent.getSystemPrompt() // Get system prompt (returns string | null)Response Types
ask() Response
const response = await agent.ask('What is 2+2?');
// Returns: string - The agent's response text
// Example: "2 + 2 equals 4"Agent.list() Response
const agents = await Agent.list({ limit: 10 });
// Returns array of Agent objects:
[
{
id: "550e8400-e29b-41d4-a716-446655440000",
name: "MyAssistant",
description: "Helpful assistant",
model: "gpt-4o",
// ... other config properties
}
]clearAll() Response
const result = await agent.clearAll();
// Returns:
{
memoriesCleared: 25, // Number of memories deleted
contextCleared: true // Whether context was cleared
}마지막 업데이트: 2026년 7월 6일
이 섹션에서
소개
실제 작업을 효과적으로 해결하는 자율 시스템을 구축하기 위한 오픈소스 AI 에이전트 프레임워크입니다. 안정적인 Astreus 에이전트 시스템을 구축하는 데 필요한 설정 패턴, API, 실용적인 예제를 알아보세요.
설치
npm, yarn, pnpm을 사용해 Astreus를 설치하고, 필요한 Node.js 버전을 확인한 다음 프레임워크로 AI 에이전트를 구축할 로컬 프로젝트를 준비합니다.
메모리
Astreus 문서에서 메모리에 대해 알아보고, 에이전트 시스템을 구축하기 위한 설정 안내, API 패턴, 실용적인 예제를 확인하세요. 안정적인 Astreus 에이전트 시스템을 구축하는 데 필요한 설정 패턴, API, 실용적인 예제를 알아보세요.
컨텍스트
Astreus 문서에서 컨텍스트에 대해 알아보고, 에이전트 시스템을 구축하기 위한 설정 안내, API 패턴, 실용적인 예제를 확인하세요. 안정적인 Astreus 에이전트 시스템을 구축하는 데 필요한 설정 패턴, API, 실용적인 예제를 알아보세요.