Skip to content

feat: add auto_collapse parameter to Step#2818

Merged
hayescode merged 2 commits intoChainlit:mainfrom
Br1an67:fix/issue-2081-collapse-step
Mar 5, 2026
Merged

feat: add auto_collapse parameter to Step#2818
hayescode merged 2 commits intoChainlit:mainfrom
Br1an67:fix/issue-2081-collapse-step

Conversation

@Br1an67
Copy link
Contributor

@Br1an67 Br1an67 commented Mar 1, 2026

What

Add auto_collapse parameter to Step that automatically collapses the step accordion when it finishes.

Closes #2081

Why

Long tool steps stream lots of tokens. After completion, developers want to signal "done" and reduce UI clutter by collapsing the step automatically.

Changes

  • backend/chainlit/step.py: Add auto_collapse: Optional[bool] = False to StepDict and Step class, include in to_dict()
  • libs/react-client/src/types/step.ts: Add autoCollapse?: boolean to IStep
  • frontend/src/components/chat/Messages/Message/Step.tsx: Switch accordion from uncontrolled to controlled mode, auto-collapse via useEffect when step finishes and autoCollapse is set

Usage

async with cl.Step(name="web_search", default_open=True, auto_collapse=True) as step:
    step.output = "Searching..."
    await step.update()
    # ... do work ...
    step.output = result
# Step auto-collapses when context exits

Testing

  • Steps without auto_collapse behave identically (backward compatible)
  • Accordion remains user-interactive: users can expand/collapse after auto-collapse
  • defaultOpen still respected for initial state

Summary by cubic

Add auto-collapse to steps so finished steps automatically fold to reduce UI clutter. Keeps manual control and default open behavior; step() decorator now forwards the flag; no breaking changes.

  • New Features
    • Added auto_collapse (Python) / autoCollapse (TS) to Step, serialization, and step() decorator forwarding.
    • Switched the step accordion to controlled mode and collapse on finish when autoCollapse is true.
    • Backward compatible: defaultOpen still sets initial state, and users can toggle after auto-collapse.

Written for commit a1158f3. Summary will update on new commits.

…letion

Add auto_collapse option to Step that automatically collapses the step
accordion when the step finishes. The accordion is now controlled so
users can still manually expand/collapse after auto-collapse.
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. backend Pertains to the Python backend. frontend Pertains to the frontend. labels Mar 1, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/chainlit/step.py">

<violation number="1" location="backend/chainlit/step.py:203">
P2: auto_collapse is added to Step but the step() decorator does not accept or forward it, so decorated steps cannot opt into auto-collapse.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@hayescode hayescode enabled auto-merge March 5, 2026 17:29
@hayescode hayescode added this pull request to the merge queue Mar 5, 2026
Merged via the queue into Chainlit:main with commit 20fc6f9 Mar 5, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Pertains to the Python backend. frontend Pertains to the frontend. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FR : Programmatically Collapse a Step (step.close() or step.status = "finished")

2 participants