Part of one of making confirmation optional - auto-confirm but still show everything

This commit is contained in:
Laine
2025-03-12 12:49:00 -04:00
parent 504361a5a7
commit 02a63917b2

View File

@@ -26,7 +26,11 @@ with workflow.unsafe.imports_passed_through():
# Constants # Constants
MAX_TURNS_BEFORE_CONTINUE = 250 MAX_TURNS_BEFORE_CONTINUE = 250
SHOW_CONFIRM = os.getenv("SHOW_CONFIRM", True) SHOW_CONFIRM = True
show_confirm_env = os.getenv("SHOW_CONFIRM")
if show_confirm_env is not None:
if show_confirm_env == "Off":
SHOW_CONFIRM = False
class ToolData(TypedDict, total=False): class ToolData(TypedDict, total=False):
next: NextStep next: NextStep
@@ -51,6 +55,7 @@ class AgentGoalWorkflow:
# see ../api/main.py#temporal_client.start_workflow() for how the input parameters are set # see ../api/main.py#temporal_client.start_workflow() for how the input parameters are set
@workflow.run @workflow.run
async def run(self, combined_input: CombinedInput) -> str: async def run(self, combined_input: CombinedInput) -> str:
"""Main workflow execution method.""" """Main workflow execution method."""
# setup phase, starts with blank tool_params and agent_goal prompt as defined in tools/goal_registry.py # setup phase, starts with blank tool_params and agent_goal prompt as defined in tools/goal_registry.py
params = combined_input.tool_params params = combined_input.tool_params
@@ -84,7 +89,7 @@ class AgentGoalWorkflow:
workflow.logger.info("Chat ended.") workflow.logger.info("Chat ended.")
return f"{self.conversation_history}" return f"{self.conversation_history}"
# user has confirmed, now actually execute the tool # Execute the tool
if self.confirm and waiting_for_confirm and current_tool and self.tool_data: if self.confirm and waiting_for_confirm and current_tool and self.tool_data:
workflow.logger.warning(f"workflow step: user has confirmed, executing the tool {current_tool}") workflow.logger.warning(f"workflow step: user has confirmed, executing the tool {current_tool}")
self.confirm = False self.confirm = False
@@ -103,8 +108,6 @@ class AgentGoalWorkflow:
self.prompt_queue self.prompt_queue
) )
workflow.logger.warning(f"tool_results keys: {self.tool_results[-1].keys()}")
workflow.logger.warning(f"tool_results values: {self.tool_results[-1].values()}")
#set new goal if we should #set new goal if we should
if len(self.tool_results) > 0: if len(self.tool_results) > 0:
if "ChangeGoal" in self.tool_results[-1].values() and "new_goal" in self.tool_results[-1].keys(): if "ChangeGoal" in self.tool_results[-1].values() and "new_goal" in self.tool_results[-1].keys():
@@ -165,28 +168,30 @@ class AgentGoalWorkflow:
next_step = tool_data.get("next") next_step = tool_data.get("next")
current_tool = tool_data.get("tool") current_tool = tool_data.get("tool")
workflow.logger.warning(f"next_step: {next_step}, current tool is {current_tool}")
#if the next step is to confirm... #if the next step is to confirm...
if next_step == "confirm" and current_tool: if next_step == "confirm" and current_tool:
workflow.logger.warning(f"next_step: confirm, current tool is {current_tool}")
args = tool_data.get("args", {}) args = tool_data.get("args", {})
#if we're missing arguments, go back to the top of the loop #if we're missing arguments, go back to the top of the loop
if await helpers.handle_missing_args(current_tool, args, tool_data, self.prompt_queue): if await helpers.handle_missing_args(current_tool, args, tool_data, self.prompt_queue):
continue continue
#...otherwise, set up the request for user confirmation #...otherwise, if we want to force the user to confirm, set that up
waiting_for_confirm = True waiting_for_confirm = True
self.confirm = False if SHOW_CONFIRM:
workflow.logger.info("Waiting for user confirm signal...") self.confirm = False
workflow.logger.info("Waiting for user confirm signal...")
else:
#theory - set self.confirm to true bc that's the signal, so we can get around the signal??
self.confirm = True
# else if the next step is to pick a new goal... # else if the next step is to pick a new goal...
elif next_step == "pick-new-goal": elif next_step == "pick-new-goal":
workflow.logger.info("All steps completed. Resetting goal.") workflow.logger.info("All steps completed. Resetting goal.")
workflow.logger.warning("next_step = pick-new-goal, setting goal to goal_choose_agent_type")
self.change_goal("goal_choose_agent_type") self.change_goal("goal_choose_agent_type")
# else if the next step is to be done - this should only happen if the user requests it via "end conversation" # else if the next step is to be done - this should only happen if the user requests it via "end conversation"
elif next_step == "done": elif next_step == "done":
workflow.logger.warning("next_step = done")
self.add_message("agent", tool_data) self.add_message("agent", tool_data)
# end the workflow # end the workflow
return str(self.conversation_history) return str(self.conversation_history)