start prompt comes from back-end

This commit is contained in:
Steve Androulakis
2025-02-03 13:32:33 -08:00
parent 2a2383bb71
commit 36d4bd5889
7 changed files with 64 additions and 18 deletions

View File

@@ -142,6 +142,7 @@ Access the UI at `http://localhost:5173`
# TODO for this branch
## Agent
- We'll have to figure out which matches are where. No use going to Manchester for a match that isn't there.
- The use of `###` in prompts I want excluded from the conversation history is a bit of a hack.
## Validator function
- Probably keep data types, but move the activity and workflow code for the demo

View File

@@ -132,3 +132,26 @@ async def end_chat():
print(e)
# Workflow not found; return an empty response
return {}
@app.post("/start-workflow")
async def start_workflow():
# Create combined input
combined_input = CombinedInput(
tool_params=ToolWorkflowParams(None, None),
agent_goal=goal_event_flight_invoice,
)
workflow_id = "agent-workflow"
# Start the workflow with the starter prompt from the goal
await temporal_client.start_workflow(
ToolWorkflow.run,
combined_input,
id=workflow_id,
task_queue=TEMPORAL_TASK_QUEUE,
start_signal="user_prompt",
start_signal_args=["### " + goal_event_flight_invoice.starter_prompt],
)
return {"message": f"Workflow started with goal's starter prompt: {goal_event_flight_invoice.starter_prompt}."}

View File

@@ -167,7 +167,7 @@ export default function App() {
try {
setError(INITIAL_ERROR_STATE);
setLoading(true);
await apiService.sendMessage("I'd like to travel for an event.");
await apiService.startWorkflow();
setConversation([]);
setLastMessage(null);
} catch (err) {

View File

@@ -56,6 +56,26 @@ export const apiService = {
}
},
async startWorkflow() {
try {
const res = await fetch(
`${API_BASE_URL}/start-workflow`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
}
);
return handleResponse(res);
} catch (error) {
throw new ApiError(
'Failed to start workflow',
error.status || 500
);
}
},
async confirm() {
try {
const res = await fetch(`${API_BASE_URL}/confirm`, {

View File

@@ -20,6 +20,7 @@ class ToolDefinition:
class AgentGoal:
tools: List[ToolDefinition]
description: str = "Description of the tools purpose and overall goal"
starter_prompt: str = "Initial prompt to start the conversation"
example_conversation_history: str = (
"Example conversation history to help the AI agent understand the context of the conversation"
)

View File

@@ -11,6 +11,7 @@ goal_event_flight_invoice = AgentGoal(
"1. FindFixtures: Find fixtures for a team in a given month "
"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",
example_conversation_history="\n ".join(
[
"user: I'd like to travel to a football match",

View File

@@ -151,23 +151,23 @@ class ToolWorkflow:
if not prompt.startswith("###"):
self.add_message("user", prompt)
# Validate the prompt before proceeding
validation_input = ValidationInput(
prompt=prompt,
conversation_history=self.conversation_history,
agent_goal=agent_goal,
)
validation_result = await workflow.execute_activity(
ToolActivities.validate_llm_prompt,
args=[validation_input],
schedule_to_close_timeout=LLM_ACTIVITY_TIMEOUT,
retry_policy=RetryPolicy(initial_interval=timedelta(seconds=5)),
)
# Validate the prompt before proceeding
validation_input = ValidationInput(
prompt=prompt,
conversation_history=self.conversation_history,
agent_goal=agent_goal,
)
validation_result = await workflow.execute_activity(
ToolActivities.validate_llm_prompt,
args=[validation_input],
schedule_to_close_timeout=LLM_ACTIVITY_TIMEOUT,
retry_policy=RetryPolicy(initial_interval=timedelta(seconds=5)),
)
if not validation_result.validationResult:
# Handle validation failure
self.add_message("agent", validation_result.validationFailedReason)
continue # Skip to the next iteration
if not validation_result.validationResult:
# Handle validation failure
self.add_message("agent", validation_result.validationFailedReason)
continue # Skip to the next iteration
# Proceed with generating the context and prompt