Temporal Cloud support

This commit is contained in:
Steve Androulakis
2025-01-10 14:13:32 -08:00
parent 22f9f6dee4
commit c623029c9d
9 changed files with 155 additions and 104 deletions

View File

@@ -1,6 +1,6 @@
import asyncio
from temporalio.client import Client
from workflows.tool_workflow import ToolWorkflow

View File

@@ -1,12 +1,12 @@
import asyncio
from temporalio.client import Client
from workflows import ToolWorkflow
from shared.config import get_temporal_client
from workflows.tool_workflow import ToolWorkflow
async def main():
# Create client connected to server at the given address
client = await Client.connect("localhost:7233")
client = await get_temporal_client()
workflow_id = "agent-workflow"
handle = client.get_workflow_handle(workflow_id)
@@ -15,16 +15,7 @@ async def main():
history = await handle.query(ToolWorkflow.get_conversation_history)
print("Conversation History")
print(
*(f"{speaker.title()}: {message}\n" for speaker, message in history), sep="\n"
)
# Queries the workflow for the conversation summary
summary = await handle.query(ToolWorkflow.get_summary_from_history)
if summary is not None:
print("Conversation Summary:")
print(summary)
print(history)
if __name__ == "__main__":

View File

@@ -1,23 +0,0 @@
import asyncio
import json
from temporalio.client import Client
from workflows.tool_workflow import ToolWorkflow
async def main():
# Create client connected to server at the given address
client = await Client.connect("localhost:7233")
workflow_id = "agent-workflow"
handle = client.get_workflow_handle(workflow_id)
# Queries the workflow for the conversation history
tool_data = await handle.query(ToolWorkflow.get_tool_data)
# pretty print
print(json.dumps(tool_data, indent=4))
if __name__ == "__main__":
asyncio.run(main())

View File

@@ -1,27 +1,26 @@
import asyncio
import concurrent.futures
import logging
from temporalio.client import Client
import concurrent.futures
from temporalio.worker import Worker
from activities.tool_activities import ToolActivities, dynamic_tool_activity
from workflows.tool_workflow import ToolWorkflow
from dotenv import load_dotenv
load_dotenv()
from shared.config import get_temporal_client, TEMPORAL_TASK_QUEUE
async def main():
# Create client connected to server at the given address
client = await Client.connect("localhost:7233")
# Create the client
client = await get_temporal_client()
activities = ToolActivities()
# Run the worker
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as activity_executor:
worker = Worker(
client,
task_queue="agent-task-queue",
task_queue=TEMPORAL_TASK_QUEUE,
workflows=[ToolWorkflow],
activities=[
activities.prompt_llm,
@@ -29,12 +28,10 @@ async def main():
],
activity_executor=activity_executor,
)
print(f"Starting worker, connecting to task queue: {TEMPORAL_TASK_QUEUE}")
await worker.run()
if __name__ == "__main__":
print("Starting worker")
logging.basicConfig(level=logging.INFO)
asyncio.run(main())

View File

@@ -1,12 +1,14 @@
import asyncio
import sys
from temporalio.client import Client
from shared.config import get_temporal_client
from workflows.tool_workflow import ToolWorkflow
async def main():
# 1) Connect to Temporal and signal the workflow
client = await Client.connect("localhost:7233")
# Connect to Temporal and signal the workflow
client = await get_temporal_client()
workflow_id = "agent-workflow"