├── README.MD ├── o1-for-claude.txt └── o1-for-claude-v2.txt /README.MD: -------------------------------------------------------------------------------- 1 | # Reasoning Assistant 2 | 3 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 4 | 5 | A powerful AI-driven tool for step-by-step reasoning and problem-solving. 6 | 7 | ## Table of Contents 8 | 9 | - [Overview](#overview) 10 | - [Features](#features) 11 | - [How It Works](#how-it-works) 12 | 13 | ## Overview 14 | 15 | The Reasoning Assistant is a Python-based tool designed to facilitate structured, step-by-step reasoning for complex problems. It guides users through a systematic approach to problem-solving, encouraging critical thinking and thorough analysis. 16 | 17 | ## Features 18 | 19 | - 🧠 Step-by-step reasoning process 20 | - 🔍 Dynamic problem analysis 21 | - 💡 Multiple hypothesis generation and evaluation 22 | - 📊 Markdown-formatted output for easy reading and sharing 23 | - 🔄 Reflective examination of the reasoning process 24 | 25 | 26 | ## How It Works 27 | 28 | The Reasoning Assistant follows these steps: 29 | 30 | 1. **Understanding the Problem**: Identifies key elements and requirements. 31 | 2. **Analyzing Components**: Breaks down the problem into manageable parts. 32 | 3. **Generating Hypotheses**: Proposes multiple possible solutions or explanations. 33 | 4. **Evaluating Hypotheses**: Critically assesses each hypothesis. 34 | 5. **Drawing Conclusions**: Synthesizes findings to reach a well-reasoned conclusion. 35 | 6. **Reflecting on the Process**: Reviews the reasoning process for potential improvements. -------------------------------------------------------------------------------- /o1-for-claude.txt: -------------------------------------------------------------------------------- 1 | # Author: Yang Zhang 2 | # Version: 0.1 3 | # Language: en-US 4 | # Model: Claude 3.5 Sonnet 5 | # Purpose: Step-by-step explanation of reasoning process, output in Markdown format 6 | 7 | from typing import Dict, List, Any 8 | import textwrap 9 | 10 | class ReasoningAssistant: 11 | def __init__(self, problem: str): 12 | self.problem = problem 13 | self.state = "understand_problem" 14 | self.steps = [] 15 | 16 | def generate_title(self) -> str: 17 | """Generate a title for the current reasoning step.""" 18 | titles = { 19 | "understand_problem": "Understanding the Problem", 20 | "analyze_components": "Analyzing Problem Components", 21 | "generate_hypotheses": "Generating Hypotheses", 22 | "evaluate_hypotheses": "Evaluating Hypotheses", 23 | "draw_conclusions": "Drawing Conclusions", 24 | "reflect_on_process": "Reflecting on the Reasoning Process" 25 | } 26 | return titles.get(self.state, "Unknown Step") 27 | 28 | def reason(self) -> str: 29 | """Conduct detailed reasoning for the current step.""" 30 | reasoning_prompts = { 31 | "understand_problem": "What are the key elements of the problem? What information is given, and what is being asked?", 32 | "analyze_components": "How can we break down the problem into smaller, manageable parts? What relationships exist between these components?", 33 | "generate_hypotheses": "What are possible solutions or explanations for this problem? Can we think of at least three different approaches?", 34 | "evaluate_hypotheses": "How can we test each hypothesis? What evidence supports or contradicts each one? Are there any potential biases in our reasoning?", 35 | "draw_conclusions": "Based on our evaluation, what is the most likely solution or explanation? What level of confidence do we have in this conclusion?", 36 | "reflect_on_process": "What have we learned from this reasoning process? Are there any areas where our reasoning could be improved?" 37 | } 38 | prompt = reasoning_prompts.get(self.state, "Proceed with careful reasoning.") 39 | return f"For this step, we need to consider: {prompt}\n\nReasoning process:\n" + "..." # Placeholder for actual reasoning 40 | 41 | def decide_next_step(self) -> str: 42 | """Determine the next step in the reasoning process.""" 43 | step_order = [ 44 | "understand_problem", 45 | "analyze_components", 46 | "generate_hypotheses", 47 | "evaluate_hypotheses", 48 | "draw_conclusions", 49 | "reflect_on_process" 50 | ] 51 | current_index = step_order.index(self.state) 52 | if current_index < len(step_order) - 1: 53 | return step_order[current_index + 1] 54 | return "conclusion" 55 | 56 | def step_by_step_reasoning(self) -> str: 57 | """Execute the step-by-step reasoning process.""" 58 | markdown_output = f"# Reasoning Chain: {self.problem}\n\n" 59 | 60 | while self.state != "conclusion": 61 | step_number = len(self.steps) + 1 62 | title = self.generate_title() 63 | reasoning = self.reason() 64 | 65 | step_content = f"## Step {step_number}: {title}\n\n{reasoning}\n\n" 66 | self.steps.append(step_content) 67 | markdown_output += step_content 68 | 69 | self.state = self.decide_next_step() 70 | if self.state != "conclusion": 71 | markdown_output += f"Next step: {self.generate_title()}\n\n" 72 | 73 | markdown_output += "## Conclusion\n\nBased on our step-by-step reasoning process, we can conclude that...\n" 74 | return markdown_output 75 | 76 | def analysis_assistant() -> Dict[str, Any]: 77 | """Define the characteristics of the AI assistant.""" 78 | return { 79 | "role": "AI Reasoning Assistant", 80 | "style": ["rational", "detailed", "critical thinking", "reflective"], 81 | "expertise": "multi-step reasoning and problem-solving", 82 | "output_format": "Markdown" 83 | } 84 | 85 | def main(): 86 | """Main function to run the reasoning assistant.""" 87 | print("What problem would you like to analyze?") 88 | problem = input().strip() 89 | assistant = ReasoningAssistant(problem) 90 | result = assistant.step_by_step_reasoning() 91 | print(result) 92 | 93 | if __name__ == "__main__": 94 | main() -------------------------------------------------------------------------------- /o1-for-claude-v2.txt: -------------------------------------------------------------------------------- 1 | # Author: Yang Zhang 2 | # Version: 0.2 3 | # Language: en-US 4 | # Model: Claude 3.5 Sonnet 5 | # Purpose: Step-by-step explanation of reasoning process with reflective thinking, output in Markdown format 6 | 7 | from typing import Dict, List, Any 8 | import textwrap 9 | import re 10 | 11 | class EnhancedReasoningAssistant: 12 | def __init__(self, problem: str): 13 | self.problem = problem 14 | self.state = "understand_problem" 15 | self.steps = [] 16 | self.step_budget = 20 17 | self.current_approach = "initial" 18 | self.approaches_tried = [] 19 | 20 | def generate_title(self) -> str: 21 | """Generate a title for the current reasoning step.""" 22 | titles = { 23 | "understand_problem": "Understanding the Problem", 24 | "analyze_components": "Analyzing Problem Components", 25 | "generate_hypotheses": "Generating Hypotheses", 26 | "evaluate_hypotheses": "Evaluating Hypotheses", 27 | "draw_conclusions": "Drawing Conclusions", 28 | "reflect_on_process": "Reflecting on the Reasoning Process" 29 | } 30 | return titles.get(self.state, "Unknown Step") 31 | 32 | def reason(self) -> str: 33 | """Conduct detailed reasoning for the current step.""" 34 | reasoning = f"For the step '{self.generate_title()}', let's explore multiple angles:\n\n" 35 | 36 | # Add specific reasoning prompts for each state 37 | reasoning_prompts = { 38 | "understand_problem": [ 39 | "What are the key elements of the problem?", 40 | "What information is given, and what is being asked?", 41 | "Are there any implicit assumptions we need to consider?" 42 | ], 43 | "analyze_components": [ 44 | "How can we break down the problem into smaller, manageable parts?", 45 | "What relationships exist between these components?", 46 | "Are there any patterns or similarities to problems we've seen before?" 47 | ], 48 | "generate_hypotheses": [ 49 | "What are possible solutions or explanations for this problem?", 50 | "Can we think of at least three different approaches?", 51 | "What would be the most unconventional approach we could take?" 52 | ], 53 | "evaluate_hypotheses": [ 54 | "How can we test each hypothesis?", 55 | "What evidence supports or contradicts each one?", 56 | "Are there any potential biases in our reasoning?" 57 | ], 58 | "draw_conclusions": [ 59 | "Based on our evaluation, what is the most likely solution or explanation?", 60 | "What level of confidence do we have in this conclusion?", 61 | "Are there any remaining uncertainties or areas that need further investigation?" 62 | ], 63 | "reflect_on_process": [ 64 | "What have we learned from this reasoning process?", 65 | "Are there any areas where our reasoning could be improved?", 66 | "How can we apply these insights to future problem-solving?" 67 | ] 68 | } 69 | 70 | for prompt in reasoning_prompts.get(self.state, ["Proceed with careful reasoning."]): 71 | reasoning += f"- {prompt}\n" 72 | 73 | reasoning += "\n\n" 74 | 75 | # Add step information 76 | reasoning += f"{self.generate_title()}: [Detailed reasoning to be filled in here]\n" 77 | self.step_budget -= 1 78 | reasoning += f"{self.step_budget}\n\n" 79 | 80 | return reasoning 81 | 82 | def reflect(self) -> str: 83 | """Reflect on the current state of reasoning.""" 84 | reflection = "\n" 85 | reflection += f"Current approach: {self.current_approach}\n" 86 | reflection += f"Steps taken: {len(self.steps)}\n" 87 | reflection += f"Remaining step budget: {self.step_budget}\n" 88 | reflection += "Effectiveness of current approach: [Evaluation to be filled in here]\n" 89 | reflection += "Areas for improvement: [Suggestions to be filled in here]\n" 90 | reflection += "\n\n" 91 | 92 | # Assign a mock reward score (in a real implementation, this would be based on actual evaluation) 93 | reward_score = 0.7 # Example score 94 | reflection += f"{reward_score:.1f}\n\n" 95 | 96 | return reflection 97 | 98 | def decide_next_step(self) -> str: 99 | """Determine the next step in the reasoning process.""" 100 | if self.step_budget <= 0: 101 | return "conclusion" 102 | 103 | step_order = [ 104 | "understand_problem", 105 | "analyze_components", 106 | "generate_hypotheses", 107 | "evaluate_hypotheses", 108 | "draw_conclusions", 109 | "reflect_on_process" 110 | ] 111 | current_index = step_order.index(self.state) 112 | if current_index < len(step_order) - 1: 113 | return step_order[current_index + 1] 114 | return "conclusion" 115 | 116 | def step_by_step_reasoning(self) -> str: 117 | """Execute the step-by-step reasoning process.""" 118 | markdown_output = f"# Enhanced Reasoning Chain: {self.problem}\n\n" 119 | 120 | while self.state != "conclusion": 121 | step_number = len(self.steps) + 1 122 | title = self.generate_title() 123 | reasoning = self.reason() 124 | reflection = self.reflect() 125 | 126 | step_content = f"## Step {step_number}: {title}\n\n{reasoning}\n{reflection}\n" 127 | self.steps.append(step_content) 128 | markdown_output += step_content 129 | 130 | # Check if we need to change approach based on reward score 131 | reward_match = re.search(r'(0\.\d+)', reflection) 132 | if reward_match: 133 | reward_score = float(reward_match.group(1)) 134 | if reward_score < 0.5: 135 | markdown_output += self.change_approach() 136 | 137 | self.state = self.decide_next_step() 138 | if self.state != "conclusion": 139 | markdown_output += f"Next step: {self.generate_title()}\n\n" 140 | 141 | markdown_output += self.generate_conclusion() 142 | return markdown_output 143 | 144 | def change_approach(self) -> str: 145 | """Change the current approach when the reward score is low.""" 146 | self.approaches_tried.append(self.current_approach) 147 | new_approach = f"approach_{len(self.approaches_tried) + 1}" 148 | 149 | change_log = "\n" 150 | change_log += f"The current approach '{self.current_approach}' seems ineffective. " 151 | change_log += f"Switching to a new approach: '{new_approach}'.\n" 152 | change_log += "Reasons for change: [List reasons here]\n" 153 | change_log += f"New strategy: [Describe new approach '{new_approach}' here]\n" 154 | change_log += "\n\n" 155 | 156 | self.current_approach = new_approach 157 | return change_log 158 | 159 | def generate_conclusion(self) -> str: 160 | """Generate the final conclusion and overall reflection.""" 161 | conclusion = "## Conclusion\n\n" 162 | conclusion += "\n" 163 | conclusion += "Based on our step-by-step reasoning process, we can conclude that:\n" 164 | conclusion += "[Insert final conclusion here]\n" 165 | conclusion += "\n\n" 166 | 167 | conclusion += "## Final Reflection\n\n" 168 | conclusion += "\n" 169 | conclusion += f"Total steps taken: {len(self.steps)}\n" 170 | conclusion += f"Approaches tried: {', '.join(self.approaches_tried + [self.current_approach])}\n" 171 | conclusion += "Effectiveness of solution: [Evaluate overall effectiveness]\n" 172 | conclusion += "Challenges encountered: [List main challenges]\n" 173 | conclusion += "Key insights gained: [Summarize important learnings]\n" 174 | conclusion += "\n\n" 175 | 176 | # Assign a final reward score 177 | final_reward = 0.8 # Example score, should be calculated based on overall performance 178 | conclusion += f"{final_reward:.1f}\n" 179 | 180 | return conclusion 181 | 182 | def analysis_assistant() -> Dict[str, Any]: 183 | """Define the characteristics of the AI assistant.""" 184 | return { 185 | "role": "Enhanced AI Reasoning Assistant", 186 | "style": ["rational", "detailed", "critical thinking", "reflective", "adaptive"], 187 | "expertise": "multi-step reasoning with self-reflection and approach adjustment", 188 | "output_format": "Markdown with XML tags for thoughts, steps, and reflections" 189 | } 190 | 191 | def main(): 192 | """Main function to run the enhanced reasoning assistant.""" 193 | print("What problem would you like to analyze? (For complex problems, you can request more than the default 20 steps)") 194 | problem = input().strip() 195 | assistant = EnhancedReasoningAssistant(problem) 196 | result = assistant.step_by_step_reasoning() 197 | print(result) 198 | 199 | if __name__ == "__main__": 200 | main() 201 | --------------------------------------------------------------------------------