コンテキスト圧縮

Astreusの自動コンテキスト圧縮システムを使用して、重要なコンテキストを維持しながら古いメッセージを要約し、長い会話を自動的に管理します。

クイックスタート#

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

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

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

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

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

bash
npm install @astreus-ai/astreus

環境設定#

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

自動コンテキスト圧縮#

autoContextCompression機能は、会話が長くなりすぎると古いメッセージを自動的に要約し、トークン使用量を削減しながらコンテキストを維持します。

typescript
import { Agent } from '@astreus-ai/astreus';

const agent = await Agent.create({
  name: 'ContextAgent',
  model: 'gpt-6-astra',
  memory: true,
  autoContextCompression: true,
  systemPrompt: 'You can handle very long conversations efficiently.'
});

// Have a long conversation
for (let i = 1; i <= 20; i++) {
  await agent.ask(`Tell me an interesting fact about space. This is message #${i}.`);
}

// Test memory - agent should remember early facts despite context compression
const response = await agent.ask("What was the first space fact you told me?");
console.log(response);

サンプルの実行#

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

bash
npm run dev

リポジトリ#

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