Add dotnet activities for train interface.

This commit is contained in:
Rob Holland
2025-02-14 11:51:57 +00:00
parent 39462955eb
commit e085f02128
12 changed files with 157 additions and 23 deletions

View File

@@ -1,7 +1,7 @@
from .search_fixtures import search_fixtures
from .search_flights import search_flights
from .search_trains import search_trains
from .search_trains import book_train
from .search_trains import book_trains
from .create_invoice import create_invoice
@@ -12,8 +12,8 @@ def get_handler(tool_name: str):
return search_flights
if tool_name == "SearchTrains":
return search_trains
if tool_name == "BookTrain":
return book_train
if tool_name == "BookTrains":
return book_trains
if tool_name == "CreateInvoice":
return create_invoice

View File

@@ -3,7 +3,7 @@ from tools.tool_registry import (
search_fixtures_tool,
search_flights_tool,
search_trains_tool,
book_train_tool,
book_trains_tool,
create_invoice_tool,
)
@@ -11,13 +11,13 @@ goal_match_train_invoice = AgentGoal(
tools=[
search_fixtures_tool,
search_trains_tool,
book_train_tool,
book_trains_tool,
create_invoice_tool,
],
description="Help the user book trains to a premier league match. The user lives in London. Gather args for these tools in order: "
"1. SearchFixtures: Search for fixtures for a team in a given month"
"2. SearchTrains: Search for trains to the city of the match and list them for the customer to choose from"
"3. BookTrain: Book the train tickets"
"3. BookTrains: Book the train tickets"
"4. CreateInvoice: Proactively offer to create a simple invoice for the cost of the flights and train tickets",
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",
example_conversation_history="\n ".join(
@@ -32,7 +32,7 @@ goal_match_train_invoice = AgentGoal(
"user_confirmed_tool_run: <user clicks confirm on SearchTrains tool>",
"tool_result: <results including train dates and times, origin and depature stations>",
"agent: Found some trains! <agent provides a human-readable list of train options>",
"user_confirmed_tool_run: <user clicks confirm on BookTrain tool>",
"user_confirmed_tool_run: <user clicks confirm on BookTrains tool>",
'tool_result: results including {"status": "success"}',
"agent: Train tickets booked! Please confirm the following invoice for the journey. <agent infers total amount for the invoice and details from the conversation history>",
"user_confirmed_tool_run: <user clicks confirm on CreateInvoice tool which includes details of the train journey, the match, and the total cost>",

View File

@@ -15,7 +15,7 @@ def search_trains(args: dict) -> dict:
if not origin or not destination or not outbound_time or not return_time:
return {"error": "Origin, destination, outbound_time and return_time are required."}
search_url = f'{BASE_URL}/api/journeys'
search_url = f'{BASE_URL}/api/search'
params = {
'from': origin,
'to': destination,
@@ -31,15 +31,15 @@ def search_trains(args: dict) -> dict:
journey_data = response.json()
return journey_data
def book_train(args: dict) -> dict:
def book_trains(args: dict) -> dict:
load_dotenv(override=True)
journey_id = args.get("journey_id")
train_ids = args.get("train_ids")
if not journey_id:
return {"error": "Journey ID is required."}
if not train_ids:
return {"error": "Train IDs is required."}
book_url = f'{BASE_URL}/api/book/{journey_id}'
book_url = f'{BASE_URL}/api/book/{train_ids}'
response = requests.post(book_url)
if response.status_code != 200:
return {"error": "Failed to book ticket."}
@@ -59,7 +59,7 @@ if __name__ == "__main__":
print(search_results)
book_args = {
"journey_id": "12345",
"train_ids": "12345",
}
booking_results = book_train(book_args)
booking_results = book_trains(book_args)
print(booking_results)

View File

@@ -54,14 +54,14 @@ search_trains_tool = ToolDefinition(
],
)
book_train_tool = ToolDefinition(
name="BookTrain",
description="Books a train ticket. Returns a booking reference.",
book_trains_tool = ToolDefinition(
name="BookTrains",
description="Books train tickets. Returns a booking reference.",
arguments=[
ToolArgument(
name="journey_id",
name="train_ids",
type="string",
description="The ID of the journey to book",
description="The IDs of the trains to book, comma separated",
),
],
)