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.
In this repository65 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/building-agents/agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- llms-full.txtllms.txt
- llms.txtllms.txt
- adding-guardrailsSkill
- agent-health-timeoutSkill
- agent-permission-scopingSkill
- agent-session-isolationSkill
- agent-step-loggingSkill
- agent-supervisor-routerSkill
- agent-telemetrySkill
- async-agent-backgroundSkill
- building-agentsSkill
- building-teamsSkill
- building-toolsSkill
- calendar-scheduling-toolSkill
- callback-tracing-handlerSkill
- chain-of-thought-promptingSkill
- chat-model-configurationSkill
- code-execution-sandboxSkill
- common-agent-patternsSkill
- context-window-managementSkill
- conversation-memorySkill
- conversation-state-dbSkill
- database-query-toolSkill
- document-loadersSkill
- document-rerankingSkill
- email-notification-toolSkill
- embedding-model-ingestionSkill
- fallback-model-chainSkill
- few-shot-injectionSkill
- filesystem-toolSkill
- human-in-the-loopSkill
- hybrid-searchSkill
- inspecting-streamsSkill
- integrating-with-laurenSkill
- json-schema-enforcementSkill
- llm-provider-connectionSkill
- llm-rate-limitingSkill
- long-term-vector-memorySkill
- managing-memorySkill
- migrating-to-lauren-aiSkill
- multi-agent-delegationSkill
- multi-tool-orchestrationSkill
- multi-turn-tool-stateSkill
- output-guardrailsSkill
- plan-and-execute-agentSkill
- prompt-injection-defenseSkill
- prompt-versioningSkill
- rag-pipelineSkill
- react-agent-loopSkill
- response-validation-retrySkill
- rest-api-toolSkill
- securing-agentsSkill
- semantic-cacheSkill
- streaming-response-handlerSkill
- structured-output-parsingSkill
- sub-agent-spawningSkill
- testing-agentsSkill
- The first 60 shown.
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
- Very specific: line 26
When you need conditional sections, structured constraints, or a fluent API, implement a SystemPromptBuilder:
- Very specific: line 113
Prefer the built-in PromptTemplate for simple cases.
≈ “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.
Files
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
PromptTemplatefor simple cases; the custom builder adds no overhead when sections are unconditional.
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
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.

