Skip to main content

Package Installation

Install the package using your preferred package manager:
npm install @deepagents/context

Basic Import

Import the functions and classes you need:
import {
  // Renderers
  XmlRenderer,
  MarkdownRenderer,
  TomlRenderer,
  ToonRenderer,
  
  // Domain fragments
  term,
  hint,
  guardrail,
  example,
  workflow,
  
  // User fragments
  identity,
  persona,
  preference,
  
  // Message fragments
  user,
  assistant,
  reminder,
} from '@deepagents/context';

Browser Entry Point

For browser environments, use the browser-specific export that excludes server-only modules:
import {
  identity,
  reminder,
  term,
  user,
  // ... other browser-compatible exports
} from '@deepagents/context/browser';
The browser entry point intentionally excludes:
  • Store implementations (SQLite, PostgreSQL, SQL Server)
  • Sandbox tooling
  • Filesystem-based skill loading
  • Stream persistence utilities

Stream Persistence (Server-Only)

If you need stream persistence, import the server-only modules:
import {
  SqliteStreamStore,
  StreamManager,
} from '@deepagents/context';
Stream persistence requires Node.js and is not available in browser environments.

TypeScript Configuration

The package includes TypeScript definitions out of the box. Ensure your tsconfig.json includes:
tsconfig.json
{
  "compilerOptions": {
    "moduleResolution": "bundler",
    "module": "ESNext",
    "target": "ES2022",
    "lib": ["ES2022"],
    "types": ["node"]
  }
}

Verify Installation

Create a simple test file to verify the installation:
test.ts
import { XmlRenderer, term } from '@deepagents/context';

const renderer = new XmlRenderer();
const output = renderer.render([
  term('API', 'Application Programming Interface'),
]);

console.log(output);
Run the test:
node --import tsx test.ts
Expected output:
<term>
  <name>API</name>
  <definition>Application Programming Interface</definition>
</term>

Dependencies

The package has the following dependencies:
  • ai - Vercel AI SDK for streaming utilities
  • pluralize - Pluralization for group rendering
  • stringcase - Case conversion utilities
  • yaml - YAML parsing (for skills)
  • pg - PostgreSQL client (optional)
  • mssql - SQL Server client (optional)
Install only if you need database store implementations.

Next Steps

Creating Fragments

Learn how to create and compose context fragments

Using Renderers

Explore different output formats

Domain Knowledge

Add business logic and domain knowledge

API Reference

Complete API documentation

Build docs developers (and LLMs) love