带知识库的智能体
创建具备知识库能力的智能体,以增强信息检索。
快速开始#
克隆完整示例#
最简单的开始方式是克隆完整的示例仓库:
git clone https://github.com/astreus-ai/examples
cd examples/agent-with-knowledge
npm install或仅安装包#
如果你更喜欢从零开始构建:
npm install @astreus-ai/astreus环境配置#
# .env
# LLM API key
OPENAI_API_KEY=sk-your-openai-api-key-here
# Knowledge database (required for RAG)
KNOWLEDGE_DB_URL=postgresql://username:password@localhost:5432/knowledge_db
# Main database for agent persistence
DB_URL=sqlite://./astreus.db知识智能体#
import { Agent } from '@astreus-ai/astreus';
// Create agent with knowledge enabled
const agent = await Agent.create({
name: 'CosmosBot',
model: 'gpt-6-astra',
embeddingModel: 'text-embedding-3-small', // Specify embedding model directly
knowledge: true,
systemPrompt: 'You can search and retrieve information from scientific knowledge bases about the cosmos and universe.'
});
// Add knowledge from scientific book about the sun and cosmos
await agent.addKnowledgeFromFile(
'./data/The Sun\'s Light and Heat.pdf',
{ category: 'solar-physics', version: '1.0' }
);
// Agent automatically uses knowledge in conversations
const response = await agent.ask("What is Correction for Atmospheric Absorption? Explain.");
console.log(response); // Uses knowledge base automatically运行示例#
如果你克隆了仓库:
npm run dev仓库#
完整示例可在 GitHub 上获取:examples/agent-with-knowledge