Skip to content

feat: per-group agent personas from WhatsApp group description #1291

@vaddisrinivas

Description

@vaddisrinivas

Summary

WhatsApp groups have a description field. Baileys already fetches it via groupFetchAllParticipating() in syncGroupMetadata() — available as metadata.desc but currently unused.

The idea: use it as the agent's system prompt for that group.

How it would work

Two small changes:

src/channels/whatsapp.ts (nanoclaw-whatsapp) — inside the existing syncGroupMetadata loop, write metadata.desc to groups/{folder}/group-persona.md when present for a registered group.

src/index.ts (nanoclaw core) — before building the prompt, check for group-persona.md and prepend it as a <group_persona> block:

const rawPrompt = formatMessages(missedMessages, TIMEZONE);
const personaPath = path.join(GROUPS_DIR, group.folder, 'group-persona.md');
const personaPrefix = fs.existsSync(personaPath)
  ? `<group_persona>\n${fs.readFileSync(personaPath, 'utf-8').trim()}\n</group_persona>\n\n`
  : '';
const prompt = personaPrefix + rawPrompt;

Result

Set the WhatsApp group description in the app → agent in that group adopts that personality. No config files, no code changes, no restart. Works per-group, fully isolated.

Group description: "You are a finance assistant. Only answer budget and expense questions. Respond in bullet points."
→ Agent in that group behaves exactly that way.

The group-persona.md file persists on disk across restarts and is re-synced from WhatsApp on each metadata cycle.

The cross-repo question

The whatsapp.ts change belongs in nanoclaw-whatsapp. The index.ts change belongs here in core nanoclaw — which makes this a two-repo skill.

Before going further, wanted to ask: is there interest in making the prompt-building step pluggable so channels can inject context without touching index.ts? Something like a getPromptContext?(group) method on the Channel interface that index.ts calls before building the prompt. That would keep the feature entirely within the WhatsApp channel layer.

Reference implementation

Working implementation with tests on vaddisrinivas/nanoclaw-whatsapp — ~20 lines across both files, 4 new tests in whatsapp.test.ts, all passing.

Happy to structure this as a skill branch PR if there's interest — just want to align on the right approach for the index.ts dependency first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions