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
Metadata
Release files for plan-and-solve 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| plan_and_solve-0.1.0.tar.gz | 13.8 kB | Without provenance | Details for plan_and_solve-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| plan_and_solve-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for plan_and_solve-0.1.0-py3-none-any.whl |
Total release size: 28.7 kB
Release files / plan_and_solve-0.1.0.tar.gz
| Download URL | plan_and_solve-0.1.0.tar.gz |
|---|---|
| Size | 13.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a160dc9a00d62cc2ddbb3f5b64540cc540e2e26c5a3fefbc80cae9eeda63fd5b
|
|
BLAKE2b-256 checksum How to use checksums |
91a34e1d75a80bffd4e4659d0ec445ecf7d07cb8906dd93251905fcbf73087fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / plan_and_solve-0.1.0-py3-none-any.whl
| Download URL | plan_and_solve-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e74d9ed1630dc1fc80e84856a78df672b859c20c4bf1bbf09b683bcf981b886a
|
|
BLAKE2b-256 checksum How to use checksums |
6dcd96eeed254615c529c08e5d0789d83bd82798a7a103ad0022f8b8ed507fce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Security for plan-and-solve 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.