Fix: Enforce JSON mode for Ollama and add Temporal RetryPolicy
Build Agents Runtime / build (push) Successful in 2m6s Details

This commit is contained in:
Deep Koluguri 2026-05-23 09:50:58 -04:00
parent 3c5d08933e
commit 6df7a23d57
2 changed files with 11 additions and 9 deletions

View File

@ -17,7 +17,8 @@ def get_llm():
model=LLM_MODEL,
api_key="ollama", # Ollama doesn't strictly need an API key
base_url=OLLAMA_BASE_URL,
temperature=0.1
temperature=0.1,
model_kwargs={"response_format": {"type": "json_object"}}
)
@activity.defn

View File

@ -1,5 +1,6 @@
from datetime import timedelta
from temporalio import workflow
from temporalio.common import RetryPolicy
with workflow.unsafe.imports_passed_through():
from .activities import (
@ -23,14 +24,14 @@ class ClinicalIntakeWorkflow:
structured_note = await workflow.execute_activity(
structure_note_activity,
raw_dictation,
start_to_close_timeout=timedelta(minutes=10)
retry_policy=RetryPolicy(maximum_attempts=3), start_to_close_timeout=timedelta(minutes=10)
)
# Step 2: Medical Coder (Generate ICD-10/CPT codes)
billing_codes = await workflow.execute_activity(
generate_billing_codes_activity,
structured_note,
start_to_close_timeout=timedelta(minutes=10)
retry_policy=RetryPolicy(maximum_attempts=3), start_to_close_timeout=timedelta(minutes=10)
)
# Step 3: Save to the client's database via ORM
@ -43,7 +44,7 @@ class ClinicalIntakeWorkflow:
save_status = await workflow.execute_activity(
save_clinical_record_activity,
save_payload,
start_to_close_timeout=timedelta(minutes=1)
retry_policy=RetryPolicy(maximum_attempts=3), start_to_close_timeout=timedelta(minutes=1)
)
return {
@ -99,14 +100,14 @@ class LabResultWatcherWorkflow:
anomaly_report = await workflow.execute_activity(
analyze_lab_anomaly_activity,
input_data,
start_to_close_timeout=timedelta(minutes=5)
retry_policy=RetryPolicy(maximum_attempts=3), start_to_close_timeout=timedelta(minutes=5)
)
if anomaly_report.get("is_dangerous", False):
await workflow.execute_activity(
send_alert_activity,
anomaly_report,
start_to_close_timeout=timedelta(minutes=1)
retry_policy=RetryPolicy(maximum_attempts=3), start_to_close_timeout=timedelta(minutes=1)
)
self._alerts.append(anomaly_report)
alerts_triggered += 1
@ -137,7 +138,7 @@ class AppointmentBookingWorkflow:
intent_data = await workflow.execute_activity(
"parse_booking_intent_activity",
self._chat_history,
schedule_to_close_timeout=timedelta(minutes=5)
retry_policy=RetryPolicy(maximum_attempts=3), schedule_to_close_timeout=timedelta(minutes=5)
)
reply_msg = intent_data.get("reply_message", "I can help with that.")
@ -147,7 +148,7 @@ class AppointmentBookingWorkflow:
await workflow.execute_activity(
"send_whatsapp_reply_activity",
{"phone_number": phone_number, "message": reply_msg},
schedule_to_close_timeout=timedelta(minutes=1)
retry_policy=RetryPolicy(maximum_attempts=3), schedule_to_close_timeout=timedelta(minutes=1)
)
# 3. Check if all details are gathered
@ -162,7 +163,7 @@ class AppointmentBookingWorkflow:
"appointment_date": intent_data.get("appointment_date"),
"appointment_time": intent_data.get("appointment_time")
},
schedule_to_close_timeout=timedelta(seconds=30)
retry_policy=RetryPolicy(maximum_attempts=3), schedule_to_close_timeout=timedelta(seconds=30)
)
return intent_data