Skip to content

Commit e6ed98e

Browse files
committed
[fix] fix overlong steps of thinking and avoid redundant steps after task completion && [add timer] set max time 1h to run the agent
1 parent 7a9e22d commit e6ed98e

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

app/flow/planning.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,14 @@ async def _create_initial_plan(self, request: str) -> None:
109109

110110
# Create a system message for plan creation
111111
system_message = Message.system_message(
112-
"You are a planning assistant. Your task is to create a detailed plan with clear steps."
112+
"You are a planning assistant. Create a concise, actionable plan with clear steps. "
113+
"Focus on key milestones rather than detailed sub-steps. "
114+
"Optimize for clarity and efficiency."
113115
)
114116

115117
# Create a user message with the request
116118
user_message = Message.user_message(
117-
f"Create a detailed plan to accomplish this task: {request}"
119+
f"Create a reasonable plan with clear steps to accomplish the task: {request}"
118120
)
119121

120122
# Call LLM with PlanningTool

app/prompt/planning.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
PLANNING_SYSTEM_PROMPT = """
2-
You are an expert Planning Agent tasked with solving complex problems by creating and managing structured plans.
2+
You are an expert Planning Agent tasked with solving problems efficiently through structured plans.
33
Your job is:
44
1. Analyze requests to understand the task scope
5-
2. Create clear, actionable plans with the `planning` tool
5+
2. Create a clear, actionable plan that makes meaningful progress with the `planning` tool
66
3. Execute steps using available tools as needed
7-
4. Track progress and adapt plans dynamically
8-
5. Use `finish` to conclude when the task is complete
7+
4. Track progress and adapt plans when necessary
8+
5. Use `finish` to conclude immediately when the task is complete
9+
910
1011
Available tools will vary by task but may include:
1112
- `planning`: Create, update, and track plans (commands: create, update, mark_step, etc.)
1213
- `finish`: End the task when complete
13-
14-
Break tasks into logical, sequential steps. Think about dependencies and verification methods.
14+
Break tasks into logical steps with clear outcomes. Avoid excessive detail or sub-steps.
15+
Think about dependencies and verification methods.
16+
Know when to conclude - don't continue thinking once objectives are met.
1517
"""
1618

1719
NEXT_STEP_PROMPT = """
18-
Based on the current state, what's your next step?
19-
Consider:
20-
1. Do you need to create or refine a plan?
21-
2. Are you ready to execute a specific step?
22-
3. Have you completed the task?
20+
Based on the current state, what's your next action?
21+
Choose the most efficient path forward:
22+
1. Is the plan sufficient, or does it need refinement?
23+
2. Can you execute the next step immediately?
24+
3. Is the task complete? If so, use `finish` right away.
2325
24-
Provide reasoning, then select the appropriate tool or action.
26+
Be concise in your reasoning, then select the appropriate tool or action.
2527
"""

run_flow.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import time
23

34
from app.agent.manus import Manus
45
from app.flow.base import FlowType
@@ -26,12 +27,24 @@ async def run_flow():
2627
logger.warning("Skipping empty prompt.")
2728
continue
2829
logger.warning("Processing your request...")
29-
result = await flow.execute(prompt)
30-
logger.info(result)
31-
30+
31+
try:
32+
start_time = time.time()
33+
result = await asyncio.wait_for(
34+
flow.execute(prompt),
35+
timeout=3600 # 60 minute timeout for the entire execution
36+
)
37+
elapsed_time = time.time() - start_time
38+
logger.info(f"Request processed in {elapsed_time:.2f} seconds")
39+
logger.info(result)
40+
except asyncio.TimeoutError:
41+
logger.error("Request processing timed out after 1 hour")
42+
logger.info("Operation terminated due to timeout. Please try a simpler request.")
43+
3244
except KeyboardInterrupt:
33-
logger.warning("Goodbye!")
34-
break
45+
logger.info("Operation cancelled by user.")
46+
except Exception as e:
47+
logger.error(f"Error: {str(e)}")
3548

3649

3750
if __name__ == "__main__":

0 commit comments

Comments
 (0)