few-shot-injection
Skill0 starsChanged 6 months agoMITView on GitHub
Injects labeled input/output examples into system prompts or message history to steer model behavior with in-context learning. Use when the task has a consistent input/output format, when zero-shot instructions are insufficient, or when you need dynamic example selection per request.
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
- 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
- system-prompt-templatingSkill
- testing-agentsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
Use them for static example sets baked into the prompt:
- Distinctive: line 34
When you need to choose examples dynamically or format them as message history:
- Distinctive: line 114
Keep examples concise — long examples consume tokens that could be used for the actual response.
≈ “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.
Few-Shot Example Injection
Built-in support: FewShotPromptTemplate
Lauren-AI ships FewShotPromptTemplate and FewShotExample in lauren_ai._prompts.
Use them for static example sets baked into the prompt:
# NOTE: future annotations are allowed, but tool signature types must resolve at import time.
from lauren_ai import FewShotPromptTemplate, FewShotExample
tpl = FewShotPromptTemplate(
prefix="Classify sentiment:\n",
examples=[
FewShotExample(input="Great product!", output="positive"),
FewShotExample(input="Terrible experience.", output="negative"),
],
example_template="{input} -> {output}",
suffix="Input: {review}\nSentiment:",
input_variables=["review"],
)
msg = tpl.render(review="Pretty good overall.")Custom builder for more control
When you need to choose examples dynamically or format them as message history:
from dataclasses import dataclass
@dataclass
class FewShotExample:
input: str
output: str
class FewShotPromptBuilder:
def __init__(self, task_description: str, examples: list[FewShotExample]):
self._task = task_description
self._examples = examples
def build_system_prompt(self) -> str:
lines = [self._task, "", "Examples:"]
for i, ex in enumerate(self._examples, 1):
lines.append(f"\nExample {i}:")
lines.append(f"Input: {ex.input}")
lines.append(f"Output: {ex.output}")
lines.append("\nNow answer the user's input in the same format.")
return "\n".join(lines)
def build_messages(self) -> list[dict]:
"""Inject examples as alternating user/assistant message history."""
messages = []
for ex in self._examples:
messages.append({"role": "user", "content": ex.input})
messages.append({"role": "assistant", "content": ex.output})
return messagesSystem-prompt injection
builder = FewShotPromptBuilder(
task_description="You are a sentiment classifier. Reply with 'positive' or 'negative'.",
examples=[
FewShotExample("I love this!", "positive"),
FewShotExample("This is awful.", "negative"),
],
)
system = builder.build_system_prompt()
from lauren_ai import agent
@agent(model="claude-haiku-4-5", system=system)
class SentimentAgent: ...Message-history injection
Injecting as message pairs is preferred when:
- The task benefits from seeing the model's "prior" responses.
- The examples are long enough that a system prompt becomes unwieldy.
from lauren_ai import Message
example_messages = builder.build_messages()
# Prepend to actual conversation:
# [*example_messages, {"role": "user", "content": actual_query}]Dynamic example selection
Select examples nearest to the current query (BM25, cosine similarity, etc.):
def select_examples(query: str, pool: list[FewShotExample], k: int = 3) -> list[FewShotExample]:
"""Simple keyword-overlap selector — replace with embedding similarity for production."""
scored = [(sum(w in ex.input.lower() for w in query.lower().split()), ex) for ex in pool]
scored.sort(key=lambda x: x[0], reverse=True)
return [ex for _, ex in scored[:k]]Pitfalls
- Keep examples concise — long examples consume tokens that could be used for the actual response.
- Maintain consistent formatting between examples and the suffix/instruction; mismatches confuse the model.
- For classification tasks, balance positive and negative examples to avoid bias.
- The built-in
FewShotPromptTemplate.render(extra_examples=[...])supports dynamic augmentation on top of the staticexampleslist.
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.

