[fix] fix overlong steps of thinking and avoid redundant steps after task completion && [add timer] set max time 1h to run the agent
This commit is contained in:
parent
7a9e22d093
commit
e6ed98e53c
@ -109,12 +109,14 @@ class PlanningFlow(BaseFlow):
|
|||||||
|
|
||||||
# Create a system message for plan creation
|
# Create a system message for plan creation
|
||||||
system_message = Message.system_message(
|
system_message = Message.system_message(
|
||||||
"You are a planning assistant. Your task is to create a detailed plan with clear steps."
|
"You are a planning assistant. Create a concise, actionable plan with clear steps. "
|
||||||
|
"Focus on key milestones rather than detailed sub-steps. "
|
||||||
|
"Optimize for clarity and efficiency."
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create a user message with the request
|
# Create a user message with the request
|
||||||
user_message = Message.user_message(
|
user_message = Message.user_message(
|
||||||
f"Create a detailed plan to accomplish this task: {request}"
|
f"Create a reasonable plan with clear steps to accomplish the task: {request}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Call LLM with PlanningTool
|
# Call LLM with PlanningTool
|
||||||
|
@ -1,25 +1,27 @@
|
|||||||
PLANNING_SYSTEM_PROMPT = """
|
PLANNING_SYSTEM_PROMPT = """
|
||||||
You are an expert Planning Agent tasked with solving complex problems by creating and managing structured plans.
|
You are an expert Planning Agent tasked with solving problems efficiently through structured plans.
|
||||||
Your job is:
|
Your job is:
|
||||||
1. Analyze requests to understand the task scope
|
1. Analyze requests to understand the task scope
|
||||||
2. Create clear, actionable plans with the `planning` tool
|
2. Create a clear, actionable plan that makes meaningful progress with the `planning` tool
|
||||||
3. Execute steps using available tools as needed
|
3. Execute steps using available tools as needed
|
||||||
4. Track progress and adapt plans dynamically
|
4. Track progress and adapt plans when necessary
|
||||||
5. Use `finish` to conclude when the task is complete
|
5. Use `finish` to conclude immediately when the task is complete
|
||||||
|
|
||||||
|
|
||||||
Available tools will vary by task but may include:
|
Available tools will vary by task but may include:
|
||||||
- `planning`: Create, update, and track plans (commands: create, update, mark_step, etc.)
|
- `planning`: Create, update, and track plans (commands: create, update, mark_step, etc.)
|
||||||
- `finish`: End the task when complete
|
- `finish`: End the task when complete
|
||||||
|
Break tasks into logical steps with clear outcomes. Avoid excessive detail or sub-steps.
|
||||||
Break tasks into logical, sequential steps. Think about dependencies and verification methods.
|
Think about dependencies and verification methods.
|
||||||
|
Know when to conclude - don't continue thinking once objectives are met.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
NEXT_STEP_PROMPT = """
|
NEXT_STEP_PROMPT = """
|
||||||
Based on the current state, what's your next step?
|
Based on the current state, what's your next action?
|
||||||
Consider:
|
Choose the most efficient path forward:
|
||||||
1. Do you need to create or refine a plan?
|
1. Is the plan sufficient, or does it need refinement?
|
||||||
2. Are you ready to execute a specific step?
|
2. Can you execute the next step immediately?
|
||||||
3. Have you completed the task?
|
3. Is the task complete? If so, use `finish` right away.
|
||||||
|
|
||||||
Provide reasoning, then select the appropriate tool or action.
|
Be concise in your reasoning, then select the appropriate tool or action.
|
||||||
"""
|
"""
|
||||||
|
21
run_flow.py
21
run_flow.py
@ -1,4 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import time
|
||||||
|
|
||||||
from app.agent.manus import Manus
|
from app.agent.manus import Manus
|
||||||
from app.flow.base import FlowType
|
from app.flow.base import FlowType
|
||||||
@ -26,12 +27,24 @@ async def run_flow():
|
|||||||
logger.warning("Skipping empty prompt.")
|
logger.warning("Skipping empty prompt.")
|
||||||
continue
|
continue
|
||||||
logger.warning("Processing your request...")
|
logger.warning("Processing your request...")
|
||||||
result = await flow.execute(prompt)
|
|
||||||
logger.info(result)
|
try:
|
||||||
|
start_time = time.time()
|
||||||
|
result = await asyncio.wait_for(
|
||||||
|
flow.execute(prompt),
|
||||||
|
timeout=3600 # 60 minute timeout for the entire execution
|
||||||
|
)
|
||||||
|
elapsed_time = time.time() - start_time
|
||||||
|
logger.info(f"Request processed in {elapsed_time:.2f} seconds")
|
||||||
|
logger.info(result)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
logger.error("Request processing timed out after 1 hour")
|
||||||
|
logger.info("Operation terminated due to timeout. Please try a simpler request.")
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logger.warning("Goodbye!")
|
logger.info("Operation cancelled by user.")
|
||||||
break
|
except Exception as e:
|
||||||
|
logger.error(f"Error: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user