Hi all — we’re building a drag-and-drop interface ...
# agents
m
Hi all — we’re building a drag-and-drop interface that allows users of our AI receptionist to create fully custom call workflows. There are two main kinds of steps the user can configure: Information-gathering steps — the agent must elicit a specific piece of info before moving on (eg. it cant move on to medical history without confirming name and DOB) Handoff requirements: This can include phrases like "I absolutely do not want to speak to an AI" "I have to speak to a human" and/or Red-flag conditions — if the patient has any red flag symptoms, then the call should be handed off to a human. This can also include other specific bits of information in the patient history that would necessitate a handoff We’re considering using LiveKit Agent Workflows to power this. The question is: if the user adds a new “step box” in the UI (i.e., a new required info step), is there a way to have this automatically generate or modify the agent’s workflow without requiring the user to write any code? Essentially, we’re looking for the best pattern to dynamically generate/update agent workflows from a visual editor. Would this mean generating new agents on the fly, or creating specific textfields that populate e.g. “instructions” variables on the agent Any guidance or examples would be super helpful — thanks!
p
generating new agents on the fly means you'd be doing that on each update to the workflow. this approach doesn't sound scalable, just to dynamically update workflows. consider populating placeholders within the agent code. which the user can configure to update the workflow. doesn't require user to write any code.
m
I think you could get away with a single agent and then dynamically generate tasks (not workflows) by looping through all stored steps from a DB and setting the instructions on the fly
Copy code
# --- 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 tasks
if you’re having to do more complex routing then perhaps dynamic workers would be a better approach but things like handover can be defined as a tool at the agent level and then called at the task level