Prompt engineering techniques and reasoning patterns

Agent instructions are system prompts which define identity, purpose, goals, behavioral guidelines, tone, style, safety constraints, knowledge, capability boundaries, tool usage rules, output formatting requirements, task prioritization, domain specific knowledge, and reasoning instructions to name most.  This is why we should never overlook the non-code aspect of building AI Agents and AI solutions.  The manner in which we instruction them is the manner in which they will operate.

LLMs are an adolescent by which it can function observably fine, but without guidance and morals, AI Agents which infer reasoning to the LLM are vulnerable to which the LLM is trained.  What I mean by that is, LLMs are trained by literature, text, and content from all forms of knowledge.  Everyone does not agree on the same, so with guidance for the given context the AI Agent my be influenced by ‘knowledge’ that is not most beneficial for the given task.  Therefore, unambiguous and complete instruction must be provided to the AI Agent for the given task, not partly, but completely.

There is plenty of documentation concerning prompt engineering so I will not repeat that here.  Instead, given the importance of system prompts are understood, I’d like to write about reasoning patterns.   Table 1 provides some insights into some more popular reasoning patterns.

Table 1, most common reasoning patterns and descriptions
Reasoning Pattern Type Description
Zero-Shot Single Pass Prompting Ask the model to solve a task without examples
Few-Shot Single Pass Prompting Provide a few examples before asking for a new answer
Chain of Thought (CoT) Single Pass Encourage step-by-step reasoning
Least-to-Most Single Pass Prompting Break a complex problem into simpler subproblems and solve them sequentially
Tree of Thoughts (ToT) Search Explore multiple reasoning branches rather than one linear chain
Graph of Thoughts (GoT) Search Organize reasoning as interconnected nodes rather than a chain or tree
Self-Consistency Search Generate multiple reasoning paths and choose the most consistent answer
ReAct (Reason + Act) Tool Alternate between reasoning and taking actions (such as searching or using tools)
Plan-then-Act Cognitive control Task requires explicit decomposition
Act-then-Reflect Cognitive control Quality improvement on complex outputs
Iterative refinement Cognitive control Uncertain solution space, needs exploration
Chain of Verification (CoVe) Cognitive control Generate an answer, then verify it through explicit checks
Reflection / Self-Reflection Cognitive control Review and critique an initial answer before finalizing it

The following are prompt pattern example which may be helpful for the instructional aspect of the system prompt, recall from the first paragraph that there are many other parts of the prompt.

Zero-Shot

"I have $1,500 to spend on a guitar. Should I buy a Fender Stratocaster, 
Gibson Les Paul, or PRS SE? Recommend one and explain why."

Few-Shot

"Example 1: Player likes blues and versatility → Recommendation: Fender 
Stratocaster. Example 2: Player likes hard rock and thick tones → 
Recommendation: Gibson Les Paul. Example 3: Player wants modern 
versatility and playability → Recommendation: PRS SE. Now: Player 
likes rock, blues, and occasional metal. Which guitar should they choose?"

Chain of Thought (CoT)

CoT → One reasoning path.

"I have $1,500 to spend on a guitar. Compare a Fender Stratocaster, Gibson 
Les Paul, and PRS SE. Think through the decision step by step before 
recommending one."

Least-to-Most

"Determine which guitar I should buy by solving smaller questions in order: 
 1) What genres do I play? 2) What tone do I prefer? 3) Which guitar best 
matches those requirements? Then give a recommendation."

Tree of Thoughts (ToT)

ToT → Multiple alternative branches.

"Explore three possible decision paths: buying a Fender Stratocaster, a 
Gibson Les Paul, or a PRS SE. For each path, evaluate strengths, 
weaknesses, and long-term suitability before choosing the best option."

Graph of Thoughts (GoT)

GoT → Interconnected factors influence each other.

"Analyze the guitar decision as an interconnected graph of factors: genre, 
tone, comfort, weight, versatility, maintenance, resale value, and budget. 
Show how these factors influence one another before recommending a 
guitar."

Self-Consistency

Self-Consistency → Multiple independent analyses, then vote.

"Generate three independent analyses of whether I should buy a Fender 
Stratocaster, Gibson Les Paul, or PRS SE. Compare the conclusions and 
select the recommendation that appears most consistently supported."

ReAct (Reason + Act)

"Help me choose between a Fender Stratocaster, Gibson Les Paul, and 
PRS SE. Reason about what information is needed. If key details are 
missing, identify questions to ask or information to gather. Then provide 
a recommendation."

Plan-then-Act

Plan-then-Act → Plan first, solve second.  You would code this in such a way that 2 inferences are requested from the LLM.  The first prompt might resemble:

I have a $1,500 budget and am considering a Fender Stratocaster, Gibson 
Les Paul, or PRS SE. Your task is ONLY to create a detailed decision-making
plan. Do not recommend a guitar yet.

For each step:
- Define the action to perform.
- Explain why the step is important.

Output strictly as JSON using this schema:
{"steps": [{"step": 1,"action": "...","rationale": "..."}]}

You would pass the output of the first prompt, combined with the second prompt as shown here.

Execute this plan: {json.dumps(plan)}. Provide analysis for each step.

Act-then-Reflect

Act-then-Reflect → Solve first, critique second. You would code this in such a way that 2 inferences are requested from the LLM.  The Act prompt might resemble:

I have a $1,500 budget and am considering a Fender Stratocaster, Gibson
Les Paul, or PRS SE.

Analyze the options and provide a recommendation.

Include:
- A comparison of tone
- Playability and comfort
- Versatility across genres
- Build quality and reliability
- Value for money

Provide a final recommendation and explain why it is the best choice.

Followed by the Reflect prompt:

Review your guitar recommendation.

Check for:

1. Unsupported assumptions about the player's preferences
2. Missing considerations such as comfort, weight, or maintenance
3. Incomplete comparison of tone and versatility
4. Missing discussion of value for money within the $1,500 budget
5. Potential bias toward a brand or guitar style
6. Important use cases or genres that were not considered

For each issue:
- Explain the gap or weakness
- Assess its impact on the recommendation

Then provide a revised recommendation that addresses any identified 
shortcomings.

Iterative refinement

Iterative Refinement → Multiple critique/improvement cycles.  In this example you would want to set values for the maximum number of reflection cycles and confidence thresholds like the following.

MAX_REFLECTION_CYCLES = 3
confidence_threshold = 8

The cycle through the iterative refinement until either the max cycles or confidence threshold is met using a Confidence prompt:

"Rate your confidence in this analysis from 1-10. Provide just the number."

and a Reflection prompt:

"Identify the weakest part of your analysis and strengthen it."

Chain of Verification (CoVe)

CoVe → Explicit verification of assumptions and facts.

"Recommend a guitar. Then list the assumptions behind your 
recommendation, verify each assumption, and update the recommendation 
if any assumption is incorrect."

Reflection / Self-Reflection

Reflection → General self-critique before final answer.

"Recommend the best guitar for me. Before finalizing the answer, review your 
reasoning, identify any biases or missing considerations, and provide an 
improved final recommendation."

Have a look at the code examples here.