chain-of-thought-prompting
Skill0 starsChanged 6 months agoMITView on GitHub
Elicits step-by-step reasoning from models to improve accuracy on complex tasks. Use when the task involves multi-step logic, math, code analysis, or planning; when zero-shot answers are unreliable; or when you need to extract and inspect the model's reasoning separately from its final answer.
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
- 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
- system-prompt-templatingSkill
- testing-agentsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
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 25
Use XML tags to separate reasoning from the final answer — the model is trained to honor them and extraction is reliable:
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 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.
Chain-of-Thought Prompting Strategy
Zero-shot CoT
Append a simple instruction to trigger step-by-step reasoning:
# NOTE: future annotations are allowed, but tool signature types must resolve at import time.
COT_SUFFIX = "\n\nThink through this step by step before answering."
def add_cot(prompt: str) -> str:
return prompt + COT_SUFFIXStructured CoT with XML tags
Use XML tags to separate reasoning from the final answer — the model is trained to honor them and extraction is reliable:
import re
STRUCTURED_COT_TEMPLATE = """\
Analyze the following problem:
{problem}
Think through it carefully:
1. Understand the problem
2. Identify key facts
3. Apply reasoning
4. Arrive at conclusion
<reasoning>
{reasoning}
</reasoning>
<answer>
{answer}
</answer>"""
def extract_cot_answer(response: str) -> tuple[str, str]:
"""Extract <reasoning> and <answer> blocks from a structured CoT response.
Returns (reasoning, answer). When the tags are absent the full response
is returned as the answer with an empty reasoning string.
"""
reasoning_match = re.search(r'<reasoning>(.*?)</reasoning>', response, re.DOTALL)
answer_match = re.search(r'<answer>(.*?)</answer>', response, re.DOTALL)
reasoning = reasoning_match.group(1).strip() if reasoning_match else ""
answer = answer_match.group(1).strip() if answer_match else response.strip()
return reasoning, answerSystem-prompt CoT instruction
Embed the CoT instruction in the agent system prompt so it applies to every turn:
from lauren_ai import agent
COT_SYSTEM = """\
You are a helpful problem-solving assistant.
When answering questions, always reason step by step inside <reasoning> tags,
then give your final answer inside <answer> tags.
Format:
<reasoning>
[your step-by-step reasoning here]
</reasoning>
<answer>
[your final answer here]
</answer>"""
@agent(model="claude-sonnet-4-6", system=COT_SYSTEM)
class ReasoningAgent: ...Few-shot CoT
Provide worked examples where the model shows its reasoning:
FEW_SHOT_COT_SYSTEM = """\
Solve math word problems step by step.
Example:
Q: A store has 24 apples. It sells 8. How many remain?
A: <reasoning>
Start: 24 apples.
Sold: 8 apples.
Remaining: 24 - 8 = 16.
</reasoning>
<answer>16</answer>
Now solve the user's problem in the same format."""Post-processing the response
from lauren_ai import AgentRunnerBase, LLMConfig
from lauren_ai._transport._mock import MockTransport # replace with real transport
async def run_with_cot(problem: str) -> tuple[str, str]:
runner = AgentRunnerBase(transport=transport)
response = await runner.run(ReasoningAgent(), problem)
reasoning, answer = extract_cot_answer(response.content)
return reasoning, answerPitfalls
- Don't truncate the output — CoT responses are longer than direct answers.
Set
max_tokens_per_turnhigh enough (2048+ for complex tasks). - Structured tags require exact matching — instruct the model to use
<reasoning>and<answer>literally; do not vary the tag names per turn. - Zero-shot CoT suffix works best at the end of the user message, not the system prompt.
- For extended thinking (Claude), use the
thinking=Truetransport parameter instead — it is token-free and separated from the visible response.
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.

