mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-15 05:58:08 +01:00
start prompt comes from back-end
This commit is contained in:
@@ -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
|
||||||
|
|||||||
23
api/main.py
23
api/main.py
@@ -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}."}
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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`, {
|
||||||
|
|||||||
@@ -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"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
@@ -150,24 +150,24 @@ class ToolWorkflow:
|
|||||||
prompt = self.prompt_queue.popleft()
|
prompt = self.prompt_queue.popleft()
|
||||||
if not prompt.startswith("###"):
|
if not prompt.startswith("###"):
|
||||||
self.add_message("user", prompt)
|
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
|
if not validation_result.validationResult:
|
||||||
validation_input = ValidationInput(
|
# Handle validation failure
|
||||||
prompt=prompt,
|
self.add_message("agent", validation_result.validationFailedReason)
|
||||||
conversation_history=self.conversation_history,
|
continue # Skip to the next iteration
|
||||||
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
|
|
||||||
|
|
||||||
# Proceed with generating the context and prompt
|
# Proceed with generating the context and prompt
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user