Skip to content

Support bot

You’ll build a scripted support flow with no model and no API key: a form collects the order number and the issue, the submission arrives in @app.on_action("open_ticket"), two live steps show the lookup, and a plan and sources close the turn.

  • pip install dyui
  • No API key.
  1. Save the code below as support_bot.py in a new, empty file, or download support_bot.py.

  2. Run it:

    Terminal window
    pip install dyui
    dyui run support_bot.py
  3. Open http://localhost:8000. Click My order has not arrived, fill in the form and submit it.

  • action.values holds the form’s field values, keyed by field name.
  • chat.step(...) shows each lookup as it runs.
  • No model is involved. To put one in charge, replace the scripted parts with dyui.llm.stream(...): the model can render the same form itself, and an unhandled form_submit comes back to it as a message.
support_bot.py
"""Support bot: collects details with a form, shows a plan, cites sources, and reports live steps."""
import asyncio
import dyui
from dyui import ui
app = dyui.App(
title="Support Desk",
description="Tell us what is wrong and we will sort it out.",
starters=["My order has not arrived", "I want a refund"],
)
@app.on_message
async def reply(msg: dyui.Message, chat: dyui.Chat):
yield "Sorry about that. I need a few details first."
yield ui.Form(
title="Order details",
fields=[
{"name": "order_id", "label": "Order number", "type": "text", "required": True, "placeholder": "A-1042"},
{"name": "issue", "label": "What happened?", "type": "select",
"options": ["Late delivery", "Damaged item", "Wrong item"]},
{"name": "notes", "label": "Anything else?", "type": "textarea"},
],
submit_label="Open ticket",
action="open_ticket",
)
@app.on_action("open_ticket")
async def open_ticket(action: dyui.Action, chat: dyui.Chat):
order = action.values.get("order_id", "?")
async with chat.step("Looking up order", type="search") as s:
s.input = {"order_id": order}
await asyncio.sleep(0.8)
s.output = {"status": "in transit", "eta": "2 days"}
async with chat.step("Checking carrier status", type="tool"):
await asyncio.sleep(0.8)
yield f"Order **{order}** is in transit and should arrive in two days. Here is what happens next."
yield ui.Plan(title="Resolution plan", items=[
{"title": "Ticket opened", "status": "done"},
{"title": "Carrier contacted", "status": "active"},
{"title": "Refund if not delivered by Friday", "status": "pending"},
])
yield ui.Sources(items=[
{"title": "Shipping policy", "url": "https://example.com/shipping", "snippet": "Delivery takes 3-7 days."},
{"title": "Refund policy", "url": "https://example.com/refunds"},
])
  • Look the order up in your database inside the steps.
  • Ask for a rating at the end with await chat.ask(ui.Rating("How did we do?")).

DyUI Docs assistant

Answers come from the DyUI docs. gpt-oss-120b via Groq. Press Escape or the close button to return to the page.