エージェントの永続化
再利用のためにエージェントをデータベースに保存・読み込みします。
クイックスタート#
完全なサンプルをクローンする#
最も簡単な始め方は、完全なサンプルリポジトリをクローンすることです。
git clone https://github.com/astreus-ai/examples
cd examples/agent-persistence
npm installまたはパッケージのみをインストール#
ゼロから構築したい場合は次のようにします。
npm install @astreus-ai/astreus環境設定#
# .env
OPENAI_API_KEY=sk-your-openai-api-key-here
DB_URL=sqlite://./astreus.dbエージェントの永続化#
import { Agent } from '@astreus-ai/astreus';
// Create and save an agent
const agent = await Agent.create({
name: 'ProjectAssistant',
model: 'gpt-6-astra',
memory: true,
systemPrompt: 'You are a project management assistant.'
});
// Use the agent
await agent.ask("Remember that our project deadline is March 15th");
// Later, load the same agent by name
const loadedAgent = await Agent.findByName('ProjectAssistant');
const response = await loadedAgent?.ask("What is our project deadline?");
console.log(response); // Should remember March 15thサンプルの実行#
リポジトリをクローンした場合は次を実行します。
npm run devリポジトリ#
完全なサンプルはGitHubで公開されています: examples/agent-persistence