# agent_ui: Show controls after every agent message \(\#61245\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/f032f4d433da3747f9d7bcc9e9cd52d6ca3fb3e4)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: f032f4d433da3747f9d7bcc9e9cd52d6ca3fb3e4

Requested commit: f032f4d433da3747f9d7bcc9e9cd52d6ca3fb3e4

Commit: f032f4d433da3747f9d7bcc9e9cd52d6ca3fb3e4

Tree: bc5e231b224529baeb1a3cc2c8ea54eff8ac21ad

Author: Yifeng Xu

Committer: GitHub

## Message

```
agent_ui: Show controls after every agent message (#61245)

# Objective

Fixes #61244 

In the Agent Panel, after a multi-turn conversation, the action buttons
("Copy this Agent response", "Scroll to User Message", and "Scroll to
top") were only shown after the last assistant response. This was
inconvenient for users who wanted to copy or navigate from earlier
responses.

Additionally, the "Scroll to User Message" button always jumped to the
most recent user message in the entire thread, even when clicked from a
historical assistant response.

This PR addresses both issues by rendering the controls after every
non-blank assistant response, and by making "Scroll to User Message"
jump to the user prompt associated with that specific response.

## Solution

- Refactored `render_thread_controls` in
`crates/agent_ui/src/conversation_view/thread_view.rs` to accept an
explicit `entry_ix`, `copy_response_index`, `is_thread_bottom`, and
`user_message_index`, making it reusable per assistant message.
- Rendered the control bar after each non-blank `AssistantMessage`
entry, not just the last entry.
- Made button IDs unique by using tuple IDs like `("name", entry_ix)`,
matching the existing style in this file and avoiding `format!`
allocations.
- Keyed the copy button ID by the control bar location (`entry_ix`)
while still copying `response_index`'s content, so the bottom fallback
bar doesn't duplicate IDs with the per-response bar.
- Gated the generation/confirmation early return to `is_thread_bottom`,
so historical controls remain accessible while the thread is generating
or waiting for confirmation.
- Gated turn stats and thread feedback buttons to the bottom of the
thread so they only appear on the last response.
- Replaced `scroll_to_most_recent_user_prompt` with a more general
`scroll_to_user_message_index` that takes an optional target user
message index.
- For each per-response button, computed the associated user message
index as the most recent user message before that assistant response.
- For the bottom fallback (when the last entry is not an assistant
message), passed `None` so the button still scrolls to the most recent
user message.
- Updated the tooltip from "Scroll to Most Recent User Message" to
"Scroll to User Message".
- Updated existing tests and added assertions for
`scroll_to_user_message_index(Some(ix), cx)`.

## Testing

- `cargo check -p agent_ui`
- `./script/clippy -p agent_ui`
- `cargo test -p agent_ui --lib` (399 passed)
- Added assertions in `test_scroll_to_most_recent_user_prompt` to verify
`scroll_to_user_message_index(Some(0), cx)` and
`scroll_to_user_message_index(Some(2), cx)` scroll to the correct user
message indices.
- Manual testing recommended: open the Agent Panel, send multiple
messages, and verify that each assistant response has the three buttons
and that "Scroll to User Message" jumps to the corresponding user
prompt.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments (no unsafe blocks)
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

## Showcase

Before: Only the last assistant response in the Agent Panel showed the
"Copy this Agent response", "Scroll to User Message", and "Scroll to
top" buttons. Clicking "Scroll to User Message" always jumped to the
most recent user message.

After: Every non-blank assistant response displays these buttons.
Clicking "Scroll to User Message" on a historical response scrolls to
the user prompt that triggered that specific response.


https://github.com/user-attachments/assets/46e02bcc-8bed-4cf3-a08a-9ef91a206d08

---

Release Notes:

- Added "Copy this Agent response", "Scroll to User Message", and
"Scroll to top" buttons to every agent response in the Agent Panel.
- Fixed "Scroll to User Message" so it jumps to the user prompt
associated with the current response, rather than the most recent user
message.
```

## Parents

- [edeaf598c7495bd7b9e9a05d68e61f08ad275d16](https://git.cafe/gitcafe/zed/commit/edeaf598c7495bd7b9e9a05d68e61f08ad275d16?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/f032f4d433da3747f9d7bcc9e9cd52d6ca3fb3e4?format=markdown)
