Dynamic system prompt
Self-correcting knowledge corpus for Claude Code — 9 stable shape clusters, bias-correction pipeline baked into contribution flow. 47 papers, 45 techniques, 1.1k skills.
npx -y skills add kjuhwa/skills-hub --skill dynamic-system-promptAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Generate agent instructions dynamically at runtime from a context object.
SKILL.md
2.0 KB, 358 tokens by cl100k_base, as published. Nobody here has run it
dynamic-system-prompt
Pass a callable to Agent.instructions instead of a static string. The callable receives RunContextWrapper[TContext] and the agent, returns a str. This enables per-user or per-request instruction customization.
When to apply
When the agent's system prompt depends on runtime data (user role, session config, locale, A/B flags). Avoids maintaining multiple agent instances for minor prompt variants.
Core snippet
from dataclasses import dataclass
from typing import Literal
from agents import Agent, RunContextWrapper, Runner
@dataclass
class CustomContext:
style: Literal["haiku", "pirate", "robot"]
def custom_instructions(
run_context: RunContextWrapper[CustomContext], agent: Agent[CustomContext]
) -> str:
context = run_context.context
if context.style == "haiku":
return "Only respond in haikus."
elif context.style == "pirate":
return "Respond as a pirate."
else:
return "Respond as a robot and say 'beep boop' a lot."
agent = Agent(
name="Chat agent",
instructions=custom_instructions,
)
async def main():
context = CustomContext(style="pirate")
result = await Runner.run(agent, "Tell me a joke.", context=context)
print(result.final_output)
Key notes
instructionscan be astrorCallable[[RunContextWrapper[T], Agent[T]], str]- The callable may also be async:
async def my_instructions(ctx, agent) -> str: - Context object is typed; use
Agent[CustomContext]for type-checked access