Overview
@deepagents/context is a domain-agnostic context management system for formatting context fragments into different prompt styles. It provides a flexible way to compose and render context data in multiple formats (XML, Markdown, TOML, TOON) suitable for various LLM prompt styles.
Key Features
Multi-format Rendering
Render context fragments as XML, Markdown, TOML, or TOON formats to match different LLM prompt styles
Fragment Builders
Rich set of builder functions for domain knowledge, user context, and messages
Stream Persistence
Durable stream storage with SQLite for resumable operations
Type-Safe
Built with TypeScript for complete type safety and IntelliSense support
Core Concepts
Context Fragments
Fragments are simple data structures that can be transformed into different representations. Each fragment has aname and associated data:
Fragment Categories
Fragments are organized into three main categories:Domain Fragments
Domain Fragments
Capture domain-specific knowledge that can be injected into AI prompts:
- Terms: Define business vocabulary
- Hints: Behavioral rules and constraints
- Guardrails: Safety rules and boundaries
- Examples: Question-answer pairs
- Workflows: Multi-step processes
User Fragments
User Fragments
Capture user-specific context and preferences:
- Identity: User name and role
- Persona: AI assistant identity
- Aliases: User-specific vocabulary
- Preferences: Output formatting preferences
- Corrections: Fixes to previous misunderstandings
Message Fragments
Message Fragments
Represent conversation messages:
- User messages: With optional system reminders
- Assistant messages: AI responses
- Reminders: Hidden instructions attached to messages
Renderers
Renderers transform fragments into different output formats:- XmlRenderer: Hierarchical XML with proper nesting and escaping
- MarkdownRenderer: Human-readable markdown with bullet points
- TomlRenderer: TOML-like configuration format
- ToonRenderer: Token-efficient format with CSV-style tables
Quick Example
Browser Support
For browser bundles, use the browser-specific export path that excludes server-only modules:The browser entry point excludes server-only modules like store implementations, sandbox tooling, and filesystem-based skill loading.
Next Steps
Installation
Get started by installing the package
Fragment Builders
Learn about creating and composing fragments
Renderers
Explore different output formats
API Reference
Complete API documentation