Skip to content

Conversation

@presstab
Copy link
Owner

Overview

This pull request introduces a new "Research Agent" capable of performing web searches and scraping web content to answer user queries. This agent can be invoked directly via a new /research command or integrated into existing chat threads through a new per-thread web search toggle. The changes enhance the application's ability to gather external information, providing more comprehensive responses to users.

What This Means for Users

Users will now have two primary ways to leverage the new research capabilities:

  • /research <query> command: Users can directly initiate a research task from the command line by typing /research followed by their query. The application will then use the Research Agent to find and summarize information related to the query.
  • Per-thread Web Search Toggle: A new "Web Search" toggle has been added to the chat settings within the UI. When enabled for a specific chat thread, any user input in that thread will first be routed through the Research Agent. This allows the agent to perform web searches and scraping to inform its responses, effectively turning the chat into a research-assisted conversation.
    • The toggle's state is persisted with the thread, meaning if a user enables web search for a thread, it will remain enabled even after closing and reopening the application.
    • A new settings button (⚙) has been added to the chat controls to expand and collapse the chat settings, including the new web search toggle.

A Closer Look at the Changes

This pull request introduces several new components and modifies existing ones to support the research functionality:

  • New ResearchAgent: A new agent (src/jrdev/agents/research_agent.py) has been added. This agent is designed to interpret user input, decide whether to perform a web search, scrape a URL, or summarize gathered information. It operates in an iterative loop, using a dedicated prompt (src/jrdev/prompts/researcher/research_prompt.md) to guide its decision-making process.
  • /research Command: A new command handler (src/jrdev/commands/handle_research.py) has been implemented. This handler orchestrates the interaction with the ResearchAgent, managing the research thread, tool calls (web search and scrape), and presenting the final summary to the user.
  • Web Search Toggle in Chat UI:
    • The ChatViewWidget (src/jrdev/ui/tui/chat/chat_view_widget.py) has been updated to include a new web_search_switch and web_search_label.
    • A new _handle_websearch_toggle function has been added to src/jrdev/commands/thread.py to manage the state of the web search toggle for individual threads.
    • The MessageThread class (src/jrdev/messages/thread.py) now supports additional metadata fields, allowing the web_search_enabled state to be stored and retrieved with each thread.
  • Application Integration:
    • The Application class (src/jrdev/core/application.py) has been updated to route user messages through the handle_research function if web search is enabled for the current thread.
    • The create_thread method in Application now accepts optional meta_data to support initializing threads with specific settings, such as web_search_enabled.
    • The CommandHandler (src/jrdev/core/commands.py) has been updated to register the new /research command.
  • LLM Stream Enhancements: Minor adjustments have been made to src/jrdev/services/streaming/openai_stream.py to improve token estimation.
  • UI Refinements: The GitOverviewWidget (src/jrdev/ui/tui/git/git_overview_widget.py) now clears the commit message textarea after a successful commit, improving the user experience.
    Generated by JrDev AI using google/gemini-2.5-flash

- initialize input_token_estimate to 0 to prevent unbound variable errors
- move len() call to assignment to store the actual token count
- add call to add_use() so usage is persisted even when the final chunk lacks usage data
Introduces ResearchAgent to handle iterative web searches and scraping using LLM decisions, integrates /research command for standalone queries, adds per-thread web search enablement via /thread websearch on|off, and routes chat inputs to the agent when toggled on. Includes UI switch, prompt template, and metadata persistence enhancements.
Introduce a settings button to toggle a dedicated container for project context and web search options, improving UI organization in the chat view widget.
@presstab
Copy link
Owner Author

presstab commented Sep 13, 2025

Overall Impression

This pull request introduces a research agent capability to the jrdev tool, enabling web-based information gathering through natural language queries integrated with the existing chat and command systems. The implementation extends the agentic pipeline with tool-based decisioning and UI toggles, providing a structured way to handle iterative research tasks while maintaining compatibility with thread metadata and streaming responses, which broadens the tool's scope for knowledge-intensive workflows without disrupting core functionality.

Suggestions for Improvement

  • Enhance Error Handling in Tool Execution Loop: In handle_research.py, the try-except block for tool calls captures all exceptions broadly, which could mask specific issues like network timeouts or invalid URLs during web scraping. Consider categorizing exceptions (e.g., using asyncio.TimeoutError for searches and ValueError for argument validation) and providing more granular logging or user feedback, such as retry mechanisms for transient failures, to improve reliability in production use.

  • Clarify Tool Authorization and Scope in ResearchAgent: The interpret method in research_agent.py assumes only web_search and web_scrape_url tools are valid, with a generic error for others, but lacks explicit documentation or enforcement of the tool list from agent_tools. Define a class-level ALLOWED_TOOLS set and validate against it before creating ToolCall objects, preventing unauthorized tool expansions and making the agent's scope more explicit for future extensions or debugging.

  • Address Potential Iteration Limits and Feedback Loops: The research loop in handle_research.py relies on max_iter from user settings, but without intermediate progress indicators beyond tool execution prints, long-running queries could appear unresponsive. Add periodic UI updates (e.g., via app.ui.update_task_info with iteration count) and consider a mechanism to detect redundant tool calls (e.g., duplicate searches) using a simple cache of prior queries, reducing unnecessary API costs and aligning with the tool's cost-optimization philosophy.
    Generated by JrDev AI using openrouter/sonoma-sky-alpha

Add specific exception handling for HTTP status errors, network issues, timeouts, and invalid arguments in tool calls, with improved error messages and logging.
- Switch to `app.state.model` for research tasks instead of fixed `intermediate_reasoning` model
- Define `ALLOWED_TOOLS` as `{"web_search", "web_scrape_url"}` and validate tool names before execution
- Log and abort on unauthorized tool attempts with error messaging
…ch handler

- Introduce sub-task IDs for UI updates during research iterations
- Cache tool call results to skip duplicates and reduce redundancy
- Stream tool feedback to chat threads when available, fallback to terminal prints
@presstab presstab merged commit 0a13caa into master Sep 17, 2025
8 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.

2 participants