Skip to content

Latest commit

 

History

History
123 lines (87 loc) · 3.26 KB

File metadata and controls

123 lines (87 loc) · 3.26 KB

s10: System Prompt

Earlier chapters build system prompts directly in code. As the agent grows, the prompt must include role, constraints, skills, memory, project instructions, and dynamic context. Inline string formatting becomes hard to maintain.

This chapter introduces structured system prompt construction.

Run

cargo run -p s10_system_prompt

New Capabilities

  • Add a prompt builder.
  • Render prompt content from a Markdown template.
  • Include available skills.
  • Include memory guidance and memory content.
  • Load CLAUDE.md instructions.
  • Include dynamic context such as current directory, date, model, and platform.
  • Keep prompt sections explicit and easy to modify.

Why Structure the Prompt

The system prompt is part of the harness contract. It defines:

  • What the agent is.
  • What tools it can use.
  • How it should behave.
  • Which external knowledge is available.
  • What project and user rules apply.

If this is just one giant string, it becomes difficult to reason about changes.

Code Layout

s10_system_prompt/
├── src/
│   ├── main.rs
│   ├── lib.rs
│   ├── prompt.rs
│   ├── memory.rs
│   ├── skill.rs
│   ├── system_prompt_template.md
│   └── tool/
│       ├── load_skill.rs
│       ├── memory.rs
│       ├── bash.rs
│       ├── read_file.rs
│       ├── write_file.rs
│       └── edit_file.rs
└── s10.md

Prompt construction lives in src/prompt.rs. The template is src/system_prompt_template.md.

Prompt Builder

The prompt builder collects sections:

  • role
  • guidelines
  • constraints
  • available skills
  • memory
  • CLAUDE.md
  • dynamic context
  • memory guidance

Then it renders them through the template.

This keeps prompt composition explicit and makes it easier to add or remove sections.

Dynamic Context

Dynamic context can include:

  • Current date.
  • Working directory.
  • Model name.
  • Platform.
  • Git branch or other environment state.

This information changes between runs, so it should be generated at runtime instead of stored in a static prompt file.

CLAUDE.md

The harness can load project-specific instructions from CLAUDE.md.

This gives the project a conventional place to express:

  • Coding style.
  • Test commands.
  • Repository-specific constraints.
  • Workflow preferences.

The loaded content is added as a prompt section.

Skills and Memory

The prompt includes skill summaries, not full skill bodies. Full skills are loaded through load_skill.

Memory content is loaded into the prompt so the agent can apply durable preferences and facts without an extra tool call.

Rust Notes

  • Use a typed prompt builder instead of ad hoc string concatenation.
  • Keep the template in a Markdown file.
  • Keep dynamic context generation separate from static prompt text.
  • Treat prompt construction as runtime state, not a tool.

Limits

  • The prompt is still a single rendered string.
  • No token budgeting by section.
  • CLAUDE.md loading is simple.
  • No priority or conflict resolution between prompt sections.
  • No localization of prompt sections.

Next

s11 adds error recovery for prompt-too-long errors, transient transport errors, and truncated model output.