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 # TODO for this branch
## Agent ## Agent
- We'll have to figure out which matches are where. No use going to Manchester for a match that isn't there. - 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 ## Validator function
- Probably keep data types, but move the activity and workflow code for the demo - 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) print(e)
# Workflow not found; return an empty response # Workflow not found; return an empty response
return {} 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 { try {
setError(INITIAL_ERROR_STATE); setError(INITIAL_ERROR_STATE);
setLoading(true); setLoading(true);
await apiService.sendMessage("I'd like to travel for an event."); await apiService.startWorkflow();
setConversation([]); setConversation([]);
setLastMessage(null); setLastMessage(null);
} catch (err) { } 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() { async confirm() {
try { try {
const res = await fetch(`${API_BASE_URL}/confirm`, { const res = await fetch(`${API_BASE_URL}/confirm`, {

View File

@@ -20,6 +20,7 @@ class ToolDefinition:
class AgentGoal: class AgentGoal:
tools: List[ToolDefinition] tools: List[ToolDefinition]
description: str = "Description of the tools purpose and overall goal" 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: str = (
"Example conversation history to help the AI agent understand the context of the conversation" "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 " "1. FindFixtures: Find fixtures for a team in a given month "
"2. SearchFlights: search for a flight around the event dates " "2. SearchFlights: search for a flight around the event dates "
"3. CreateInvoice: Create a simple invoice for the cost of that flight ", "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( example_conversation_history="\n ".join(
[ [
"user: I'd like to travel to a football match", "user: I'd like to travel to a football match",