#6965: feat: add CONTACTS.md for persistent WhatsApp contact storage
docs
agents
Fixes #6919
## Problem
When WhatsApp tool is connected, the agent can send messages to contacts when given the number. But in a new session, the agent doesn't remember previously used contacts and asks for the number again.
## Solution
Add persistent CONTACTS.md file in the workspace that stores contact information:
- **Created on-demand** - Only when agent first sends a WhatsApp message
- **Auto-updated** - When new contact info is provided
- **Injected into system prompt** - When messaging is available
## Changes Made
### New Files
- `src/agents/contacts.ts` - Contact parsing utilities (loadContacts, parseContactsMarkdown, findContactByName)
- `docs/reference/templates/CONTACTS.md` - Template file for the phonebook
### Modified Files
- `src/agents/workspace.ts` - Add CONTACTS.md to bootstrap file loading
- `src/agents/system-prompt.ts` - Add contacts guidance section instructing the agent to:
- Check CONTACTS.md for saved numbers before asking user
- Use WRITE tool to create file on first contact
- Use EDIT tool to APPEND new contacts (preserves existing!)
## How It Works
1. **First contact**: Agent creates CONTACTS.md with template + first contact row
2. **New contacts**: Agent uses EDIT to APPEND rows (existing contacts preserved)
3. **New sessions**: CONTACTS.md is auto-loaded in bootstrap context, agent finds saved numbers
## Testing
- Send message with new contact → CONTACTS.md created
- Start new session → send to same contact → agent uses saved number without asking
<img width="623" height="254" alt="Screenshot 2026-02-02 at 12 33 32" src="https://github.com/user-attachments/assets/8ee036de-1d90-4133-9e15-9932b137ab86" />
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds a persistent contact phonebook mechanism for messaging by introducing a `CONTACTS.md` template (under `docs/reference/templates/`) and wiring workspace bootstrap loading to include `CONTACTS.md` when present. It also adds `src/agents/contacts.ts` with basic parsing and lookup helpers, and extends the system prompt to instruct the agent to consult and maintain CONTACTS.md when the `message` tool is available.
Overall the approach fits the existing workspace-template/bootstrap model (AGENTS.md, TOOLS.md, etc.), but there are a couple correctness edge cases in the parser/matcher that can drop valid rows or lead to surprising matches, and one silent failure path when CONTACTS.md can’t be accessed.
<h3>Confidence Score: 4/5</h3>
- This PR looks safe to merge with minor correctness/UX tweaks.
- Changes are localized (new parser + prompt text + workspace bootstrap inclusion) and don’t alter core execution paths beyond adding an optional context file. The main concerns are edge cases in contact parsing/matching and silent skipping of CONTACTS.md on unexpected access errors, which could cause confusing behavior but not systemic breakage.
- src/agents/contacts.ts (parsing/matching behavior), src/agents/workspace.ts (error handling around CONTACTS.md access)
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#21953: feat(whatsapp): sender prefix on BodyForAgent + contactNames config
by mactsk · 2026-02-20
74.1%
#16064: feat: add contact-based tool permissions with verification
by jamiequint · 2026-02-14
73.2%
#11966: feat: Add Contact Guard extension with hooks for contact state mana...
by impozzible · 2026-02-08
71.8%
#9606: fix: pass fileName to WhatsApp document messages
by AytuncYildizli · 2026-02-05
71.6%
#13431: feat(whatsapp): add built-in Markdown to WhatsApp format transform
by asklee-klawd · 2026-02-10
71.5%
#8224: feat(whatsapp): extract @mentions into dedicated module
by zurizuriaria · 2026-02-03
71.2%
#10196: fix(whatsapp): sanitize raw mention IDs in outbound messages
by koala73 · 2026-02-06
70.8%
#12069: fix(whatsapp): handle native group @mentions with requireMention
by abhishek0450 · 2026-02-08
70.6%
#20003: feat(whatsapp): follow-up window for group conversations with requi...
by alexmelges · 2026-02-18
70.4%
#2772: fix: search WhatsApp account subdirs for LID mapping files
by impozzible · 2026-01-27
70.3%