Improved Zero-Shot Reasoning - Implementation of Plan-and-Solve paper
Project description
Plan-and-Solve
Improved Zero-Shot Reasoning via Planning
Architecture • Installation • Quick Start • API Reference
A Python implementation of Plan-and-Solve, a framework that improves zero-shot reasoning by explicitly generating plans before solving problems.
Architecture
Plan-and-Solve Architecture
│
├── PlanAndSolveAgent (Main Agent)
│ ├── Orchestrates planning and solving
│ ├── Handles iterative refinement
│ └── Manages self-checking
│
├── Planner (Plan Generator)
│ ├── Creates step-by-step plans
│ ├── Refines plans on failure
│ └── Manages plan dependencies
│
├── Solver (Plan Executor)
│ ├── Executes plan steps
│ ├── Tracks intermediate results
│ └── Builds final solution
│
└── SelfChecker (Solution Validator)
├── Validates solutions
├── Identifies issues
└── Suggests improvements
Core Workflow
┌─────────────────────────────────────────────────────────────────┐
│ Plan-and-Solve Workflow │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Problem ──▶ Plan ──▶ Execute ──▶ Check ──▶ Solution │
│ │ │ │ │
│ │ │ └── Failed? │
│ │ │ │ │
│ │ └──────────────────┘ │
│ │ (Refine) │
│ │ │
│ └───────────────────────────────────────────── │
│ (Iterate until success) │
│ │
└─────────────────────────────────────────────────────────────────┘
Installation
pip install plan-and-solve
Quick Start
from plansolve import PlanAndSolveAgent
# Define planning function (typically uses an LLM)
def plan_fn(problem: str) -> list:
# Generate step-by-step plan
# response = llm.generate(f"Plan how to solve: {problem}")
return [
"Understand the problem",
"Identify key components",
"Develop solution approach",
"Execute the solution",
"Verify the result"
]
# Define solving function
def solve_fn(step: str, context: dict) -> str:
# Execute step with context from previous steps
# response = llm.generate(f"Execute: {step}\nContext: {context}")
return f"Result of: {step}"
# Create and run agent
agent = PlanAndSolveAgent(plan_fn=plan_fn, solve_fn=solve_fn)
result = agent.solve("Calculate 15 * 17 using mental math")
print(f"Success: {result.success}")
print(f"Answer: {result.answer}")
print(f"Plan steps: {len(result.plan.steps)}")
Key Components
Planner
Generates step-by-step plans for solving problems. Can be customized with domain-specific planning logic.
Solver
Executes plans step by step, maintaining context and building the solution incrementally.
SelfChecker
Validates solutions and identifies issues, enabling iterative refinement.
CLI Usage
# Run a single problem
ps-agent run "What is 15 * 17?"
# Interactive mode
ps-agent interactive
# Export result
ps-agent run "Problem" --export result.json
API Reference
PlanAndSolveAgent
| Method | Description |
|---|---|
solve(problem) |
Solve a problem with planning |
quick_solve(problem) |
Quick solve returning just answer |
| Parameter | Description |
|---|---|
plan_fn |
Function to generate plans |
solve_fn |
Function to execute steps |
check_fn |
Function to validate solutions |
max_iterations |
Maximum refinement iterations |
Academic Reference
Implementation of the Plan-and-Solve paper:
Plan-and-Solve Prompting: Improving Zero-Shot Reasoning by Large Language Models
Lei Wang, Wanyu Xu, Yihuai Lan, Zhiqiang Hu, Yunshi Lan, Roy Ka-Wei Lee, Lidong Bing
ACL 2023
@inproceedings{wang2023plan,
title={Plan-and-Solve Prompting: Improving Zero-Shot Reasoning by Large Language Models},
author={Wang, Lei and Xu, Wanyu and Lan, Yihuai and Hu, Zhiqiang and Lan, Yunshi and Lee, Roy Ka-Wei and Bing, Lidong},
booktitle={Proceedings of the Annual Meeting of the Association for Computational Linguistics (ACL)},
year={2023}
}
License
MIT License
Made with ❤️ by AI Agent Research Team
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file plan_and_solve-0.1.0.tar.gz.
File metadata
- Download URL: plan_and_solve-0.1.0.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a160dc9a00d62cc2ddbb3f5b64540cc540e2e26c5a3fefbc80cae9eeda63fd5b
|
|
| MD5 |
fc9ff898d3de6d33472826cdcedc6fd1
|
|
| BLAKE2b-256 |
91a34e1d75a80bffd4e4659d0ec445ecf7d07cb8906dd93251905fcbf73087fc
|
File details
Details for the file plan_and_solve-0.1.0-py3-none-any.whl.
File metadata
- Download URL: plan_and_solve-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e74d9ed1630dc1fc80e84856a78df672b859c20c4bf1bbf09b683bcf981b886a
|
|
| MD5 |
512002bbf22bbcd174a54cf2ead555c8
|
|
| BLAKE2b-256 |
6dcd96eeed254615c529c08e5d0789d83bd82798a7a103ad0022f8b8ed507fce
|