renaming workflows and activities

This commit is contained in:
Steve Androulakis
2025-02-15 12:12:39 -08:00
parent ab83f4e5a0
commit b37d158770
8 changed files with 80 additions and 26 deletions

View File

@@ -25,7 +25,7 @@ if os.environ.get("LLM_PROVIDER") == "ollama":
class ToolActivities: class ToolActivities:
@activity.defn @activity.defn
async def validate_llm_prompt( async def agent_validatePrompt(
self, validation_input: ValidationInput self, validation_input: ValidationInput
) -> ValidationResult: ) -> ValidationResult:
""" """
@@ -78,7 +78,7 @@ class ToolActivities:
prompt=validation_prompt, context_instructions=context_instructions prompt=validation_prompt, context_instructions=context_instructions
) )
result = self.prompt_llm(prompt_input) result = self.agent_toolPlanner(prompt_input)
return ValidationResult( return ValidationResult(
validationResult=result.get("validationResult", False), validationResult=result.get("validationResult", False),
@@ -86,7 +86,7 @@ class ToolActivities:
) )
@activity.defn @activity.defn
def prompt_llm(self, input: ToolPromptInput) -> dict: def agent_toolPlanner(self, input: ToolPromptInput) -> dict:
llm_provider = os.environ.get("LLM_PROVIDER", "openai").lower() llm_provider = os.environ.get("LLM_PROVIDER", "openai").lower()
print(f"LLM provider: {llm_provider}") print(f"LLM provider: {llm_provider}")

View File

@@ -4,8 +4,8 @@ from temporalio.client import Client
from temporalio.exceptions import TemporalError from temporalio.exceptions import TemporalError
from temporalio.api.enums.v1 import WorkflowExecutionStatus from temporalio.api.enums.v1 import WorkflowExecutionStatus
from workflows.tool_workflow import ToolWorkflow from workflows.agent_goal_workflow import AgentGoalWorkflow
from models.data_types import CombinedInput, ToolWorkflowParams from models.data_types import CombinedInput, AgentGoalWorkflowParams
from tools.goal_registry import goal_match_train_invoice from tools.goal_registry import goal_match_train_invoice
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from shared.config import get_temporal_client, TEMPORAL_TASK_QUEUE from shared.config import get_temporal_client, TEMPORAL_TASK_QUEUE
@@ -94,7 +94,7 @@ async def get_conversation_history():
async def send_prompt(prompt: str): async def send_prompt(prompt: str):
# Create combined input # Create combined input
combined_input = CombinedInput( combined_input = CombinedInput(
tool_params=ToolWorkflowParams(None, None), tool_params=AgentGoalWorkflowParams(None, None),
agent_goal=goal_match_train_invoice, agent_goal=goal_match_train_invoice,
) )
@@ -102,7 +102,7 @@ async def send_prompt(prompt: str):
# Start (or signal) the workflow # Start (or signal) the workflow
await temporal_client.start_workflow( await temporal_client.start_workflow(
ToolWorkflow.run, AgentGoalWorkflow.run,
combined_input, combined_input,
id=workflow_id, id=workflow_id,
task_queue=TEMPORAL_TASK_QUEUE, task_queue=TEMPORAL_TASK_QUEUE,
@@ -141,7 +141,7 @@ async def end_chat():
async def start_workflow(): async def start_workflow():
# Create combined input # Create combined input
combined_input = CombinedInput( combined_input = CombinedInput(
tool_params=ToolWorkflowParams(None, None), tool_params=AgentGoalWorkflowParams(None, None),
agent_goal=goal_match_train_invoice, agent_goal=goal_match_train_invoice,
) )
@@ -149,7 +149,7 @@ async def start_workflow():
# Start the workflow with the starter prompt from the goal # Start the workflow with the starter prompt from the goal
await temporal_client.start_workflow( await temporal_client.start_workflow(
ToolWorkflow.run, AgentGoalWorkflow.run,
combined_input, combined_input,
id=workflow_id, id=workflow_id,
task_queue=TEMPORAL_TASK_QUEUE, task_queue=TEMPORAL_TASK_QUEUE,

50
backup_sessions.json Normal file
View File

@@ -0,0 +1,50 @@
{
"$schema": "https://cdn.statically.io/gh/nguyenngoclongdev/cdn/main/schema/v10/terminal-keeper.json",
"theme": "tribe",
"active": "default",
"activateOnStartup": false,
"keepExistingTerminals": false,
"sessions": {
"default": [
[
{
"name": "frontend",
"autoExecuteCommands": true,
"commands": [
"cd frontend && npx vite"
]
},
{
"name": "uvicorn",
"autoExecuteCommands": true,
"commands": [
"poetry run uvicorn api.main:app --reload"
]
}
],
[
{
"name": "agent worker",
"autoExecuteCommands": true,
"commands": [
"poetry run python scripts/run_worker.py"
]
},
{
"name": "trains worker",
"autoExecuteCommands": true,
"commands": [
"poetry run python scripts/run_legacy_worker.py"
]
}
],
{
"name": "trains_api",
"autoExecuteCommands": true,
"commands": [
"poetry run python thirdparty/train_api.py"
]
}
]
}
}

View File

@@ -4,14 +4,14 @@ from models.tool_definitions import AgentGoal
@dataclass @dataclass
class ToolWorkflowParams: class AgentGoalWorkflowParams:
conversation_summary: Optional[str] = None conversation_summary: Optional[str] = None
prompt_queue: Optional[Deque[str]] = None prompt_queue: Optional[Deque[str]] = None
@dataclass @dataclass
class CombinedInput: class CombinedInput:
tool_params: ToolWorkflowParams tool_params: AgentGoalWorkflowParams
agent_goal: AgentGoal agent_goal: AgentGoal

View File

@@ -1,7 +1,7 @@
import asyncio import asyncio
from workflows.tool_workflow import ToolWorkflow from workflows.agent_goal_workflow import AgentGoalWorkflow
async def main(): async def main():
@@ -10,10 +10,10 @@ async def main():
workflow_id = "agent-workflow" workflow_id = "agent-workflow"
handle = client.get_workflow_handle_for(ToolWorkflow.run, workflow_id) handle = client.get_workflow_handle_for(AgentGoalWorkflow.run, workflow_id)
# Sends a signal to the workflow # Sends a signal to the workflow
await handle.signal(ToolWorkflow.end_chat) await handle.signal(AgentGoalWorkflow.end_chat)
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -1,7 +1,7 @@
import asyncio import asyncio
from shared.config import get_temporal_client from shared.config import get_temporal_client
from workflows.tool_workflow import ToolWorkflow from workflows.agent_goal_workflow import AgentGoalWorkflow
async def main(): async def main():
@@ -12,7 +12,7 @@ async def main():
handle = client.get_workflow_handle(workflow_id) handle = client.get_workflow_handle(workflow_id)
# Queries the workflow for the conversation history # Queries the workflow for the conversation history
history = await handle.query(ToolWorkflow.get_conversation_history) history = await handle.query(AgentGoalWorkflow.get_conversation_history)
print("Conversation History") print("Conversation History")
print(history) print(history)

View File

@@ -5,7 +5,7 @@ import concurrent.futures
from temporalio.worker import Worker from temporalio.worker import Worker
from activities.tool_activities import ToolActivities, dynamic_tool_activity from activities.tool_activities import ToolActivities, dynamic_tool_activity
from workflows.tool_workflow import ToolWorkflow from workflows.agent_goal_workflow import AgentGoalWorkflow
from shared.config import get_temporal_client, TEMPORAL_TASK_QUEUE from shared.config import get_temporal_client, TEMPORAL_TASK_QUEUE
@@ -21,10 +21,10 @@ async def main():
worker = Worker( worker = Worker(
client, client,
task_queue=TEMPORAL_TASK_QUEUE, task_queue=TEMPORAL_TASK_QUEUE,
workflows=[ToolWorkflow], workflows=[AgentGoalWorkflow],
activities=[ activities=[
activities.prompt_llm, activities.agent_validatePrompt,
activities.validate_llm_prompt, activities.agent_toolPlanner,
dynamic_tool_activity, dynamic_tool_activity,
], ],
activity_executor=activity_executor, activity_executor=activity_executor,

View File

@@ -11,7 +11,11 @@ from models.data_types import ConversationHistory, NextStep, ValidationInput
with workflow.unsafe.imports_passed_through(): with workflow.unsafe.imports_passed_through():
from activities.tool_activities import ToolActivities from activities.tool_activities import ToolActivities
from prompts.agent_prompt_generators import generate_genai_prompt from prompts.agent_prompt_generators import generate_genai_prompt
from models.data_types import CombinedInput, ToolWorkflowParams, ToolPromptInput from models.data_types import (
CombinedInput,
AgentGoalWorkflowParams,
ToolPromptInput,
)
from shared.config import TEMPORAL_LEGACY_TASK_QUEUE from shared.config import TEMPORAL_LEGACY_TASK_QUEUE
@@ -31,7 +35,7 @@ class ToolData(TypedDict, total=False):
@workflow.defn @workflow.defn
class ToolWorkflow: class AgentGoalWorkflow:
"""Workflow that manages tool execution with user confirmation and conversation history.""" """Workflow that manages tool execution with user confirmation and conversation history."""
def __init__(self) -> None: def __init__(self) -> None:
@@ -111,7 +115,7 @@ class ToolWorkflow:
prompt=summary_prompt, context_instructions=summary_context prompt=summary_prompt, context_instructions=summary_context
) )
self.conversation_summary = await workflow.start_activity_method( self.conversation_summary = await workflow.start_activity_method(
ToolActivities.prompt_llm, ToolActivities.agent_toolPlanner,
summary_input, summary_input,
schedule_to_close_timeout=LLM_ACTIVITY_SCHEDULE_TO_CLOSE_TIMEOUT, schedule_to_close_timeout=LLM_ACTIVITY_SCHEDULE_TO_CLOSE_TIMEOUT,
) )
@@ -121,7 +125,7 @@ class ToolWorkflow:
workflow.continue_as_new( workflow.continue_as_new(
args=[ args=[
CombinedInput( CombinedInput(
tool_params=ToolWorkflowParams( tool_params=AgentGoalWorkflowParams(
conversation_summary=self.conversation_summary, conversation_summary=self.conversation_summary,
prompt_queue=self.prompt_queue, prompt_queue=self.prompt_queue,
), ),
@@ -178,7 +182,7 @@ class ToolWorkflow:
agent_goal=agent_goal, agent_goal=agent_goal,
) )
validation_result = await workflow.execute_activity( validation_result = await workflow.execute_activity(
ToolActivities.validate_llm_prompt, ToolActivities.agent_validatePrompt,
args=[validation_input], args=[validation_input],
schedule_to_close_timeout=LLM_ACTIVITY_SCHEDULE_TO_CLOSE_TIMEOUT, schedule_to_close_timeout=LLM_ACTIVITY_SCHEDULE_TO_CLOSE_TIMEOUT,
start_to_close_timeout=LLM_ACTIVITY_START_TO_CLOSE_TIMEOUT, start_to_close_timeout=LLM_ACTIVITY_START_TO_CLOSE_TIMEOUT,
@@ -208,7 +212,7 @@ class ToolWorkflow:
) )
tool_data = await workflow.execute_activity( tool_data = await workflow.execute_activity(
ToolActivities.prompt_llm, ToolActivities.agent_toolPlanner,
prompt_input, prompt_input,
schedule_to_close_timeout=LLM_ACTIVITY_SCHEDULE_TO_CLOSE_TIMEOUT, schedule_to_close_timeout=LLM_ACTIVITY_SCHEDULE_TO_CLOSE_TIMEOUT,
start_to_close_timeout=LLM_ACTIVITY_START_TO_CLOSE_TIMEOUT, start_to_close_timeout=LLM_ACTIVITY_START_TO_CLOSE_TIMEOUT,