Change instructions to AI to handle switching back to ListAgents when done with tool chain

This commit is contained in:
Laine
2025-03-11 12:02:26 -04:00
parent 804568e366
commit f13ed70bfe
3 changed files with 16 additions and 24 deletions

View File

@@ -194,7 +194,6 @@ async def end_chat():
@app.post("/start-workflow")
async def start_workflow():
# Get the initial goal as set in shared/config or env or just...always should be "pick a goal?"
initial_agent_goal = get_initial_agent_goal()
# Create combined input

View File

@@ -81,9 +81,8 @@ def generate_genai_prompt(
"1) If any required argument is missing, set next='question' and ask the user.\n"
"2) If all required arguments are known, set next='confirm' and specify the tool.\n"
" The user will confirm before the tool is run.\n"
"3) If no more tools are needed (user_confirmed_tool_run has been run for all), set next='done' and tool=null.\n"
"3) If no more tools are needed (user_confirmed_tool_run has been run for all), set next='confirm' and tool='ListAgents'.\n"
"4) response should be short and user-friendly.\n"
"5) Don't set next='done' until the final tool has returned user_confirmed_tool_run.\n"
)
# Validation Task (If raw_json is provided)
@@ -126,9 +125,7 @@ def generate_tool_completion_prompt(current_tool: str, dynamic_result: dict) ->
"You will need to use the tool_results to auto-fill arguments for subsequent tools and also to figure out if all tools have been run."
'{"next": "<question|confirm|done>", "tool": "<tool_name or null>", "args": {"<arg1>": "<value1 or null>", "<arg2>": "<value2 or null>}, "response": "<plain text (can include \\n line breaks)>"}'
"ONLY return those json keys (next, tool, args, response), nothing else."
'Next should only be "done" if all tools have been run (use the system prompt to figure that out).'
'Next should be "question" if the tool is not the last one in the sequence.'
'Next should NOT be "confirm" at this point.'
'Next should be "question".'
)
def generate_missing_args_prompt(current_tool: str, tool_data: dict, missing_args: list[str]) -> str:

View File

@@ -12,9 +12,6 @@ from workflows.workflow_helpers import LLM_ACTIVITY_START_TO_CLOSE_TIMEOUT, \
LLM_ACTIVITY_SCHEDULE_TO_CLOSE_TIMEOUT
from workflows import workflow_helpers as helpers
#importlib.reload(my_module)
with workflow.unsafe.imports_passed_through():
from activities.tool_activities import ToolActivities
from prompts.agent_prompt_generators import (
@@ -24,9 +21,6 @@ with workflow.unsafe.imports_passed_through():
CombinedInput,
ToolPromptInput,
)
import shared.config
importlib.reload(shared.config)
#from shared.config import AGENT_GOAL
from tools.goal_registry import goal_match_train_invoice, goal_event_flight_invoice, goal_choose_agent_type
# Constants
@@ -50,7 +44,6 @@ class AgentGoalWorkflow:
self.tool_data: Optional[ToolData] = None
self.confirm: bool = False
self.tool_results: List[Dict[str, Any]] = []
#set initial goal of "pick an agent" here??
self.goal: AgentGoal = {"tools": []}
# see ../api/main.py#temporal_client.start_workflow() for how these parameters are set
@@ -108,16 +101,8 @@ class AgentGoalWorkflow:
if len(self.tool_results) > 0 and "new_goal" in self.tool_results[-1].keys() and "ChangeGoal" in self.tool_results[-1].values():
new_goal = self.tool_results[-1].get("new_goal")
workflow.logger.info(f"Booya new goal!: {new_goal}")
goals = {
"goal_match_train_invoice": goal_match_train_invoice,
"goal_event_flight_invoice": goal_event_flight_invoice,
"goal_choose_agent_type": goal_choose_agent_type,
}
if new_goal is not None:
self.goal = goals.get(new_goal)
#todo reset goal or tools if this doesn't work or whatever
workflow.logger.warning(f"Booya new goal!: {new_goal}")
self.change_goal(new_goal)
continue
if self.prompt_queue:
@@ -161,7 +146,6 @@ class AgentGoalWorkflow:
context_instructions=context_instructions,
)
# connect to LLM and get...its feedback? which tool to run? ??
tool_data = await workflow.execute_activity(
ToolActivities.agent_toolPlanner,
prompt_input,
@@ -259,3 +243,15 @@ class AgentGoalWorkflow:
self.conversation_history["messages"].append(
{"actor": actor, "response": response}
)
def change_goal(self, goal: str) -> None:
goals = {
"goal_match_train_invoice": goal_match_train_invoice,
"goal_event_flight_invoice": goal_event_flight_invoice,
"goal_choose_agent_type": goal_choose_agent_type,
}
if goal is not None:
self.goal = goals.get(goal)
workflow.logger.warning("Changed goal to " + goal)
#todo reset goal or tools if this doesn't work or whatever