Agent Persistence

Save and load agents from database for reusability.

Quick Start#

Clone the Complete Example#

The easiest way to get started is to clone the complete example repository:

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

Or Install Package Only#

If you prefer to build from scratch:

bash
npm install @astreus-ai/astreus

Environment Setup#

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

Agent Persistence#

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

// Create and save an agent
const agent = await Agent.create({
  name: 'ProjectAssistant',
  model: 'gpt-4o',
  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

Running the Example#

If you cloned the repository:

bash
npm run dev

Repository#

The complete example is available on GitHub: examples/agent-persistence