Skip to content

Commit 9cd2937

Browse files
committed
🤖 feat: add memory encoding instruction to system prompt
When users ask the agent to 'remember' something, encode that lesson into the project's AGENTS.md file. Also adds auto-sync for docs/system-prompt.md: - Uses #region/#endregion markers in source - make fmt updates docs automatically - make fmt-check (via static-check) catches drift
1 parent 3bb190c commit 9cd2937

File tree

4 files changed

+86
-28
lines changed

4 files changed

+86
-28
lines changed

docs/system-prompt.md

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ To that end, we're built on the [Vercel AI SDK](https://ai-sdk.dev/providers/ai-
66

77
Even with consistent support at the protocol layer, we have found that different models react very differently to the same set of tools and instructions. So, **we strive to minimize the system prompt and let users figure out the prompting trade-offs**.
88

9-
Here's a snippet from `src/services/systemMessage.ts` which is our shared system prompt (minus tools).
9+
Here's a snippet from `src/node/services/systemMessage.ts` which is our shared system prompt (minus tools).
1010

11-
<!-- keep this in sync with the code above -->
11+
<!-- AUTO-GENERATED: Do not edit manually. Run 'make fmt' to update. -->
1212

1313
```typescript
1414
// The PRELUDE is intentionally minimal to not conflict with the user's instructions.
1515
// mux is designed to be model agnostic, and models have shown large inconsistency in how they
1616
// follow instructions.
17-
const PRELUDE = `
17+
const PRELUDE = `
1818
<prelude>
19-
You are a coding agent.
19+
You are a coding agent called Mux. You may find information about yourself here: https://mux.coder.com/.
2020
2121
<markdown>
2222
Your Assistant messages display in Markdown with extensions for mermaidjs and katex.
@@ -30,14 +30,18 @@ When creating mermaid diagrams:
3030
3131
Use GitHub-style \`<details>/<summary>\` tags to create collapsible sections for lengthy content, error traces, or supplementary information. Toggles help keep responses scannable while preserving detail.
3232
</markdown>
33+
34+
<memory>
35+
When the user asks you to remember something, encode that lesson into the project's AGENTS.md file (or create it if missing), matching its existing tone and structure.
36+
</memory>
3337
</prelude>
3438
`;
3539

36-
function buildEnvironmentContext(runtime: Runtime, workspacePath: string): string {
37-
const isWorktree = runtime instanceof LocalRuntime;
38-
39-
if (isWorktree) {
40-
return `
40+
/**
41+
* Build environment context XML block describing the workspace.
42+
*/
43+
function buildEnvironmentContext(workspacePath: string): string {
44+
return `
4145
<environment>
4246
You are in a git worktree at ${workspacePath}
4347
@@ -47,16 +51,5 @@ You are in a git worktree at ${workspacePath}
4751
- You are meant to do your work isolated from the user and other agents
4852
</environment>
4953
`;
50-
} else {
51-
return `
52-
<environment>
53-
You are in a git repository at ${workspacePath}
54-
55-
- This IS a git repository - run git commands directly (no cd needed)
56-
- Tools run here automatically
57-
- You are meant to do your work isolated from the user and other agents
58-
</environment>
59-
`;
60-
}
6154
}
6255
```

fmt.mk

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This file contains all code formatting logic.
44
# Included by the main Makefile.
55

6-
.PHONY: fmt fmt-check fmt-prettier fmt-prettier-check fmt-shell fmt-shell-check fmt-nix fmt-nix-check fmt-python fmt-python-check
6+
.PHONY: fmt fmt-check fmt-prettier fmt-prettier-check fmt-shell fmt-shell-check fmt-nix fmt-nix-check fmt-python fmt-python-check fmt-sync-docs fmt-sync-docs-check
77

88
# Centralized patterns - single source of truth
99
PRETTIER_PATTERNS := 'src/**/*.{ts,tsx,json}' 'mobile/**/*.{ts,tsx,json}' 'tests/**/*.ts' 'docs/**/*.md' 'package.json' 'tsconfig*.json' 'README.md'
@@ -18,10 +18,10 @@ SHFMT := $(shell command -v shfmt 2>/dev/null)
1818
NIX := $(shell command -v nix 2>/dev/null)
1919
UVX := $(shell command -v uvx 2>/dev/null || (test -x $(HOME)/.local/bin/uvx && echo $(HOME)/.local/bin/uvx))
2020

21-
fmt: fmt-prettier fmt-shell fmt-python fmt-nix
21+
fmt: fmt-prettier fmt-shell fmt-python fmt-nix fmt-sync-docs
2222
@echo "==> All formatting complete!"
2323

24-
fmt-check: fmt-prettier-check fmt-shell-check fmt-python-check fmt-nix-check
24+
fmt-check: fmt-prettier-check fmt-shell-check fmt-python-check fmt-nix-check fmt-sync-docs-check
2525
@echo "==> All formatting checks passed!"
2626

2727
fmt-prettier:
@@ -92,3 +92,9 @@ else
9292
exit 1; \
9393
fi
9494
endif
95+
96+
fmt-sync-docs:
97+
@./scripts/sync_system_prompt_docs.sh
98+
99+
fmt-sync-docs-check:
100+
@./scripts/sync_system_prompt_docs.sh check

scripts/sync_system_prompt_docs.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
# Syncs docs/system-prompt.md with the actual code in src/node/services/systemMessage.ts
3+
# Usage:
4+
# ./scripts/sync_system_prompt_docs.sh # Update docs
5+
# ./scripts/sync_system_prompt_docs.sh check # Check if in sync (exit 1 if not)
6+
7+
set -euo pipefail
8+
9+
SOURCE_FILE="src/node/services/systemMessage.ts"
10+
DOCS_FILE="docs/system-prompt.md"
11+
12+
# Extract code between #region and #endregion SYSTEM_PROMPT_DOCS markers
13+
extract_code_block() {
14+
sed -n '/^\/\/ #region SYSTEM_PROMPT_DOCS$/,/^\/\/ #endregion SYSTEM_PROMPT_DOCS$/p' "$SOURCE_FILE" \
15+
| sed '1d;$d' # Remove the marker lines themselves
16+
}
17+
18+
generate_docs() {
19+
cat <<'HEADER'
20+
# System Prompt
21+
22+
`mux` is interested in supporting a variety of models at different levels of performance.
23+
24+
To that end, we're built on the [Vercel AI SDK](https://ai-sdk.dev/providers/ai-sdk-providers) which does most of the heavy lifting in creating a unified API for all models.
25+
26+
Even with consistent support at the protocol layer, we have found that different models react very differently to the same set of tools and instructions. So, **we strive to minimize the system prompt and let users figure out the prompting trade-offs**.
27+
28+
Here's a snippet from `src/node/services/systemMessage.ts` which is our shared system prompt (minus tools).
29+
30+
<!-- AUTO-GENERATED: Do not edit manually. Run 'make fmt' to update. -->
31+
32+
```typescript
33+
HEADER
34+
extract_code_block
35+
echo '```'
36+
}
37+
38+
if [[ "${1:-}" == "check" ]]; then
39+
# Check mode: compare generated vs actual
40+
generated=$(generate_docs)
41+
actual=$(cat "$DOCS_FILE")
42+
43+
if [[ "$generated" != "$actual" ]]; then
44+
echo "$DOCS_FILE is out of sync with $SOURCE_FILE"
45+
echo "Run 'make fmt' to update."
46+
exit 1
47+
fi
48+
echo "$DOCS_FILE is in sync"
49+
else
50+
# Update mode
51+
generate_docs >"$DOCS_FILE"
52+
echo "Updated $DOCS_FILE"
53+
fi

src/node/services/systemMessage.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ import { getAvailableTools } from "@/common/utils/tools/toolDefinitions";
1515

1616
// NOTE: keep this in sync with the docs/models.md file
1717

18-
// The PRELUDE is intentionally minimal to not conflict with the user's instructions.
19-
// mux is designed to be model agnostic, and models have shown large inconsistency in how they
20-
// follow instructions.
21-
2218
function sanitizeSectionTag(value: string | undefined, fallback: string): string {
2319
const normalized = (value ?? "")
2420
.toLowerCase()
@@ -36,9 +32,14 @@ function buildTaggedSection(
3632
const tag = sanitizeSectionTag(rawTagValue, fallback);
3733
return `\n\n<${tag}>\n${content}\n</${tag}>`;
3834
}
35+
36+
// #region SYSTEM_PROMPT_DOCS
37+
// The PRELUDE is intentionally minimal to not conflict with the user's instructions.
38+
// mux is designed to be model agnostic, and models have shown large inconsistency in how they
39+
// follow instructions.
3940
const PRELUDE = `
4041
<prelude>
41-
You are a coding agent.
42+
You are a coding agent called Mux. You may find information about yourself here: https://mux.coder.com/.
4243
4344
<markdown>
4445
Your Assistant messages display in Markdown with extensions for mermaidjs and katex.
@@ -52,6 +53,10 @@ When creating mermaid diagrams:
5253
5354
Use GitHub-style \`<details>/<summary>\` tags to create collapsible sections for lengthy content, error traces, or supplementary information. Toggles help keep responses scannable while preserving detail.
5455
</markdown>
56+
57+
<memory>
58+
When the user asks you to remember something, encode that lesson into the project's AGENTS.md file (or create it if missing), matching its existing tone and structure.
59+
</memory>
5560
</prelude>
5661
`;
5762

@@ -70,6 +75,7 @@ You are in a git worktree at ${workspacePath}
7075
</environment>
7176
`;
7277
}
78+
// #endregion SYSTEM_PROMPT_DOCS
7379

7480
/**
7581
* Get the system directory where global mux configuration lives.

0 commit comments

Comments
 (0)