1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
"""Advanced reasoning and planning skill for Agentux.
"""
from __future__ import annotations
import json
import re
from typing import Any, Dict, List, Optional
from .base import BaseSkill
class ReasoningSkill(BaseSkill):
"""Enhances the agent's reasoning and planning capabilities.
This skill provides advanced reasoning patterns, task decomposition,
and strategic thinking capabilities that enable the agent to tackle
complex, multi-step problems like Claude Code.
"""
def __init__(self, agent: Agent, config: Optional[Dict[str, Any]] = None):
super().__init__(agent, config)
self.reasoning_patterns = {
"task_decomposition": self._decompose_task,
"step_by_step_planning": self._create_step_by_step_plan,
"hierarchical_planning": self._create_hierarchical_plan,
"reflection": self._reflect_on_progress,
"problem_solving": self._apply_problem_solving_framework
}
async def initialize(self) -> None:
"""Initialize the reasoning skill."""
# No async initialization needed for this skill
pass
async def execute(self, operation: str, **kwargs) -> Any:
"""Execute a reasoning operation.
Args:
operation: The reasoning operation to perform
**kwargs: Additional arguments for the operation
Returns:
The result of the reasoning operation
"""
if operation not in self.reasoning_patterns:
raise ValueError(f"Unknown reasoning operation: {operation}")
return await self.reasoning_patterns[operation](**kwargs)
async def _decompose_task(self, task_description: str,
max_subtasks: int = 5) -> List[Dict[str, Any]]:
"""Break down a complex task into smaller, manageable subtasks.
Args:
task_description: Description of the task to decompose
max_subtasks: Maximum number of subtasks to create
Returns:
List of subtask dictionaries with descriptions and estimated complexity
"""
# Use the agent's own capabilities to decompose the task
prompt = f"""Break down the following task into {max_subtasks} or fewer smaller, manageable subtasks.
For each subtask, provide:
1. A clear description
2. Estimated complexity (simple, medium, complex)
3. Any dependencies on other subtasks
Task: {task_description}
Format your response as a JSON array of objects, where each object has:
- "description": string describing the subtask
- "complexity": "simple", "medium", or "complex"
- "dependencies": array of integers indicating which other subtasks this depends on (by index)
Example: [{{"description": "Set up development environment", "complexity": "simple", "dependencies": []}}]
Only return the JSON array, nothing else."""
# This would normally call the agent's provider, but for now we'll return a structured approach
# In a full implementation, this would use self.agent.run() or similar
# For demonstration, return a generic decomposition
return [
{
"description": f"Analyze and understand: {task_description}",
"complexity": "simple",
"dependencies": []
},
{
"description": f"Plan approach for: {task_description}",
"complexity": "medium",
"dependencies": [0]
},
{
"description": f"Execute solution for: {task_description}",
"complexity": "complex",
"dependencies": [1]
},
{
"description": f"Verify and test results for: {task_description}",
"complexity": "medium",
"dependencies": [2]
},
{
"description": f"Document and finalize: {task_description}",
"complexity": "simple",
"dependencies": [3]
}
][:max_subtasks]
async def _create_step_by_step_plan(self, goal: str,
constraints: Optional[List[str]] = None) -> Dict[str, Any]:
"""Create a detailed step-by-step plan to achieve a goal.
Args:
goal: The goal to achieve
constraints: Any constraints or limitations
Returns:
A structured plan with steps, estimated time, and resources needed
"""
constraints = constraints or []
# In a full implementation, this would use the agent's reasoning capabilities
# For now, return a structured template
return {
"goal": goal,
"constraints": constraints,
"steps": [
{
"step": 1,
"description": "Understand the requirements and gather information",
"estimated_time": "5-15 minutes",
"tools_needed": ["search", "filesystem"]
},
{
"step": 2,
"description": "Design the solution approach",
"estimated_time": "10-30 minutes",
"tools_needed": ["think", "todo"]
},
{
"step": 3,
"description": "Implement the solution",
"estimated_time": "30-120 minutes",
"tools_needed": ["filesystem", "shell", "git"]
},
{
"step": 4,
"description": "Test and validate the solution",
"estimated_time": "15-30 minutes",
"tools_needed": ["shell", "filesystem"]
},
{
"step": 5,
"description": "Document and cleanup",
"estimated_time": "5-15 minutes",
"tools_needed": ["filesystem"]
}
],
"estimated_total_time": "65-210 minutes",
"success_criteria": [
"The goal stated in the request has been achieved",
"Any tests or validation checks pass",
"The solution follows best practices and conventions"
]
}
async def _create_hierarchical_plan(self, objective: str) -> Dict[str, Any]:
"""Create a hierarchical plan with multiple levels of detail.
Args:
objective: The high-level objective
Returns:
A hierarchical plan structure
"""
return {
"objective": objective,
"levels": {
"strategic": {
"timeframe": "Long-term (weeks/months)",
"goals": [
f"Achieve {objective}",
"Establish sustainable processes",
"Create reusable components"
]
},
"tactical": {
"timeframe": "Medium-term (days/weeks)",
"goals": [
"Design system architecture",
"Implement core features",
"Set up development environment"
]
},
"operational": {
"timeframe": "Short-term (hours/days)",
"goals": [
"Write specific code modules",
"Fix individual bugs",
"Complete defined tasks"
]
}
}
}
async def _reflect_on_progress(self, completed_work: List[str],
remaining_work: List[str]) -> Dict[str, Any]:
"""Reflect on progress made and suggest adjustments.
Args:
completed_work: List of completed tasks/work items
remaining_work: List of remaining tasks/work items
Returns:
Reflection insights and recommendations
"""
return {
"progress_assessment": {
"completed_count": len(completed_work),
"remaining_count": len(remaining_work),
"completion_percentage": len(completed_work) / max(len(completed_work) + len(remaining_work), 1) * 100
},
"insights": [
f"Completed {len(completed_work)} tasks so far",
f"Have {len(remaining_work)} tasks remaining",
"Progress is on track" if len(completed_work) >= len(remaining_work) else "May need to adjust approach"
],
"recommendations": [
"Continue with current approach" if len(completed_work) > 0 else "Consider starting with simpler tasks",
"Break down large remaining tasks into smaller pieces",
"Verify completed work before moving on"
],
"suggested_adjustments": []
}
async def _apply_problem_solving_framework(self, problem: str) -> Dict[str, Any]:
"""Apply a structured problem-solving framework.
Args:
problem: Description of the problem to solve
Returns:
Structured analysis and solution approach
"""
return {
"problem": problem,
"framework_applied": "IDEAL (Identify, Define, Explore, Act, Look)",
"steps": {
"Identify": {
"description": "Clearly identify what the problem is",
"questions": [
"What exactly is not working or needs to be created?",
"What are the symptoms or error messages?",
"When does the problem occur?"
]
},
"Define": {
"description": "Define the problem clearly and specifically",
"questions": [
"What are the boundaries of this problem?",
"What would a successful solution look like?",
"What constraints or requirements exist?"
]
},
"Explore": {
"description": "Explore possible solutions and approaches",
"questions": [
"What similar problems have been solved before?",
"What different approaches could work?",
"What resources or tools are available?"
]
},
"Act": {
"description": "Act on the best solution found",
"questions": [
"What is the most promising approach?",
"What steps need to be taken to implement it?",
"What risks or challenges might arise?"
]
},
"Look": {
"description": "Look back and evaluate the results",
"questions": [
"Did the solution work as expected?",
"What was learned from this process?",
"How can this approach be improved or generalized?"
]
}
}
}
|