ReAct (Reasoning and Acting) is a powerful agent pattern that combines the reasoning capabilities of Large Language Models with the ability to take actions through tools. This approach allows agents to break down complex problems, gather necessary information, and provide accurate responses.
The ReAct pattern follows a cyclical process:
Diagram credit: Scrimba
The process consists of these key steps:
Here's a comprehensive system prompt for implementing a ReAct agent:
You are a helpful assistant that uses the ReAct (Reasoning and Acting) framework to answer questions.
Follow this format for each response:
Thought: [Your reasoning about what you need to do next]
Action: [The tool/function you want to call]
Action Input: [The input for the tool]
Observation: [The result of the tool call]
... (repeat Thought/Action/Observation as needed)
Thought: [I now have enough information to answer]
Final Answer: [Your final response to the user]
Available tools:
- getLocation: Get the user's current location
- getCurrentWeather: Get weather information for a location
- searchWeb: Search the web for information
- calculate: Perform mathematical calculations
Rules:
1. Always start with a Thought
2. Only use the available tools listed above
3. If you don't have enough information after using tools, continue the cycle
4. Provide a Final Answer only when you have sufficient information
5. Be specific and accurate in your responses
Here's how a ReAct agent handles a user query:
Diagram credit: Scrimba
Example Interaction:
User: "What should I do tonight for fun?"
Agent Response:
Thought: The user wants suggestions for fun activities tonight. To provide good recommendations, I should know their location and current weather conditions, as these factors affect what activities are suitable.
Action: getLocation
Action Input: {}
Observation: New York City, NY
Thought: Now I have the user's location. I should check the current weather to suggest appropriate activities for tonight.
Action: getCurrentWeather
Action Input: {"location": "New York City, NY"}
Observation: Temperature: 72°F, Clear skies, Low humidity
Thought: Perfect! I have the location (New York City) and weather information (clear, pleasant weather). Now I can suggest appropriate fun activities for tonight.
Final Answer: Based on your location in New York City and the clear, pleasant weather (72°F), here are some great options for tonight:
1. **Outdoor Activities**: Take a walk in Central Park, visit a rooftop bar with city views, or enjoy outdoor dining
2. **Entertainment**: Catch a Broadway show, visit a comedy club, or explore the nightlife in areas like Greenwich Village
3. **Cultural**: Visit museums that have evening hours, attend a live music venue, or explore art galleries
4. **Social**: Meet friends at a local restaurant, join a trivia night at a bar, or attend a community event
The clear weather makes outdoor activities particularly appealing tonight. What type of experience are you most interested in?
When building ReAct agents, consider:
ReAct agents represent a significant advancement in AI capabilities, enabling more sophisticated and helpful interactions that go beyond simple question-answering.
Overview
AI agents are autonomous systems that can perceive their environment, make decisions, and take actions to achieve specific goals. This section covers various agent architectures and patterns.
RAG
comprehensive guide to Retrieval-Augmented Generation (RAG), covering Vector Databases, Semantic Search, Embeddings, Chunking strategies, and the RAG workflow.