← Back to list

The Art of Reasoning with GPTs

Cover of GPT Agents In Action by Micheal Lanham

Micheal Lanham · 2024-05-09 17:48 · 11 claps · 5.6 min read paywalled
#micheal-lanham #agentgpt #gpt-assistant #prompt-engineering #llm-reasoning
Open on Medium ↗
Wiki topics: LLM · Large Language Models AGT · AI Agents

The Art of Reasoning with GPTs

Cover of GPT Agents In Action by Micheal Lanham

Cover of GPT Agents In Action by Micheal Lanham

I am writing my 11th book for Manning Publications, GPT Agents In Action. This book takes a technical and practical focus on building large language model (LLM) assistants and agents, beginning with the basics of building GPT Assistants and then powering up to building agentic systems.

As part of the journey through this book, I guide the reader on the core patterns or components every agent should use. These patterns include memory, knowledge, actions with tools, personas or profiles, evaluation, feedback, planning, and reasoning.

While most assistant and agent platforms now support memory, knowledge, and actions, they fail to encompass more of the powerful patterns. Reasoning is one of the most powerful patterns rarely addressed on these platforms or exposed to the user.

So, what is reasoning and how does it work with assistants and agents powered by LLMs?

Reasoning is providing the ability for your LLM to take a step back and think about the answer it will give. In prompt engineering parlance this is often described as giving the LLM time to think. In fact, you can apply simple reasoning to every prompt you write by just using these simple but effective words:

“Think about your answer.”

Go ahead and try this with any LLM. Try using a simple but common testing prompt (example: write a Flappy Bird clone using Pygame). My previous standard was writing a snake game, which has become ubiquitous now.

write a Flappy Bird clone using Pygame
Think about your answer

By augmenting the prompt with that simple phrase I get the working game shown below about 50% of the time, so it may not always work. But, not using the phrase always results in errors, missed references, etc. You get the idea.

Generated Flappy Bird clone game running

Generated Flappy Bird clone game running

That phrase is an implicit or implied form of reasoning. There are also many other explicit reasoning patterns you can employ. You may have heard of chain of thought, tree of thought, prompt chaining, self-consistency, etc. All of these methods work to a certain degree, but they often require additional prompt preparation and extra effort.

Without worrying too much about those reasoning patterns we can employ simple reasoning augmentation to enhance any prompt or assistant and agent interaction. The figure below shows how a prompt can be augmented by simply applying a reasoning step to augment any prompt.

Understanding how reasoning prompt augmentation can be applied

Understanding how reasoning prompt augmentation can be applied

As an example lets go through step by step and apply this to our sample problem:

The first prompt to submit is:

Generate a chain of thought reasoning strategy to solve the following problem. 
Just output the reasoning steps and avoid coming to any conclusions. 
Also, be sure to avoid any assumptions and factor in potential unknowns.
Problem:
[write a Flappy Bird clone using Pygame]

This will return the chain of thought reasoning strategy to build the game, shown below:

Reasoning steps:
1. Identify the core mechanics of Flappy Bird: the player controls a bird, making it fly upwards each time the player taps the screen, and the bird falls due to gravity when not tapping. The goal is to avoid pipes that come from the right at varying heights, without hitting them or the ground.
2. Set up the Pygame environment: Install Pygame if it's not already installed, initialize Pygame, and create the main display window with a set width and height.
3. Define the game assets: Create or find suitable images for the bird and pipes. Determine if any sound effects or background music are needed and source them.
4. Create the bird object: Define its properties like position, velocity, and gravity effect. Implement the jump function to make the bird "flap" and move upwards.
5. Implement the pipe object: Define the properties of pipes, such as position, speed, and the gap between the top and bottom pipes. The pipes should move from right to left and be generated continuously with random heights.
6. Handle user input: Detect key presses to make the bird jump and to restart the game after losing.
7. Add game logic: Include collision detection to determine when the bird hits a pipe or the ground. Implement a scoring system that increases as the bird passes each set of pipes.
8. Design the game loop: The loop should continuously update the bird's position, generate and update pipes, check for collisions, draw the game assets to the screen, and update the display.
9. Include game states: Manage different game states such as starting, playing, and game over. Display appropriate screens or messages for each state.
10. Test the game: Play the game to check for bugs, fine-tune the difficulty, and ensure the mechanics are smooth and responsive.
11. Optimize and refine: Based on testing, adjust the game's physics, graphics, and sounds. Consider adding additional features like leaderboards, achievements, or visual effects.
12. Plan for potential unknowns: Be prepared to handle unexpected bugs, compatibility issues across different systems, and user feedback that may require changes to the game.

Now we combine that strategy with the original goal prompt and submit again:

Problem:
[write a Flappy Bird clone using Pygame]
Reasoning steps:
1. Identify the core mechanics of Flappy Bird: the player controls a bird, making it fly upwards each time the player taps the screen, and the bird falls due to gravity when not tapping. The goal is to avoid pipes that come from the right at varying heights, without hitting them or the ground.
2. Set up the Pygame environment: Install Pygame if it's not already installed, initialize Pygame, and create the main display window with a set width and height.
3. Define the game assets: Create or find suitable images for the bird and pipes. Determine if any sound effects or background music are needed and source them.
4. Create the bird object: Define its properties like position, velocity, and gravity effect. Implement the jump function to make the bird "flap" and move upwards.
5. Implement the pipe object: Define the properties of pipes, such as position, speed, and the gap between the top and bottom pipes. The pipes should move from right to left and be generated continuously with random heights.
6. Handle user input: Detect key presses to make the bird jump and to restart the game after losing.
7. Add game logic: Include collision detection to determine when the bird hits a pipe or the ground. Implement a scoring system that increases as the bird passes each set of pipes.
8. Design the game loop: The loop should continuously update the bird's position, generate and update pipes, check for collisions, draw the game assets to the screen, and update the display.
9. Include game states: Manage different game states such as starting, playing, and game over. Display appropriate screens or messages for each state.
10. Test the game: Play the game to check for bugs, fine-tune the difficulty, and ensure the mechanics are smooth and responsive.
11. Optimize and refine: Based on testing, adjust the game's physics, graphics, and sounds. Consider adding additional features like leaderboards, achievements, or visual effects.
12. Plan for potential unknowns: Be prepared to handle unexpected bugs, compatibility issues across different systems, and user feedback that may require changes to the game.

Now, 100% of the time, I will get a working game. However, the game may have other issues resolved by being more specific in the reasoning step. This technique may also shift the effectiveness of your LLM and typically works well on open-source models.

For agents and assistants, this form of reasoning can become an automatic augmentation applied to any problem. However, reasoning can also be specific to types of agents or tasks, which is why I address it as an agent component.

In GPT Agents, I demonstrate how reasoning is applied to agentic systems to tackle various problems. For now, though, I hope I have provided you with a new technique to improve your appreciation for the power of LLMs and agents.

Happy reasoning…


메타데이터
post_id
ffdddf2d22c2
slug
the-art-of-reasoning-with-gpts-ffdddf2d22c2
url
https://medium.com/@Micheal-Lanham/the-art-of-reasoning-with-gpts-ffdddf2d22c2
canonical_url
https://medium.com/@Micheal-Lanham/the-art-of-reasoning-with-gpts-ffdddf2d22c2
author_url
https://medium.com/@Micheal-Lanham
status
ok
fetched_at
2026-07-27 00:54:22