Steps & reasoning
Steps show work in progress (a search, a tool call, a booking) and reasoning shows the model’s thinking, both without cluttering the answer. Use them whenever a reply takes more than a moment.
The snippets below are fragments that assume an app and ui; the complete example is a whole file.
chat.step() renders a live step in the reply. It moves from running to done (or error) and shows how long it took.
@app.on_messageasync def reply(msg, chat): async with chat.step("Searching flights", type="search") as step: step.input = {"from": "LHR", "to": "LIS"} await step.log("Querying 4 airlines") step.output = await search_flights("LHR", "LIS") yield ui.Table(["Airline", "Depart", "Price"], to_rows(step.output))| Member | Purpose |
|---|---|
title, type |
The label and a free-form kind (tool, search, code…) |
step.input, step.output |
Shown when the step is expanded. Any JSON-serializable value; pydantic models are dumped. |
await step.log(text) |
Appends a log line, shown when expanded |
If an exception escapes the block, the step is marked error, its message becomes the output, and the exception is re-raised. If the user presses stop while the step runs, it also ends in the error state.
chat.step also works as a decorator. The wrapped function’s arguments become the input and its return value the output:
async def reply(msg, chat): @chat.step("Geocode city", type="tool") async def geocode(city: str): return await lookup(city)
coords = await geocode(msg.text)You can also render a step that you control yourself: ui.Step("Indexing", "running", id="idx"), then yield it again with the same id and status="done".
Reasoning
Section titled “Reasoning”Yield dyui.Reasoning(text) deltas, and DyUI collects them into a collapsible “thinking” block that records how long it took:
yield dyui.Reasoning("Comparing departure times… ")yield dyui.Reasoning("Friday evening keeps Saturday free.")yield "TAP at 18:05 is the best fit."dyui.llm.stream does this for you. Anthropic thinking deltas, and the reasoning fields that OpenAI-compatible providers send, arrive as Reasoning. The LangGraph adapter forwards thinking blocks the same way.
Reasoning and steps are not included in chat.history, so they don’t cost tokens on later turns.
For multi-step agents, the plan component shows a live checklist. Yield it with a stable id and update item statuses as work progresses:
items = [ui.PlanItem("Find flights", "active"), ui.PlanItem("Shortlist hotels"), ui.PlanItem("Build itinerary")]yield ui.Plan(*items, title="Planning your trip", id="plan")Complete example
Section titled “Complete example”A live plan, a step with input, logs and output, the decorator form, and a reasoning block. It needs no API key.
"""Live steps (context manager and decorator), a reasoning block and a live plan.
Save as app.py, then run: dyui run app.py"""import asyncio
import dyuifrom dyui import ui
app = dyui.App(title="Trip Planner", starters=["Plan a weekend in Lisbon"])
FLIGHTS = [["TAP", "Fri 18:05", "$189"], ["easyJet", "Fri 06:50", "$142"]]
async def search_flights(origin: str, dest: str) -> list[list[str]]: await asyncio.sleep(0.3) # call a real API here return FLIGHTS
@app.on_messageasync def reply(msg: dyui.Message, chat: dyui.Chat): items = [ui.PlanItem("Find flights", "active"), ui.PlanItem("Pick the best one"), ui.PlanItem("Build itinerary")] yield ui.Plan(*items, title="Planning your trip", id="plan")
async with chat.step("Searching flights", type="search") as step: step.input = {"from": "LHR", "to": "LIS"} await step.log("Querying 2 airlines") step.output = await search_flights("LHR", "LIS") yield ui.Table(["Airline", "Depart", "Price"], step.output)
items[0].status, items[1].status = "done", "active" yield ui.Plan(*items, title="Planning your trip", id="plan") # same id: updated in place
yield dyui.Reasoning("Comparing departure times… ") yield dyui.Reasoning("Friday evening keeps Saturday free.")
@chat.step("Geocode city", type="tool") # the decorator form: args become input, return the output async def geocode(city: str) -> dict: await asyncio.sleep(0.1) return {"city": city, "lat": 38.72, "lon": -9.14}
await geocode("Lisbon") items[1].status, items[2].status = "done", "done" yield ui.Plan(*items, title="Planning your trip", id="plan") yield "TAP at 18:05 is the best fit."-
Save it as
app.pyin a new, empty file, or download app.py. -
Run it:
Terminal window pip install dyuidyui run app.py -
Open http://localhost:8000, send the starter, and expand the steps.
See also
Section titled “See also”- Messages & streaming: everything else a handler can yield.
- LangGraph: steps and components from inside an agent.