agentleFS
lauren-frameworklauren-framework/lauren-ai/skills/system-prompt-templating/SKILL.md

system-prompt-templating

Skill0 starsChanged 6 months agoMITView on GitHub

Builds system prompts dynamically with composable sections, template variable substitution, and fluent builder API. Use when agent system prompts need to vary by user, context, or feature flag; when assembling role + context + constraints programmatically; or when sharing prompt fragments across multiple agents.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When you need conditional sections, structured constraints, or a fluent API, implement a SystemPromptBuilder:

    line 26
  2. Very specific:

    Prefer the built-in PromptTemplate for simple cases.

    line 113

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Use codemap find "SymbolName" to locate any symbol before reading.

System Prompt Templating & Dynamic Composition

Built-in support: PromptTemplate and ChatPromptTemplate

Lauren-AI ships PromptTemplate (single message) and ChatPromptTemplate (multi-turn) in lauren_ai._prompts. Use them for simple {variable} interpolation:

# NOTE: future annotations are allowed, but tool signature types must resolve at import time.
from lauren_ai import PromptTemplate, ChatPromptTemplate

tpl = PromptTemplate(template="You are a {role}. Context: {context}")
msg = tpl.render(role="financial analyst", context="User is a portfolio manager")
# msg.content == "You are a financial analyst. Context: User is a portfolio manager"

Custom builder for richer composition

When you need conditional sections, structured constraints, or a fluent API, implement a SystemPromptBuilder:

class PromptTemplate:
    def __init__(self, template: str):
        self._template = template

    def render(self, **kwargs) -> str:
        result = self._template
        for key, value in kwargs.items():
            result = result.replace(f"{{{key}}}", str(value))
        return result


class SystemPromptBuilder:
    def __init__(self):
        self._sections: list[str] = []

    def add_role(self, role: str) -> "SystemPromptBuilder":
        self._sections.append(f"You are {role}.")
        return self

    def add_context(self, context: str) -> "SystemPromptBuilder":
        self._sections.append(f"Context: {context}")
        return self

    def add_instruction(self, instruction: str) -> "SystemPromptBuilder":
        self._sections.append(instruction)
        return self

    def add_constraints(self, *constraints: str) -> "SystemPromptBuilder":
        if constraints:
            self._sections.append("Constraints:\n" + "\n".join(f"- {c}" for c in constraints))
        return self

    def build(self) -> str:
        return "\n\n".join(self._sections)

Full example

system = (
    SystemPromptBuilder()
    .add_role("a financial analyst specializing in risk assessment")
    .add_context("User is a portfolio manager at a hedge fund")
    .add_instruction("Always provide quantitative estimates with confidence intervals.")
    .add_constraints(
        "Never give specific stock picks",
        "Always mention risks",
    )
    .build()
)

from lauren_ai import agent

@agent(model="claude-opus-4-6", system=system)
class FinancialAgent: ...

Conditional sections

import os

builder = SystemPromptBuilder().add_role("a helpful assistant")
if os.getenv("VERBOSE_MODE"):
    builder.add_instruction("Explain each step in detail.")
if user_tier == "enterprise":
    builder.add_context("User has access to premium data feeds.")
system = builder.build()

Template variables with PromptTemplate

tpl = PromptTemplate(template="You are {role} working for {company}.")
system = tpl.render(role="a legal advisor", company="Acme Corp")

Pitfalls

  • build() joins sections with "\n\n" — sections should not have trailing newlines themselves or you get extra blank lines.
  • Template {key} replacement is plain string substitution — curly braces in the template for non-variable purposes must be avoided or escaped.
  • Prefer the built-in PromptTemplate for simple cases; the custom builder adds no overhead when sections are unconditional.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.