Replies: 3 comments
-
Here is the thing I have written so far for this purpose: from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from browser_use import Agent
from colored_print import log
load_dotenv()
MAX_STEPS = 30
async def main(task):
log.info("Starting the automation process...")
try:
agent = Agent(
task=task,
llm=ChatOpenAI(model="gpt-4o"),
)
result = await agent.run(max_steps=MAX_STEPS)
# Determine success based on completion and steps
is_complete = result.history[-1].model_output.current_state.evaluation_previous_goal if result.history else False
max_steps_reached = len(result.history) >= MAX_STEPS
if max_steps_reached:
return {
"result": "Task exceeded maximum allowed steps",
"success": False,
"error": "Max steps exceeded without completion"
}
return {
"result": str(result),
"success": is_complete,
"error": None
}
except Exception as e:
return {
"result": str(e),
"success": False,
"error": str(e)
} async def process_automation(
task: str, task_id: str, is_capsolver: bool, webhook_url: str
):
webhook_sent = False # Flag to track if webhook has been sent
try:
log.info("Starting automation process...")
result = await browser_capsolver(task) if is_capsolver else await browser_main(task)
log.info(f"Automation result: {result}")
if isinstance(result, dict):
# Ensure success is a boolean
success = bool(result.get("success", False))
# Use the previous 'success' value as the message
message = result.get("success") if success else result.get("error", "Unknown error")
log.info("Sending webhook for valid result")
await send_webhook(
task_id=task_id,
success=success,
message=message,
webhook_url=webhook_url
)
webhook_sent = True # Set flag to true after successful webhook
else:
log.info("Sending webhook for invalid result format")
await send_webhook(
task_id=task_id,
success=False,
message="Invalid result format",
webhook_url=webhook_url
)
webhook_sent = True
except httpx.ConnectError as e:
log.error(f"Connection error occurred: {str(e)}")
# Handle connection-specific errors here if needed
except Exception as e:
log.error(f"Exception occurred: {str(e)}")
if not webhook_sent: # Only send webhook if it hasn't been sent yet
await send_webhook(
task_id=task_id,
success=False,
message=str(e),
webhook_url=webhook_url
) |
Beta Was this translation helpful? Give feedback.
-
I found something more accurate within the max_steps_reached = len(result.history) >= MAX_STEPS
is_done = result.history[-1].result[-1].is_done
message = result.history[-1].result[-1].extracted_content
error = result.history[-1].result[-1].error |
Beta Was this translation helpful? Give feedback.
-
To determine the final result of #348, you might want to break down the process into smaller steps or analyze key factors that influence the outcome. Consulting with "infection control experts" could also provide valuable insights, especially if it's related to health or safety protocols. |
Beta Was this translation helpful? Give feedback.
-
after calling
result = await agent.run(max_steps=30)
and getting the result, is there any way to determine whether the process has been successful or has failed?Beta Was this translation helpful? Give feedback.
All reactions