agentleFS
lauren-frameworklauren-framework/lauren-ai/skills/chain-of-thought-prompting/SKILL.md

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.

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
  1. Distinctive:

    Use XML tags to separate reasoning from the final answer — the model is trained to honor them and extraction is reliable:

    line 25

≈ “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.

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.

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_SUFFIX

Structured 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, answer

System-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, answer

Pitfalls

  • Don't truncate the output — CoT responses are longer than direct answers. Set max_tokens_per_turn high 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=True transport parameter instead — it is token-free and separated from the visible response.

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.