Skip to content

Optimize Router Agent Decision-Making and Enhance UI Confirmation Workflows#152

Merged
presstab merged 6 commits into
masterfrom
router_agent_refine
Jun 28, 2026
Merged

Optimize Router Agent Decision-Making and Enhance UI Confirmation Workflows#152
presstab merged 6 commits into
masterfrom
router_agent_refine

Conversation

@presstab

Copy link
Copy Markdown
Owner

Overview

This pull request introduces a series of refinements to the message thread architecture, the router agent's decision-making process, and the user interface. The primary goal is to transition from direct manipulation of thread state to a clean, encapsulated API on the MessageThread class. Additionally, this update optimizes routing logic by establishing a clear policy on when to invoke the heavy /code agent versus performing lightweight, localized edits directly. It also introduces user confirmation prompts before launching coding agents and improves clipboard integration across terminal and chat interfaces.

What This Means for Users

  • Smarter Agent Routing: The assistant will no longer default to launching a heavy coding agent for simple, single-file edits or basic questions. Instead, it will perform localized edits directly, resulting in faster response times and lower token usage.
  • Control Over Coding Agents: Users will now see a clear confirmation prompt before a coding agent is launched, allowing them to approve or cancel the operation.
  • Improved Clipboard & Terminal Experience: Copying text from the terminal or chat bubbles is now more reliable. On Linux systems, copied text is automatically synced to the X11 primary selection, enabling standard terminal paste shortcuts like Shift+Insert.

A Closer Look at the Changes

Code Refinements & Thread Encapsulation

  • Replaced direct list operations on thread.messages and thread.context with dedicated methods on MessageThread (add_message, add_user_message, clear, and clear_context) to ensure consistent state management and automatic persistence.
  • Introduced a robust parse_router_json method in CommandInterpretationAgent to handle LLM responses containing markdown code blocks inside JSON strings, reducing parsing failures.

Router Agent & Input Handler Optimizations

  • Updated the router agent's system prompt (select_command.md) with a strict /code selection policy, guiding it to use direct tools (like write_file) for simple edits and reserve /code for complex, multi-file tasks.
  • Implemented a router_turn_id tracking mechanism to record user requests once per routing turn, preventing duplicate user messages from cluttering the conversation history during multi-step tool executions.

UI & Confirmation Enhancements

  • Generalized the CommandConfirmationWidget into an inline yes/no prompt widget capable of displaying custom titles and questions.
  • Added a prompt_for_yes_no interface to UiWrapper and implemented it across CLI and TUI environments to support interactive user confirmations.
  • Integrated X11 primary selection support in the terminal output widget to improve clipboard compatibility on Linux.

Testing

  • Added comprehensive unit tests in test_message_thread.py and test_router_agent.py to verify thread persistence, idempotent turn recording, and robust JSON parsing.

Generated by JrDev AI using google/gemini-3.5-flash

presstab added 6 commits June 27, 2026 16:04
Introduce `add_message`, `add_user_message`, `clear`, and `clear_context` methods on `MessageThread` to encapsulate state changes. This ensures that thread persistence and metadata updates are consistently handled via the `@auto_persist` decorator, rather than relying on direct list or set mutations by callers.
…+insert paste

- track terminal text selection to preserve copied content across interactions
- add shift+insert keybinding for pasting in the terminal input widget
- implement x11 primary selection support via xclip for linux terminal compatibility
- integrate textual's app-level clipboard api as a fallback alongside pyperclip
…prompt context

Introduces a router_turn_id to track routing iterations and ensure the user's initial request is persisted exactly once. Updates the prompt builder to filter out the request message on subsequent iterations, appending only tool call observations. Adds comprehensive tests for turn tracking and idempotency.
replace cutoff_string utility with a dedicated parse_router_json method
that uses raw_decode to correctly parse json containing embedded markdown
code blocks. add unit test to verify parsing behavior.
…o prompts

- Introduce `prompt_for_yes_no` interface across CLI and TUI wrappers
- Refactor command confirmation widgets to support customizable titles and questions
- Update AI routing instructions to restrict `/code` usage to large, complex tasks
- Implement explicit user confirmation step before executing the `/code` command
Capture the selection on copy button mouse down to prevent losing it when focus changes. Also, fall back to copying all terminal text if no selection is present.
@presstab presstab merged commit 6fa64e9 into master Jun 28, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant