エージェントの永続化

再利用のためにエージェントをデータベースに保存・読み込みします。

クイックスタート#

完全なサンプルをクローンする#

最も簡単な始め方は、完全なサンプルリポジトリをクローンすることです。

bash
git clone https://github.com/astreus-ai/examples
cd examples/agent-persistence
npm install

またはパッケージのみをインストール#

ゼロから構築したい場合は次のようにします。

bash
npm install @astreus-ai/astreus

環境設定#

bash
# .env
OPENAI_API_KEY=sk-your-openai-api-key-here
DB_URL=sqlite://./astreus.db

エージェントの永続化#

typescript
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

サンプルの実行#

リポジトリをクローンした場合は次を実行します。

bash
npm run dev

リポジトリ#

完全なサンプルはGitHubで公開されています: examples/agent-persistence