mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-15 14:08:08 +01:00
added confirmation signal step, Temporal is awesome
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from temporalio import activity
|
from temporalio import activity
|
||||||
from temporalio.exceptions import ApplicationError
|
|
||||||
from ollama import chat, ChatResponse
|
from ollama import chat, ChatResponse
|
||||||
import json
|
import json
|
||||||
from typing import Sequence
|
from typing import Sequence
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class ToolWorkflow:
|
|||||||
self.chat_ended: bool = False
|
self.chat_ended: bool = False
|
||||||
self.tool_data = None
|
self.tool_data = None
|
||||||
self.max_turns_before_continue: int = 250
|
self.max_turns_before_continue: int = 250
|
||||||
|
self.confirm = False
|
||||||
|
|
||||||
@workflow.run
|
@workflow.run
|
||||||
async def run(self, combined_input: CombinedInput) -> str:
|
async def run(self, combined_input: CombinedInput) -> str:
|
||||||
@@ -96,6 +97,14 @@ class ToolWorkflow:
|
|||||||
) # e.g. "FindEvents", "SearchFlights", "CreateInvoice"
|
) # e.g. "FindEvents", "SearchFlights", "CreateInvoice"
|
||||||
|
|
||||||
if next_step == "confirm" and current_tool:
|
if next_step == "confirm" and current_tool:
|
||||||
|
self.confirm = False
|
||||||
|
|
||||||
|
# Wait for a 'confirm' signal
|
||||||
|
await workflow.wait_condition(lambda: self.confirm)
|
||||||
|
workflow.logger.info(
|
||||||
|
"Confirmed. Proceeding with tool execution: " + current_tool
|
||||||
|
)
|
||||||
|
|
||||||
# We have enough info to call the tool
|
# We have enough info to call the tool
|
||||||
dynamic_result = await workflow.execute_activity(
|
dynamic_result = await workflow.execute_activity(
|
||||||
current_tool,
|
current_tool,
|
||||||
@@ -188,6 +197,10 @@ class ToolWorkflow:
|
|||||||
async def end_chat(self) -> None:
|
async def end_chat(self) -> None:
|
||||||
self.chat_ended = True
|
self.chat_ended = True
|
||||||
|
|
||||||
|
@workflow.signal
|
||||||
|
async def confirm(self) -> None:
|
||||||
|
self.confirm = True
|
||||||
|
|
||||||
@workflow.query
|
@workflow.query
|
||||||
def get_conversation_history(self) -> List[Tuple[str, str]]:
|
def get_conversation_history(self) -> List[Tuple[str, str]]:
|
||||||
return self.conversation_history
|
return self.conversation_history
|
||||||
|
|||||||
Reference in New Issue
Block a user