Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(context-agent): move Deep Cody out of model dropdown #6513

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

abeatrix
Copy link
Contributor

@abeatrix abeatrix commented Jan 2, 2025

Adds on #6513
CLOSE https://linear.app/sourcegraph/issue/CODY-4535 https://linear.app/sourcegraph/issue/CODY-4563 https://linear.app/sourcegraph/issue/CODY-4539

Building blocks of https://www.loom.com/share/16b55f92368844b4b766083ed4d30091

This PR introduces a new UI-based approach for managing Cody's agent capabilities, replacing the previous VS Code settings configuration. It also moves Deep Cody out of the model dropdown into its own Agent Settings component

Key Changes

  1. New Agent UI Controls:

    • Added ToolboxButton component in chat input area with:
    • Bot icon indicating agent status (active/inactive)
    • Green pulse animation for active state
    • Popover menu for settings
    • Dedicated switches for agent and terminal features
  2. Deep Cody Architecture Improvements:

    • Simplified agent ID for Deep Cody to 'deep-cody' from previous ModelRef format
    • Added support for model selection between default chat model and Claude 3.5 Haiku
    • Moved shell context permission to UI toggle with warning message
    • Enhanced context handling with deduplication for repeated queries
  3. API & Type Updates:

    • Added toolboxSettings and updateToolboxSettings to WebView API
    • Updated AgentToolboxSettings type to use string-based agent ID
    • Enhanced message types to support agent attribution
    • Added feature flag for chat model selection
  4. Code Organization:

    • Refactored CodyToolProvider into namespace pattern
    • Improved tool factory initialization and management
    • Enhanced test coverage for new UI components
    • Removed deprecated VS Code settings
  5. Default Model

    • Defaulted to use 3.5 Haiku as the reflection model
    • When the ContextAgentDefaultChatModel feature flag is enabled on the instance, reflection model will be set to Sonnet instead
  6. Merge CodyChatAgent with DeepCodyAgent.

  7. Introduce ToolboxManager and AgentToolboxSettings

    • Added a ToolboxManager class to centralize the management of agent toolbox settings, including the terminal/shell context.
    • Introduced the AgentToolboxSettings interface to represent the user's preferences for the agent and terminal context.
    • Integrated the ToolboxManager into the ChatController to update the user's terminal context setting based on the configuration.
    • Persisted the agent and terminal context settings in the local storage for user-specific preferences.
    • ToolboxManager settings for terminal context gets updated on user config changes
  8. Improve prompt and response format for context review

    • Enhance the review prompt to provide clearer instructions and the expected response format.
    • Add new tags for context and answers to standardize the response structure.
    • Provide examples of valid and invalid responses to guide the user.
    • Update the prompt to emphasize the importance of only including the expected tags in the response.
    • Integrate the ToolboxManager into the ChatController to update the user's terminal context setting based on the configuration.
    • Persist the agent and terminal context settings in the local storage for user-specific preferences.
  9. Improve context retrieval for deep-cody / context agent

    • send context to webview for display before sending the request
    • update context retrieval to only include validated context items that match the end of the path
    • post empty message in progress when processing steps are updated

TO-DO

Will be continued in follow-ups:

  • Update Deep Cody Notice / upsell with the new changes
  • Remove Deep Cody rate limit
  • Update Agentic context UI
  • Update New toolbox setting UI

Test plan

Updated all existing unit tests and added new unit tests to cover all the Deep Cody components.

Deep Cody should work as it does currently:

Example Question: how many files are there in the root of my codebase? Find where PromptSelectField is defined in the codebase

image

In UI, enabling the Terminal Context Agent would enable terminal context

image

In UI, disabling the Terminal Context Agent would disable terminal context

image

  1. Agent Controls:

    • Verify bot icon appears in chat input
    • Check icon states (active/inactive)
    • Confirm green pulse animation when active
    • Test settings popover interaction
  2. Settings Management:

    • Enable/disable agent via toggle
    • Toggle terminal access (when available)
    • Verify warning message for terminal access
    • Confirm settings persist across sessions
  3. Chat Experience:

    • Test chat with agent enabled/disabled
    • Verify model selection works correctly
    • Check context gathering improvements
    • Confirm terminal integration (when enabled)
  4. Settings Transition:

    • Verify existing setting is not respected and is marked as deprecated
    • The Terminal context is disabled by default in the new UI component
    • Test default states as PLG and Enterprise users
    • Check settings sync behavior

Changelog

## 1.  introduce ToolboxManager and AgentToolboxSettings

This change introduces the following improvements to the Cody chat agent system:

1. Added a `ToolboxManager` class to centralize the management of agent toolbox settings, including the terminal/shell context.
2. Introduced the `AgentToolboxSettings` interface to represent the user's preferences for the agent and terminal context.
3. Integrated the `ToolboxManager` into the `ChatController` to update the user's terminal context setting based on the configuration.
4. Persisted the agent and terminal context settings in the local storage for user-specific preferences.

## 2. improve prompt and response format for context review

- Enhance the review prompt to provide clearer instructions and expected response format
- Add new tags for context and answer to standardize the response structure
- Provide examples of valid and invalid responses to guide the user
- Update the prompt to emphasize the importance of only including the expected tags in the response
- AgentToolboxSettings
This change introduces the following improvements to the Cody chat agent system:

1. Enhance the review prompt to provide clearer instructions and expected response format.
2. Add new tags for context and answer to standardize the response structure.
3. Provide examples of valid and invalid responses to guide the user.
4. Update the prompt to emphasize the importance of only including the expected tags in the response.
5. Integrate the ToolboxManager into the ChatController to update the user's terminal context setting based on the configuration.
6. Persist the agent and terminal context settings in the local storage for user-specific preferences.
This change updates the user's terminal context setting in the ToolboxManager based on the configuration changes. Specifically:

- Integrate the ToolboxManager into the ChatsController to update the user's terminal context setting when the configuration changes
- Persist the updated terminal context setting in the local storage for user-specific preferences
Copy link

github-actions bot commented Jan 2, 2025

‼️ Hey @sourcegraph/cody-security, please review this PR carefully as it introduces the usage of an unsafe_ function or abuses PromptString.

@abeatrix abeatrix requested review from beyang and a team January 3, 2025 01:03
- skip query rewrite for deep-cody models as it will be reviewed by the agent. This was the default behavior before the handler migration that removed this option (by accident?)
- send context to webview for display before sending the request
- update context retrieval to only include validated context items that match the end of the path
- post empty message in progress when processing steps are updated
@abeatrix abeatrix force-pushed the bee/context-agent-cleanup branch from 0787c6e to eb73c68 Compare January 3, 2025 12:28
Copy link
Member

@valerybugakov valerybugakov left a comment

Choose a reason for hiding this comment

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

Went through half of it. Will complete my review tomorrow morning!

Adds on #6513

This PR introduces a new UI-based approach for managing Cody's agent
capabilities, replacing the previous VS Code settings configuration. It
also moves Deep Cody out of the model dropdown into its own Agent
Settings component

## Key Changes

1. New Agent UI Controls:
   - Added `ToolboxButton` component in chat input area with:
     - Bot icon indicating agent status (active/inactive)
     - Green pulse animation for active state
     - Popover menu for settings
     - Dedicated switches for agent and terminal features

2. Deep Cody Architecture Improvements:
- Simplified agent ID for Deep Cody to 'deep-cody' from previous
ModelRef format
- Added support for model selection between default chat model and
Claude 3.5 Haiku
   - Moved shell context permission to UI toggle with warning message
   - Enhanced context handling with deduplication for repeated queries

3. API & Type Updates:
   - Added `toolboxSettings` and `updateToolboxSettings` to WebView API
   - Updated `AgentToolboxSettings` type to use string-based agent ID
   - Enhanced message types to support agent attribution
   - Added feature flag for chat model selection

4. Code Organization:
   - Refactored `CodyToolProvider` into namespace pattern
   - Improved tool factory initialization and management
   - Enhanced test coverage for new UI components
   - Removed deprecated VS Code settings

5. Default Model
   - Defaulted to use 3.5 Haiku as the reflection model
- When the `ContextAgentDefaultChatModel` feature flag is enabled on the
instance, reflection model will be set to Sonnet instead


## TO-DO

- [ ] Update Deep Cody Notice / upsell with the new changes
- [ ] Remove Deep Cody rate limit

## Test plan

<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->

1. Agent Controls:
   - [ ] Verify bot icon appears in chat input
   - [ ] Check icon states (active/inactive)
   - [ ] Confirm green pulse animation when active
   - [ ] Test settings popover interaction

2. Settings Management:
   - [ ] Enable/disable agent via toggle
   - [ ] Toggle terminal access (when available)
   - [ ] Verify warning message for terminal access
   - [ ] Confirm settings persist across sessions

3. Chat Experience:
   - [ ] Test chat with agent enabled/disabled
   - [ ] Verify model selection works correctly
   - [ ] Check context gathering improvements
   - [ ] Confirm terminal integration (when enabled)

4. Settings Transition:
- [ ] Verify existing setting is not respected and is marked as
deprecated
- [ ] The Terminal context is disabled by default in the new UI
component
   - [ ] Test default states as PLG and Enterprise users
   - [ ] Check settings sync behavior

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
Copy link
Member

@valerybugakov valerybugakov left a comment

Choose a reason for hiding this comment

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

A few notes from the interaction I tested:

  1. The context row in the UI shows "none fetched," but there are two items with green check marks under the collapsible context section.
  2. The green check marks suggest that context was successfully retrieved, but the output channel logs show errors when attempting to use the SearchTool.
  3. And the obvious: the output doesn’t match what’s shown in the screenshot from the PR description. Cody couldn’t use the tools, and as a user, I don’t understand why that happened.
outputChannelId:"16472d3f-0a82-4a46-9f8f-dbbdd5bd2e34": {
  "completion": "<TOOLFILE><name>.</name></TOOLFILE><TOOLSEARCH><query>promptselectfield</query></TOOLSEARCH>"
}
█ CodyTool requesting 1 files
█ SearchTool searching codebase for promptselectfield
█ getContextFileFromUri failed: {
  "name": "CodeExpectedError",
  "message": "cannot open file:///Users/val/Desktop/sourcegraph-root/cody-chat-eval. Detail: Unable to read file '/Users/val/Desktop/sourcegraph-root/cody-chat-eval' (Error: Unable to read file '/Users/val/Desktop/sourcegraph-root/cody-chat-eval' that is actually a directory)"
}
Screenshot 2025-01-06 at 10 28 10

Copy link
Member

@valerybugakov valerybugakov left a comment

Choose a reason for hiding this comment

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

Checkmarks on the context items in the light theme have an odd shadow that seems out of place:

Screenshot 2025-01-06 at 10 33 30

Copy link
Member

@valerybugakov valerybugakov left a comment

Choose a reason for hiding this comment

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

Is it intentional that the agent icon is noticeably lighter than the "Open in Editor" icon?

Screenshot 2025-01-06 at 10 36 51

@abeatrix
Copy link
Contributor Author

abeatrix commented Jan 6, 2025

Thanks for testing this out!

@valerybugakov are you in the cody report when you run the question? Do you have any file opened in your editor? (Our search only works if you have file from the codebase opened in your editor, not an issue with deep cody since deep cody is just reusing our search).

For the second issue where file fetch failed - Since you don't have terminal setting enabled it fallback to use file search and search for all (".") so that's why it failed (will work on integrating the error next). Right now, the icon on the left only show you that it run the tools but it doesn't tell you how many files it fetch, which is what the none fetch is for (we will move from this UI soon).

Copy link
Member

@valerybugakov valerybugakov left a comment

Choose a reason for hiding this comment

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

This PR is pretty big, with many independent parts being updated simultaneously, which makes it much harder to review, especially for engineers who aren't working full-time on Deep Cody. Based on the sections in the PR description, it could be split into around nine smaller, independent PRs that we can merge and roll back separately if needed.

Sharing one of my earlier comments on this topic for more context on why this approach is helpful: #6066 (review).

It might seem like a lot of extra work, but by stacking PRs and iterating quickly on reviews, we can merge small chunks of functionality much faster while reducing the risk of breaking the release candidate. Let's give that a try for the upcoming changes!

lib/shared/src/configuration.ts Outdated Show resolved Hide resolved
lib/shared/src/configuration.ts Outdated Show resolved Hide resolved
lib/shared/src/configuration.ts Outdated Show resolved Hide resolved
lib/shared/src/configuration.ts Outdated Show resolved Hide resolved
vscode/src/chat/agentic/DeepCody.ts Outdated Show resolved Hide resolved
@abeatrix abeatrix force-pushed the bee/context-agent-cleanup branch from 4a6cacb to 9583a67 Compare January 6, 2025 19:18
@abeatrix abeatrix force-pushed the bee/context-agent-cleanup branch from 0fda5f5 to ec66e6e Compare January 6, 2025 22:06
@abeatrix abeatrix force-pushed the bee/context-agent-cleanup branch from ec66e6e to c8dfcb2 Compare January 6, 2025 22:27
@abeatrix abeatrix force-pushed the bee/context-agent-cleanup branch from c8dfcb2 to 2e5d77e Compare January 7, 2025 00:39
@abeatrix abeatrix changed the title feat(context-agent): introduce ToolboxManager and AgentToolboxSettings feat(context-agent): move Deep Cody out of model dropdown Jan 7, 2025
@abeatrix abeatrix force-pushed the bee/context-agent-cleanup branch from 95d87ab to 0d55e7c Compare January 7, 2025 01:08
@abeatrix abeatrix requested a review from valerybugakov January 7, 2025 02:19
@abeatrix abeatrix force-pushed the bee/context-agent-cleanup branch 3 times, most recently from b529c9f to 3eed255 Compare January 7, 2025 04:58
@abeatrix abeatrix force-pushed the bee/context-agent-cleanup branch from 3eed255 to 321da9a Compare January 7, 2025 05:08
Copy link
Member

@valerybugakov valerybugakov left a comment

Choose a reason for hiding this comment

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

Thank you for addressing all the comments, @abeatrix! You rock! 🤘

Comment on lines 276 to 279
// Create a new controller that will be triggered when the parent signal aborts
const controller = new AbortController()
// Listen to parent signal and abort new controller when it aborts
parentSignal?.addEventListener('abort', () => controller.abort())
Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's perfect! We have a couple of helpers in the codebase to do that. Search for dependentAbortController or forkSignal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

replaced it with forkSignal. Thank you so much!

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