ReAct and Agents in AI

In the previous post, we looked at the use of Chain of Thought (CoT) reasoning in the context of LLMs. For an LLM to take action in the world, however, it needs agents. The paradigm for this is called ReAct—that is, REason and ACT.

In order to interact with the world, the agent will use tools (such as code that accesses APIs, searches the Internet, etc.). This creates a dynamic cycle:

Think—the LLM reasons and decides what tool to use
ACT—the LLM uses the tool to take action in the world
Observe—the LLM observes the result of the action and adjusts accordingly, refining its plan

The cycle ends when the LLM has its final answer.

Prompts for ReAct

The prompt must specify the available tools and their descriptions. It will instruct the LLM to use the cycle above and provide examples of the cycle. Finally, it will constrain the output into a machine-readable format.

The prompt must be very clear and precise. The basic template is to tell the agent what it is (“you are a medical assistant”), what tools it has access to, how to use the tool, what the returned observation will look like (structured data such as JSON) and how to provide the interim and final answers.

The output after each tool use is machine-readable so that it can be fed back into the cycle or to a tool or internal prompt.

With CoT (Chain of Thought), the LLM was limited to its existing knowledge and could not deviate from its initial planning. With ReAct the LLM can adapt to the observed results and use tools to extend its knowledge. If an error is encountered, the LLM can adjust its plan to avoid the failure (e.g., using a different tool).

We can tell the LLM to output its plan and observations as it goes. This can be enormously helpful for debugging.

When we look at the “think” phase, we return to the use of CoT. It is here that an initial plan is generated and the LLM uses the tools to execute the plan after which the LLM will observe the results and use them to adjust the plan.

Interacting with the tools brings us to the Model Context Protocol (MCP), a topic for an upcoming blog post.

Unknown's avatar

About Jesse Liberty

** Note ** Jesse is currently looking for a new position. You can learn more about him at https://jesseliberty.bio Thank you. Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen online courses. His latest book, Building APIs with .NET, is now available wherever you buy your books. Liberty was a Team Lead and Senior Software Engineer for various corporations, a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a 13 year Microsoft MVP.
This entry was posted in Agents, AI and tagged , . Bookmark the permalink.