mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-15 14:08:08 +01:00
improved performance with openai but not perfect
This commit is contained in:
@@ -57,18 +57,20 @@ class ToolActivities:
|
||||
# Create validation prompt
|
||||
validation_prompt = f"""The user's prompt is: "{validation_input.prompt}"
|
||||
Please validate if this prompt makes sense given the agent goal and conversation history.
|
||||
If the prompt doesn't make sense toward the goal then validationResult should be true.
|
||||
Only return false if the prompt is nonsensical given the goal, tools available, and conversation history.
|
||||
If the prompt makes sense toward the goal then validationResult should be true.
|
||||
If the prompt is wildly nonsensical or makes no sense toward the goal and current conversation history then validationResult should be false.
|
||||
If the response is low content such as "yes" or "that's right" then the user is probably responding to a previous prompt.
|
||||
Therefore examine it in the context of the conversation history to determine if it makes sense and return true if it makes sense.
|
||||
Return ONLY a JSON object with the following structure:
|
||||
"validationResult": true/false,
|
||||
"validationFailedReason": "If validationResult is false, provide a clear explanation to the user
|
||||
"validationFailedReason": "If validationResult is false, provide a clear explanation to the user in the response field
|
||||
about why their request doesn't make sense in the context and what information they should provide instead.
|
||||
validationFailedReason should contain JSON in the format
|
||||
{{
|
||||
"next": "question",
|
||||
"response": "[your reason here and a response to get the user back on track with the agent goal]"
|
||||
}}
|
||||
If validationResult is true, return an empty dict {{}}"
|
||||
If validationResult is true (the prompt makes sense), return an empty dict as its value {{}}"
|
||||
"""
|
||||
|
||||
# Call the LLM with the validation prompt
|
||||
@@ -172,8 +174,10 @@ class ToolActivities:
|
||||
|
||||
genai.configure(api_key=api_key)
|
||||
model = genai.GenerativeModel(
|
||||
"models/gemini-2.0-flash-exp",
|
||||
system_instruction=input.context_instructions,
|
||||
"models/gemini-1.5-flash",
|
||||
system_instruction=input.context_instructions
|
||||
+ ". The current date is "
|
||||
+ datetime.now().strftime("%B %d, %Y"),
|
||||
)
|
||||
response = model.generate_content(input.prompt)
|
||||
response_content = response.text
|
||||
@@ -196,7 +200,8 @@ class ToolActivities:
|
||||
response = client.messages.create(
|
||||
model="claude-3-5-sonnet-20241022",
|
||||
max_tokens=1024,
|
||||
system=input.context_instructions + ". The current date is "
|
||||
system=input.context_instructions
|
||||
+ ". The current date is "
|
||||
+ get_current_date_human_readable(),
|
||||
messages=[
|
||||
{
|
||||
|
||||
10
thirdparty/train_api.py
vendored
10
thirdparty/train_api.py
vendored
@@ -23,17 +23,23 @@ def parse_datetime(datetime_str):
|
||||
"%Y-%m-%dT%H:%M", # e.g. "2025-04-18T09:00"
|
||||
"%Y-%m-%dT%H:%M:%S", # e.g. "2025-04-18T09:00:00"
|
||||
"%Y-%m-%d %H:%M:%S", # e.g. "2025-04-18 09:00:00"
|
||||
"%Y-%m-%d", # e.g. "2025-04-11"
|
||||
]
|
||||
|
||||
for fmt in formats:
|
||||
try:
|
||||
parsed = time.strptime(datetime_str, fmt)
|
||||
if fmt == "%Y-%m-%d":
|
||||
# Default to 9am if no time provided
|
||||
hour, minute = 9, 0
|
||||
else:
|
||||
hour, minute = parsed.tm_hour, parsed.tm_min
|
||||
return (
|
||||
parsed.tm_year,
|
||||
parsed.tm_mon,
|
||||
parsed.tm_mday,
|
||||
parsed.tm_hour,
|
||||
parsed.tm_min,
|
||||
hour,
|
||||
minute,
|
||||
)
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
@@ -16,9 +16,9 @@ goal_match_train_invoice = AgentGoal(
|
||||
],
|
||||
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 visit somewhere before or after the match"
|
||||
"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"
|
||||
"4. CreateInvoice: Create a simple invoice for the cost of the flights and 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(
|
||||
[
|
||||
@@ -28,13 +28,13 @@ goal_match_train_invoice = AgentGoal(
|
||||
"agent: Great! Let's find a match for Wolverhampton Wanderers FC in May.",
|
||||
"user_confirmed_tool_run: <user clicks confirm on SearchFixtures tool, passing the full team name as an input>",
|
||||
'tool_result: results including {"homeTeam": "Wolverhampton Wanderers FC", "awayTeam": "Manchester United", "date": "2025-05-04"}',
|
||||
"agent: Found a match! There's an away game against Manchester United on May 4 2025. Would you like to plan train travel from London for around this date?",
|
||||
"agent: Found a match! <agent provides a human-readable list of match options including the location and date>",
|
||||
"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! The best option is leaving <origin> on <date> <time> and arriving in <destination> at <date> <time>. The return trip is leaving <origin> on <date> <time> and arriving in <destination> at <date> <time>. Would you like to book this train?",
|
||||
"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>",
|
||||
'tool_result: results including {"status": "success"}',
|
||||
"agent: Train tickets booked! Now let's create an invoice for your train tickets",
|
||||
"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>",
|
||||
"tool_result: contains an invoiceURL",
|
||||
"agent: Great! I've generated your invoice for your trains to the <match>. You can view and pay your invoice at this link: https://invoice.stripe.com/i/acct_1NBOLuKVZbzw7QA5/test_YWNjdF8xTkJPTHVLVlpienc3UUE1LF9SaHlBTU9GYnFibEJ4VlpNaThkWkhrcUR6a1dwTmNULDEyOTE2MjkwNA0200CCUNvTox?s=ap",
|
||||
|
||||
@@ -29,17 +29,17 @@ search_flights_tool = ToolDefinition(
|
||||
|
||||
search_trains_tool = ToolDefinition(
|
||||
name="SearchTrains",
|
||||
description="Search for trains between two stations. Returns a list of trains.",
|
||||
description="Search for trains between two English cities. Returns a list of train information for the user to choose from.",
|
||||
arguments=[
|
||||
ToolArgument(
|
||||
name="origin",
|
||||
type="string",
|
||||
description="The station to depart from",
|
||||
description="The city or place to depart from",
|
||||
),
|
||||
ToolArgument(
|
||||
name="destination",
|
||||
type="string",
|
||||
description="The station to arrive at",
|
||||
description="The city or place to arrive at",
|
||||
),
|
||||
ToolArgument(
|
||||
name="outbound_time",
|
||||
|
||||
Reference in New Issue
Block a user