Feature: AI-Powered Replies & Persona
Relevant source files
The following files were used as context for generating this wiki page:The AI-Powered Replies and Persona feature is a core component of Inbox Zero's AI assistant. It enables the system to generate context-aware, personalized email drafts by leveraging a user-defined persona and a structured knowledge base. This system is designed to automate reply generation, ensuring responses are consistent with the user's tone, style, and specific knowledge, thereby reducing the time spent on managing emails.
The persona is not only used for drafting replies but also for generating analytical reports on the user's email behavior, providing insights into their professional identity and priorities. The user's persona and knowledge base are managed through interactions with the AI assistant, allowing for dynamic updates and refinements.
Sources: ARCHITECTURE.md:120-134, apps/web/utils/ai/reply/draft-with-knowledge.ts, apps/web/utils/ai/report/build-user-persona.ts
System Architecture
The feature is composed of several interconnected modules that work together to generate a reply. The process begins when a draft needs to be generated, which triggers a pipeline involving knowledge extraction, context collection, and final draft generation by an LLM.
The following diagram illustrates the high-level data flow for generating an AI-powered reply.
Persona & Knowledge Management
The personalization of the AI assistant is rooted in the user's persona and a dedicated knowledge base. These elements provide the necessary context for the AI to generate relevant and accurate responses.
Sources: apps/web/utils/ai/assistant/chat.ts
User Persona
The user's persona is primarily defined by two attributes on the EmailAccount model:
about: A free-text field where the user can describe their role, company, and general context.writingStyle: A field to guide the AI on the desired tone and style of the replies.
This information is passed to the LLM during reply generation to ensure the tone and content align with the user's professional identity. The AI assistant provides a tool, updateAbout, to modify this information.
Sources: apps/web/utils/ai/assistant/chat.ts:484-513, apps/web/utils/ai/reply/draft-with-knowledge.ts:58-64
Knowledge Base
The Knowledge Base allows users to store specific pieces of information that the AI can use to answer questions. It is implemented using the Knowledge model in Prisma, which consists of a title and content.
Example knowledge base entries from tests include pricing for services, which the AI can then use to reply to sponsorship inquiries.
Sources: apps/web/tests/ai-extract-knowledge.test.ts:10-72
The AI assistant provides the addToKnowledgeBase tool to add new entries, making it easy for users to expand the AI's knowledge over time.
| AI Assistant Tool | Description | Input Schema |
|---|---|---|
updateAbout | Updates the user's about information. This replaces any existing information. | { about: string } |
addToKnowledgeBase | Adds a new entry to the user's knowledge base. Titles must be unique. | { title: string, content: string } |
Sources: apps/web/utils/ai/assistant/chat.ts:449-482, apps/web/utils/ai/assistant/chat.ts:484-513
Reply Generation Pipeline
The process of generating a draft is a multi-step pipeline orchestrated by generate-draft.ts.
This diagram shows the sequence of operations from the initial trigger to the final draft creation.
1. Knowledge Extraction
Before a reply can be drafted, the system first extracts the most relevant information from the user's knowledge base. This is handled by the aiExtractRelevantKnowledge function.
Sources: apps/web/utils/ai/knowledge/extract.ts
The function is guided by a system prompt that instructs the AI to act as a "knowledge extraction agent".
// apps/web/utils/ai/knowledge/extract.ts:5-29
const system = `You are a knowledge extraction agent. Your task is to analyze the provided knowledge base entries and extract the most relevant information for drafting an email response, based ONLY on the provided knowledge base entries.
Given:
1. A set of knowledge base entries (each with a title and content)
2. The content of an email that needs to be responded to
3. Information about the user responding
Your task:
1. Analyze the email content to understand the context and requirements of the query.
2. Review all knowledge base entries provided in the <knowledge_base> section.
3. Extract and summarize information ONLY from the <knowledge_base> section that is directly relevant to answering the query in the email.
4. Provide a brief explanation of why this specific information from the knowledge base is relevant to the email query.
5. DO NOT include information about the email itself in 'relevantContent'. Your response should ONLY contain information extracted from the knowledge base.
6. If no relevant information is found in the knowledge base, return an empty string for 'relevantContent'.
Keep the extracted content concise (max 2000 characters) but include all crucial information.
Format your response as a JSON object with two fields:
- relevantContent: A string containing the extracted, relevant information from the knowledge base.
- explanation: A brief string explaining why this information is relevant.
...
`;
The expected output is a JSON object conforming to the extractionSchema.
| Field | Type | Description |
|---|---|---|
relevantContent | string | Extracted relevant information from the knowledge base. |
explanation | string | Explanation of why the extracted information is relevant. |
Sources: apps/web/utils/ai/knowledge/extract.ts:80-86
2. Reply Drafting
With the relevant knowledge extracted, the aiDraftWithKnowledge function is called to generate the final reply. This function receives a comprehensive set of context, including:
- The user's persona (
aboutfield). - The extracted knowledge base content.
- A summary of historical email exchanges with the sender.
- Context from similar, precedent email threads.
- The user's defined writing style.
Sources: apps/web/utils/ai/reply/draft-with-knowledge.ts:54-60
The system prompt for this step instructs the AI to be concise, professional, and to avoid mentioning that it is an AI.
// apps/web/utils/ai/reply/draft-with-knowledge.ts:10-24
const system = `You are an expert assistant that drafts email replies using knowledge base information.
Write a polite and professional email that follows up on the previous conversation.
Keep it concise and friendly.
IMPORTANT: Keep the reply short. Aim for 2 sentences at most.
Don't be pushy.
Use context from the previous emails and the provided knowledge base to make it relevant and accurate.
IMPORTANT: Do NOT simply repeat or mirror what the last email said. It doesn't add anything to the conversation to repeat back to them what they just said.
Your reply should aim to continue the conversation or provide new information based on the context or knowledge base. If you have nothing substantial to add, keep the reply minimal.
Don't mention that you're an AI.
Don't reply with a Subject. Only reply with the body of the email.
IMPORTANT: Use placeholders sparingly! Only use them where you have limited information.
Never use placeholders for the user's name. You do not need to sign off with the user's name. Do not add a signature.
Do not invent information. For example, DO NOT offer to meet someone at a specific time as you don't know what time the user is available.
Return your response in JSON format.
`;
The output is a JSON object containing the drafted reply.
| Field | Type | Description |
|---|---|---|
reply | string | The complete email reply draft. |
Sources: apps/web/utils/ai/reply/draft-with-knowledge.ts:133-138
Persona Analytics
Beyond drafting replies, the persona concept is also used for analytics. The aiBuildUserPersona function analyzes email summaries, signatures, and templates to generate a professional profile of the user.
This function is likely used in a reporting or analytics feature to give users insights into their own communication patterns and professional focus.
*Sources: apps/web/utils/ai/report/build-user-persona.ts_
The process is as follows:
- Collect summaries of received and sent emails.
- Gather the user's Gmail signature and any saved templates.
- Pass this data to an LLM with a prompt to identify the user's professional identity and current priorities.
- The LLM returns a structured JSON object.
The output schema is defined by userPersonaSchema.
| Field | Type | Description |
|---|---|---|
professionalIdentity | object | Contains the identified persona and supporting evidence. |
currentPriorities | string[] | A list of current professional priorities based on email content. |
Sources: apps/web/utils/ai/report/build-user-persona.ts:10-18
Conclusion
The AI-Powered Replies & Persona feature is a sophisticated system that deeply integrates into the user's workflow. By combining a user-managed persona and knowledge base with AI-driven context extraction and drafting, Inbox Zero can produce highly personalized and relevant email replies. The dual use of the persona for both reply generation and analytics provides a comprehensive AI assistant that not only saves time but also delivers valuable insights. The entire process is managed through a series of orchestrated LLM calls, with clear separation of concerns between knowledge extraction, context gathering, and final drafting.