most-jewelry-78743
10/27/2025, 9:33 PMprehistoric-alligator-43413
10/27/2025, 10:03 PMmagnificent-salesclerk-38445
10/28/2025, 9:01 AMmagnificent-salesclerk-38445
10/28/2025, 9:03 AM# --- Imagine this is your DB call ---
def get_task_instructions_from_db(limit=5):
"""
Fetch a list of task instruction strings from the database.
Each record might have fields like: id, name, instructions.
"""
# Example placeholder data from DB
return [
{"name": "CollectConsent", "instructions": "Ask for recording consent politely."},
{"name": "CollectName", "instructions": "Ask the caller for their full name."},
{"name": "CollectEmail", "instructions": "Ask the caller for their email address."},
{"name": "CollectReason", "instructions": "Ask why the caller is contacting today."},
{"name": "CollectAvailability", "instructions": "Ask what time suits them for an appointment."},
][:limit]
# --- Generic dynamic AgentTask class ---
class DynamicAgentTask(AgentTask[str]):
def __init__(self, name: str, instructions: str, chat_ctx=None):
super().__init__(instructions=instructions, chat_ctx=chat_ctx)
self.name = name
async def on_enter(self):
# Send initial message when the task starts
await self.session.generate_reply(instructions=f"Task '{self.name}' started.")
# --- Main flow to create 5 tasks ---
async def load_tasks(chat_ctx=None) -> List[AgentTask]:
task_records = get_task_instructions_from_db(limit=5)
tasks = []
for record in task_records:
task = DynamicAgentTask(
name=record["name"],
instructions=record["instructions"],
chat_ctx=chat_ctx,
)
tasks.append(task)
return tasksmagnificent-salesclerk-38445
10/28/2025, 9:07 AM