import { identity } from '@deepagents/context';// Full identityidentity({ name: 'John', role: 'VP of Sales' });// Role onlyidentity({ role: 'Data analyst in the marketing team' });// Name onlyidentity({ name: 'Sarah' });// Detailed roleidentity({ role: 'Finance manager focused on cost optimization' });
The role field helps tailor explanations, terminology, and focus areas to the user’s perspective and needs.
import { persona } from '@deepagents/context';// Basic personapersona({ name: 'DataBot', role: 'SQL Expert',});// With objectivepersona({ name: 'QueryMaster', role: 'Database Analyst', objective: 'Generate accurate SQL queries from natural language',});// Full persona with tonepersona({ name: 'Freya', role: 'Data Assistant', objective: 'Help users explore and understand their data', tone: 'friendly and professional',});
import { XmlRenderer, persona, identity } from '@deepagents/context';const fragments = [ identity({ name: 'Sarah', role: 'Product Manager' }), persona({ name: 'AnalyticsAI', role: 'Product Analytics Assistant', objective: 'Provide insights on user behavior and product metrics', tone: 'concise and data-driven', }),];const renderer = new XmlRenderer();console.log(renderer.render(fragments));
Output:
<identity> <name>Sarah</name> <role>Product Manager</role></identity><persona> <name>AnalyticsAI</name> <role>Product Analytics Assistant</role> <objective>Provide insights on user behavior and product metrics</objective> <tone>concise and data-driven</tone></persona>
import { alias } from '@deepagents/context';// Disambiguate termsalias('revenue', 'gross revenue before deductions, not net');// Map user language to dataalias('active users', 'users who logged in within the last 30 days');// Table nicknamesalias('the big table', 'the orders table');// Fiscal periodsalias('Q4', 'October through December, not fiscal Q4');
Alias vs Glossary:
alias() maps user vocabulary to table/column names (“the big table” → “orders table”)
glossary() maps terms to SQL expressions (“revenue” → “SUM(amount)”)
Use alias() for personalization, glossary() for computation.
import { preference } from '@deepagents/context';// Date formattingpreference('date format', 'YYYY-MM-DD');// Output stylepreference('output style', 'tables over charts unless showing trends');// Verbositypreference('detail level', 'always show the SQL query in responses');// Default limitspreference('row limit', 'default to 50 rows unless I ask for more');// Explanation stylepreference('explanation style', 'brief and to the point');
import { userContext } from '@deepagents/context';// Current projectuserContext('Preparing Q4 board presentation');// InvestigationuserContext('Investigating drop in signups last week');// Regional focususerContext('Working on EMEA regional analysis for strategy meeting');// DebugginguserContext('Debugging discrepancy in revenue numbers');
Update userContext() as the user’s focus changes. It helps the AI make better assumptions and suggestions based on what the user is currently working on.
import { correction } from '@deepagents/context';// Data type correctioncorrection( 'status column', '1 = active, 0 = inactive, not boolean true/false');// Table correctioncorrection( 'orders table', 'Use orders_v2, not the deprecated legacy_orders table');// Field meaning correctioncorrection( 'date field', 'order_date is when order was placed, ship_date is when shipped');// Calculation correctioncorrection( 'revenue calculation', 'Must exclude refunds and chargebacks');
Corrections are persistent reminders of past mistakes. They help prevent the AI from repeating the same misunderstandings.
import { XmlRenderer, correction, userContext } from '@deepagents/context';const fragments = [ userContext('Analyzing user retention metrics'), correction( 'active users', 'Active = logged in within 30 days, not just signed up' ), correction( 'retention calculation', 'Compare cohorts month-over-month, not cumulative' ),];const renderer = new XmlRenderer({ groupFragments: true });console.log(renderer.render(fragments));
Output:
<userContext>Analyzing user retention metrics</userContext><corrections> <correction> <subject>active users</subject> <clarification>Active = logged in within 30 days, not just signed up</clarification> </correction> <correction> <subject>retention calculation</subject> <clarification>Compare cohorts month-over-month, not cumulative</clarification> </correction></corrections>
User fragments work best when combined to create a complete user profile:
import { identity, persona, preference, userContext, alias, correction,} from '@deepagents/context';const userProfile = [ // Who is the user? identity({ name: 'Morgan', role: 'Head of Revenue Operations', }), // What are they working on? userContext('Building automated revenue forecasting model'), // How do they prefer results? preference('date format', 'YYYY-MM-DD'), preference('output', 'always show confidence intervals'), preference('aggregation', 'weekly rolling averages'), // Their vocabulary alias('bookings', 'closed-won deals with signed contracts'), alias('pipeline', 'opportunities in stages 3-6'), // Past corrections correction( 'revenue recognition', 'Use booking_date, not payment_date for revenue timing' ),];
identity({ role: 'Marketing Manager' })// AI focuses on CAC, conversion rates, campaign metricsidentity({ role: 'CFO' })// AI focuses on revenue, costs, margins, forecasts
Custom Vocabulary
Handle organization-specific terminology:
alias('active customer', 'made purchase in last 90 days')alias('churn', 'no activity for 180+ days')alias('revenue', 'net revenue after returns and discounts')
Output Formatting
Consistent formatting across sessions:
preference('currency', 'always USD with $ symbol')preference('large numbers', 'use K/M/B abbreviations')preference('dates', 'relative dates like "2 days ago" for recent')
Context-Aware Defaults
Make better assumptions based on current focus:
userContext('Analyzing Q4 holiday season performance')// AI automatically filters to Q4, focuses on seasonal metrics