You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement a simplified system prompt builder that assembles the ~10 sections RemoteClaw needs to inject into CLI subprocess agents. This replaces OpenClaw's 26-section, 665-line builder with a clean ~100 LoC module.
RemoteClaw's CLI-subprocess architecture means the CLI agent handles most context management natively (skills, workspace files, memory, reasoning, tool discovery via MCP). The system prompt only needs to inject what the CLI agent cannot know: channel identity, messaging conventions, and formatting guidance.
Budget: ~770–1,270 tokens (2–5% of context window). Well within budget for all 4 runtimes. See the system prompt size budget analysis for full analysis.
API Surface
/** Parameters for system prompt generation. */exporttypeSystemPromptParams={/** Channel provider name (e.g., "telegram", "discord", "whatsapp"). */channelName: string;/** Display name of the user sending the message. */userName?: string|undefined;/** Agent identifier within RemoteClaw. */agentId?: string|undefined;/** IANA timezone string (e.g., "America/New_York"). */timezone?: string|undefined;/** Working directory for the CLI subprocess. */workspaceDir: string;/** Phone numbers / IDs of authorized senders (owner allowlist). */authorizedSenders?: string[]|undefined;/** Channel-specific formatting hints (e.g., LINE directives, Discord component schema). */messageToolHints?: string[]|undefined;/** Reaction/emoji guidance level. */reactionGuidance?: {level: "minimal"|"extensive";channel: string}|undefined;};/** * Build the RemoteClaw system prompt for injection into CLI subprocess agents. * * Assembles ~10 sections totaling ~3,000-5,000 chars (~770-1,270 tokens). * No promptMode switch (always full), no bootstrap context (CLI agent handles), * no tool list (MCP handles), no skills/memory/sandbox sections. */exportfunctionbuildSystemPrompt(params: SystemPromptParams): string;
Sections (10 total)
Each section is either static (constant text) or dynamic (parameterized).
1. Identity & Context (~200 chars) — Dynamic
You are running inside RemoteClaw, a middleware that connects AI agents to messaging channels.
You are responding to a message from {userName} on {channelName}.
Sets the agent's role context: it's operating as a messaging agent, not a standalone CLI tool.
2. Safety (~563 chars) — Static
Core safety principles. Always included, immutable. Adapted from OpenClaw's safety section for the RemoteClaw context. Covers: no harmful content, respect user privacy, no credential exposure.
3. Messaging Guidance (~500 chars) — Static
Cross-session messaging conventions: how to use sessions_send for reaching other channels, messaging tool behavior, reply expectations.
Only included when params.authorizedSenders is non-empty. Lists phone numbers / IDs that are trusted senders (owner allowlist).
8. Reactions (~300 chars) — Dynamic (conditional)
Emoji reaction guidance, level-dependent ("minimal" = react sparingly, "extensive" = react freely). Only included when params.reactionGuidance is provided.
Summary
Implement a simplified system prompt builder that assembles the ~10 sections RemoteClaw needs to inject into CLI subprocess agents. This replaces OpenClaw's 26-section, 665-line builder with a clean ~100 LoC module.
File:
src/middleware/system-prompt.tsTest:
src/middleware/system-prompt.test.tsDepends on: types module (PR #4, merged)
Background
RemoteClaw's CLI-subprocess architecture means the CLI agent handles most context management natively (skills, workspace files, memory, reasoning, tool discovery via MCP). The system prompt only needs to inject what the CLI agent cannot know: channel identity, messaging conventions, and formatting guidance.
Budget: ~770–1,270 tokens (2–5% of context window). Well within budget for all 4 runtimes. See the system prompt size budget analysis for full analysis.
API Surface
Sections (10 total)
Each section is either static (constant text) or dynamic (parameterized).
1. Identity & Context (~200 chars) — Dynamic
Sets the agent's role context: it's operating as a messaging agent, not a standalone CLI tool.
2. Safety (~563 chars) — Static
Core safety principles. Always included, immutable. Adapted from OpenClaw's safety section for the RemoteClaw context. Covers: no harmful content, respect user privacy, no credential exposure.
3. Messaging Guidance (~500 chars) — Static
Cross-session messaging conventions: how to use sessions_send for reaching other channels, messaging tool behavior, reply expectations.
4. Message Tool Hints (0–2,000 chars) — Dynamic (conditional)
Channel-specific formatting guidance injected from
params.messageToolHints. Only included when hints are provided. Examples:5. Reply Tags (~420 chars) — Static
Syntax for reply targeting:
[[reply_to_current]]— reply to the message that triggered this response[[reply_to:<id>]]— reply to a specific message by ID6. Silent Replies (~450 chars) — Static
NO_REPLYtoken behavior: when the agent determines no response is needed, it outputsNO_REPLYand the middleware suppresses delivery.7. Authorized Senders (~150 chars) — Dynamic (conditional)
Only included when
params.authorizedSendersis non-empty. Lists phone numbers / IDs that are trusted senders (owner allowlist).8. Reactions (~300 chars) — Dynamic (conditional)
Emoji reaction guidance, level-dependent ("minimal" = react sparingly, "extensive" = react freely). Only included when
params.reactionGuidanceis provided.9. Runtime (~300 chars) — Dynamic
Runtime metadata: channel name, timezone, agent ID. Always included.
10. Workspace (~200 chars) — Dynamic
Working directory path. Always included.
Implementation Notes
\n\n— each section is a self-contained paragraph/blockpromptModeswitch — always full (unlike OpenClaw's full/minimal/none)Test Requirements
Test file:
src/middleware/system-prompt.test.tsSection inclusion
Dynamic content
Conditional omission
messageToolHintsis undefined or emptyauthorizedSendersis undefined or emptyreactionGuidanceis undefinedSize budget
Content correctness
[[reply_to_current]]syntaxNO_REPLYtokenAcceptance Criteria
src/middleware/system-prompt.tsexportsbuildSystemPrompt()andSystemPromptParamstypenpx vitest run src/middleware/system-prompt.test.tsnpx vitest run