Reasoning
Learn how to enable and use agent reasoning to improve task execution.
Overview
Agent reasoning is a feature that allows agents to reflect on a task and create a plan before execution. This helps agents approach tasks more methodically and ensures they’re ready to perform the assigned work.
Usage
To enable reasoning for an agent, simply set reasoning=True
when creating the agent:
How It Works
When reasoning is enabled, before executing a task, the agent will:
- Reflect on the task and create a detailed plan
- Evaluate whether it’s ready to execute the task
- Refine the plan as necessary until it’s ready or max_reasoning_attempts is reached
- Inject the reasoning plan into the task description before execution
This process helps the agent break down complex tasks into manageable steps and identify potential challenges before starting.
Configuration Options
Enable or disable reasoning
Maximum number of attempts to refine the plan before proceeding with execution. If None (default), the agent will continue refining until it’s ready.
Example
Here’s a complete example:
Error Handling
The reasoning process is designed to be robust, with error handling built in. If an error occurs during reasoning, the agent will proceed with executing the task without the reasoning plan. This ensures that tasks can still be executed even if the reasoning process fails.
Here’s how to handle potential errors in your code:
Example Reasoning Output
Here’s an example of what a reasoning plan might look like for a data analysis task:
This reasoning plan helps the agent organize its approach to the task, consider potential challenges, and ensure it delivers the expected output.