diff --git a/models/tool_definitions.py b/models/tool_definitions.py index d4b085f..76d9ab3 100644 --- a/models/tool_definitions.py +++ b/models/tool_definitions.py @@ -15,9 +15,11 @@ class ToolDefinition: description: str arguments: List[ToolArgument] - @dataclass class AgentGoal: + id: str + agent_name: str + agent_friendly_description: str tools: List[ToolDefinition] description: str = "Description of the tools purpose and overall goal" starter_prompt: str = "Initial prompt to start the conversation" diff --git a/prompts/agent_prompt_generators.py b/prompts/agent_prompt_generators.py index d5e301f..cbd0d97 100644 --- a/prompts/agent_prompt_generators.py +++ b/prompts/agent_prompt_generators.py @@ -125,7 +125,8 @@ 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": "", "tool": "", "args": {"": "", "": "}, "response": ""}' "ONLY return those json keys (next, tool, args, response), nothing else." - 'Next should be "question".' + 'Next should be "question" if the tool is not the last one in the sequence.' + 'Next should only be "confirm" if all tools have been run (use the system prompt to figure that out).' ) def generate_missing_args_prompt(current_tool: str, tool_data: dict, missing_args: list[str]) -> str: diff --git a/tools/change_goal.py b/tools/change_goal.py index 7588ae2..df897ef 100644 --- a/tools/change_goal.py +++ b/tools/change_goal.py @@ -1,18 +1,8 @@ -# can this just call the API endpoint to set the goal, if that changes to allow a param? -# if this functions, it could work to both send a signal and also circumvent the UI -> API thing. Maybe? - -# --- OR --- - -# end this workflow and start a new one with the new goal - -# --- OR --- - -# send a signal to the workflow from here? -import shared.config - def change_goal(args: dict) -> dict: new_goal = args.get("goalID") + if new_goal is None: + new_goal = "goal_choose_agent_type" return { "new_goal": new_goal, diff --git a/tools/goal_registry.py b/tools/goal_registry.py index 01d1ea9..00be732 100644 --- a/tools/goal_registry.py +++ b/tools/goal_registry.py @@ -1,3 +1,4 @@ +from typing import List from models.tool_definitions import AgentGoal from tools.tool_registry import ( search_fixtures_tool, @@ -13,9 +14,12 @@ from tools.tool_registry import ( starter_prompt_generic = "Welcome me, give me a description of what you can do, then ask me for the details you need to do your job" goal_choose_agent_type = AgentGoal( + id = "goal_choose_agent_type", + agent_name="Choose Agent", + agent_friendly_description="Choose the type of agent to assist you today.", tools=[ list_agents_tool, - change_goal_tool + change_goal_tool, ], description="The user wants to choose which type of agent they will interact with. " "Help the user gather args for these tools, in order: " @@ -38,6 +42,9 @@ goal_choose_agent_type = AgentGoal( ) goal_match_train_invoice = AgentGoal( + id = "goal_match_train_invoice", + agent_name="UK Premier League Match Trip Booking", + agent_friendly_description="Book a trip to a city in the UK around the dates of a premier league match.", tools=[ search_fixtures_tool, search_trains_tool, @@ -81,10 +88,14 @@ goal_match_train_invoice = AgentGoal( ) goal_event_flight_invoice = AgentGoal( + id = "goal_event_flight_invoice", + agent_name="Australia and New Zealand Event Flight Booking", + agent_friendly_description="Book a trip to a city in Australia or New Zealand around the dates of events in that city.", tools=[ find_events_tool, search_flights_tool, create_invoice_tool, + list_agents_tool, ], description="Help the user gather args for these tools in order: " "1. FindEvents: Find an event to travel to " @@ -113,3 +124,9 @@ goal_event_flight_invoice = AgentGoal( ] ), ) + +#Add the goals to a list for more generic processing, like listing available agents +goal_list: List[AgentGoal] = [] +goal_list.append(goal_choose_agent_type) +goal_list.append(goal_event_flight_invoice) +goal_list.append(goal_match_train_invoice) diff --git a/tools/list_agents.py b/tools/list_agents.py index 62f3010..1fc56f3 100644 --- a/tools/list_agents.py +++ b/tools/list_agents.py @@ -1,27 +1,17 @@ -from pathlib import Path -import json +import tools.goal_registry as goals def list_agents(args: dict) -> dict: - # file_path = Path(__file__).resolve().parent / "goal_regsitry.py" - #if not file_path.exists(): - # return {"error": "Data file not found."} - agents = [] - agents.append( - { - "agent_name": "Event Flight Helper", - "goal_id": "goal_event_flight_invoice", - "agent_description": "Helps users find interesting events and arrange travel to them", - } - ) - agents.append( - { - "agent_name": "Soccer Train Thing Guy", - "goal_id": "goal_match_train_invoice", - "agent_description": "Something about soccer and trains and stuff", - } - ) + if goals.goal_list is not None: + for goal in goals.goal_list: + agents.append( + { + "agent_name": goal.agent_name, + "goal_id": goal.id, + "agent_description": goal.agent_friendly_description, + } + ) return { "agents": agents, - } \ No newline at end of file + } diff --git a/workflows/agent_goal_workflow.py b/workflows/agent_goal_workflow.py index c6c05ae..2569041 100644 --- a/workflows/agent_goal_workflow.py +++ b/workflows/agent_goal_workflow.py @@ -1,6 +1,5 @@ from collections import deque from datetime import timedelta -import importlib from typing import Dict, Any, Union, List, Optional, Deque, TypedDict from temporalio.common import RetryPolicy @@ -97,12 +96,17 @@ class AgentGoalWorkflow: 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 - 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.warning(f"Booya new goal!: {new_goal}") - self.change_goal(new_goal) + if len(self.tool_results) > 0: + if "ChangeGoal" in self.tool_results[-1].values() and "new_goal" in self.tool_results[-1].keys(): + new_goal = self.tool_results[-1].get("new_goal") + workflow.logger.warning(f"Booya new goal!: {new_goal}") + self.change_goal(new_goal) + elif "ListAgents" in self.tool_results[-1].values() and self.goal.id != "goal_choose_agent_type": + workflow.logger.warning("setting goal to goal_choose_agent_type") + self.change_goal("goal_choose_agent_type") continue if self.prompt_queue: @@ -252,6 +256,9 @@ class AgentGoalWorkflow: } if goal is not None: + # for listed_goal in goals.goal_list: + # if listed_goal.id == goal: + # self.goal = listed_goal self.goal = goals.get(goal) workflow.logger.warning("Changed goal to " + goal) #todo reset goal or tools if this doesn't work or whatever