功能
在 Astreus 文档中了解 功能,获取用于构建智能体系统的设置指导、API 模式和实用示例。 了解构建可靠的 Astreus 智能体系统所需的设置模式、API 和实用示例。
搭建新智能体时可以包含的每项功能的详细说明。
记忆(Memory)
为你的智能体启用持久化记忆。智能体会使用向量搜索来高效检索,从而跨会话记住对话内容。
const agent = await Agent.create({
name: 'my-agent',
model: 'gpt-4o',
memory: true,
});
await agent.ask("My name is John");
// Later, even in a new session:
await agent.ask("What's my name?"); // "Your name is John"使用场景:
- 记住用户偏好的个人助手
- 带有对话历史的客服机器人
- 需要上下文持久化的长时间运行智能体
知识库(RAG)
添加文档检索能力。将 PDF、文本文件和其他文档导入一个可搜索的知识库。
const agent = await Agent.create({
name: 'my-agent',
model: 'gpt-4o',
knowledge: true,
});
// Add documents to knowledge base
await agent.addKnowledgeFromFile('./docs/guide.pdf', { category: 'docs' });
await agent.addKnowledgeFromFile('./docs/api.md', { category: 'api' });
// Agent answers from documents
await agent.ask("What does the guide say about authentication?");使用场景:
- 文档问答机器人
- 研究助手
- 知识管理系统
要求: 带有 pgvector 扩展的 PostgreSQL
图工作流(Graph Workflows)
通过基于 DAG 的任务编排创建复杂的多步骤工作流。定义任务之间的依赖关系,并在可能的情况下并行运行。
import { Agent, Graph } from '@astreus-ai/astreus';
const agent = await Agent.create({ name: 'my-agent', model: 'gpt-4o' });
const graph = new Graph({ name: 'research-workflow' }, agent);
// Define workflow nodes
const researchNode = graph.addTaskNode({
prompt: 'Research the topic thoroughly'
});
const analyzeNode = graph.addTaskNode({
prompt: 'Analyze the research findings',
dependsOn: [researchNode]
});
const writeNode = graph.addTaskNode({
prompt: 'Write a comprehensive report',
dependsOn: [analyzeNode]
});
// Execute the workflow
const result = await graph.run();
console.log(result.results);使用场景:
- 多步骤内容生成
- 数据处理流水线
- 复杂决策工作流
子智能体(Sub-Agents)
协调多个专业化智能体来完成复杂任务。每个子智能体都可以拥有自己的配置和专长。
// Create specialized agents
const researcher = await Agent.create({
name: 'researcher',
model: 'gpt-4o',
systemPrompt: 'You are a research specialist.'
});
const writer = await Agent.create({
name: 'writer',
model: 'gpt-4o',
systemPrompt: 'You are a professional writer.'
});
// Main agent coordinates sub-agents
const agent = await Agent.create({ name: 'coordinator', model: 'gpt-4o' });
const result = await agent.executeWithSubAgents(
'Research and write an article about quantum computing',
[researcher, writer]
);使用场景:
- 内容创作流水线
- 涉及多个领域的专家系统
- 并行任务执行
自定义插件(Custom Plugins)
通过自定义工具扩展你的智能体。为每个工具定义参数、描述和处理函数。
const weatherPlugin = {
name: 'weather-plugin',
version: '1.0.0',
description: 'Get weather information',
tools: [{
name: 'get_weather',
description: 'Get current weather for a location',
parameters: {
location: {
type: 'string',
description: 'City name',
required: true
}
},
handler: async ({ location }) => {
const response = await fetch(`https://api.weather.com/${location}`);
const data = await response.json();
return { success: true, data };
}
}]
};
const agent = await Agent.create({ name: 'my-agent', model: 'gpt-4o' });
await agent.registerPlugin(weatherPlugin);
// Agent can now use the weather tool
await agent.ask("What's the weather in Tokyo?");使用场景:
- API 集成
- 数据库操作
- 自定义业务逻辑
MCP 集成
Model Context Protocol 支持,用于标准化的工具集成。可连接到兼容 MCP 的服务和工具。
const agent = await Agent.create({
name: 'my-agent',
model: 'gpt-4o',
mcp: {
servers: [
{ name: 'filesystem', command: 'mcp-server-filesystem' },
{ name: 'github', command: 'mcp-server-github' }
]
}
});使用场景:
- 文件系统操作
- GitHub 集成
- 标准化的工具生态
功能组合
各项功能可以无缝协同工作:
const agent = await Agent.create({
name: 'advanced-agent',
model: 'gpt-4o',
memory: true, // Remember conversations
knowledge: true, // Access documents
mcp: { // Use MCP tools
servers: [
{ name: 'filesystem', command: 'mcp-server-filesystem' }
]
}
});
// Register custom plugins
await agent.registerPlugin(myCustomPlugin);
// Use with graph workflows
const graph = new Graph({ name: 'workflow' }, agent);最后更新时间:2026年7月6日
本节内容