Add new goal to choose agent type - only kind of working

This commit is contained in:
Laine
2025-03-07 16:12:21 -05:00
parent 64d2a92630
commit 4117d5d62d
9 changed files with 170 additions and 16 deletions

View File

@@ -4,6 +4,9 @@ from .search_trains import search_trains
from .search_trains import book_trains
from .create_invoice import create_invoice
from .find_events import find_events
from .choose_agent import choose_agent
from .change_goal import change_goal
from .transfer_control import transfer_control
def get_handler(tool_name: str):
@@ -19,5 +22,11 @@ def get_handler(tool_name: str):
return create_invoice
if tool_name == "FindEvents":
return find_events
if tool_name == "ChooseAgent":
return choose_agent
if tool_name == "ChangeGoal":
return change_goal
if tool_name == "TransferControl":
return transfer_control
raise ValueError(f"Unknown tool: {tool_name}")

13
tools/change_goal.py Normal file
View File

@@ -0,0 +1,13 @@
# can this just call the API endpoint to set the goal, if that changes to allow a param?
# --- OR ---
# end this workflow and start a new one with the new goal
import shared.config
def change_goal(args: dict) -> dict:
new_goal = args.get("goalID")
shared.config.AGENT_GOAL = new_goal
return {
"new_goal": shared.config.AGENT_GOAL,
}

27
tools/choose_agent.py Normal file
View File

@@ -0,0 +1,27 @@
from pathlib import Path
import json
def choose_agent(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",
}
)
return {
"agents": agents,
}

View File

@@ -6,6 +6,42 @@ from tools.tool_registry import (
book_trains_tool,
create_invoice_tool,
find_events_tool,
change_goal_tool,
choose_agent_tool,
transfer_control_tool
)
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(
tools=[
choose_agent_tool,
change_goal_tool,
transfer_control_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: "
"1. ChooseAgent: Choose which agent to interact with "
"2. ChangeGoal: Change goal of agent "
"3. TransferControl: Transfer control to new agent "
"After these tools are complete, change your goal to the new goal as chosen by the user. ",
starter_prompt=starter_prompt_generic,
example_conversation_history="\n ".join(
[
"user: I'd like to choose an agent",
"agent: Sure! Would you like me to list the available agents?",
"user_confirmed_tool_run: <user clicks confirm on ChooseAgent tool>",
"tool_result: { 'agent_name': 'Event Flight Finder', 'goal_id': 'goal_event_flight_invoice', 'agent_description': 'Helps users find interesting events and arrange travel to them' }",
"agent: The available agents are: 1. Event Flight Finder. Which agent would you like to speak to?",
"user: 1",
"user_confirmed_tool_run: <user clicks confirm on ChangeGoal tool>",
# bot changes goal here and hopefully just...switches??
# could also end 1 workflow and start another with new goal
"tool_result: { 'new_goal': 'goal_event_flight_invoice' }",
"agent: Would you like to transfer control to the new agent now?",
"user: yes",
]
),
)
goal_match_train_invoice = AgentGoal(
@@ -23,7 +59,7 @@ goal_match_train_invoice = AgentGoal(
"2. SearchTrains: Search for trains to the city of the match and list them for the customer to choose from "
"3. BookTrains: Book the train tickets, used to invoice the user for the cost of the train tickets "
"4. CreateInvoice: Invoices the user for the cost of train tickets, with total and details inferred from the conversation history ",
starter_prompt="Welcome me, give me a description of what you can do, then ask me for the details you need to begin your job as an agent ",
starter_prompt=starter_prompt_generic,
example_conversation_history="\n ".join(
[
"user: I'd like to travel to a premier league match",
@@ -61,7 +97,7 @@ goal_event_flight_invoice = AgentGoal(
"1. FindEvents: Find an event to travel to "
"2. SearchFlights: search for a flight around the event dates "
"3. CreateInvoice: Create a simple invoice for the cost of that flight ",
starter_prompt="Welcome me, give me a description of what you can do, then ask me for the details you need to do your job",
starter_prompt=starter_prompt_generic,
example_conversation_history="\n ".join(
[
"user: I'd like to travel to an event",

View File

@@ -1,5 +1,43 @@
from models.tool_definitions import ToolDefinition, ToolArgument
#This also doesn't help...
transfer_control_tool = ToolDefinition(
name="TransferControl",
description="Do one extra input from user to apply the new goal to the workflow (Hacky, hopefully temp). ",
arguments=[
ToolArgument(
name="userConfirmation",
type="string",
description="dummy variable to make thing work",
),
],
)
choose_agent_tool = ToolDefinition(
name="ChooseAgent",
description="List available agents to interact with, pulled from goal_registry. ",
arguments=[
ToolArgument(
name="userConfirmation",
type="string",
description="dummy variable to make thing work",
),
],
)
change_goal_tool = ToolDefinition(
name="ChangeGoal",
description="Change the goal of the active agent. ",
arguments=[
ToolArgument(
name="goalID",
type="string",
description="Which goal to change to",
),
],
)
search_flights_tool = ToolDefinition(
name="SearchFlights",
description="Search for return flights from an origin to a destination within a date range (dateDepart, dateReturn).",

View File

@@ -0,0 +1,7 @@
import shared.config
def transfer_control(args: dict) -> dict:
return {
"new_goal": shared.config.AGENT_GOAL,
}