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

Merged
merged 24 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data class SerializedChatMessage(
val intent: IntentEnum? = null, // Oneof: search, chat, edit, insert
abeatrix marked this conversation as resolved.
Show resolved Hide resolved
val manuallySelectedIntent: ManuallySelectedIntentEnum? = null, // Oneof: search, chat, edit, insert
val search: Any? = null,
val agent: String? = null,
val processes: List<ProcessingStep>? = null,
) {

Expand Down
1 change: 1 addition & 0 deletions lib/shared/src/chat/transcript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ export function serializeChatMessage(chatMessage: ChatMessage): SerializedChatMe
manuallySelectedIntent: chatMessage.manuallySelectedIntent,
search: chatMessage.search,
processes: chatMessage.processes,
agent: chatMessage.agent,
}
}
2 changes: 2 additions & 0 deletions lib/shared/src/chat/transcript/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface ChatMessage extends Message {
intent?: 'search' | 'chat' | 'edit' | 'insert' | undefined | null
manuallySelectedIntent?: 'search' | 'chat' | 'edit' | 'insert' | undefined | null
search?: ChatMessageSearch | undefined | null
agent?: string
processes?: ProcessingStep[] | undefined | null
}

Expand Down Expand Up @@ -101,6 +102,7 @@ export interface SerializedChatMessage {
intent?: ChatMessage['intent']
manuallySelectedIntent?: ChatMessage['manuallySelectedIntent']
search?: ChatMessage['search']
agent?: string
processes?: ProcessingStep[] | undefined | null
}

Expand Down
12 changes: 12 additions & 0 deletions lib/shared/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,15 @@ export interface FireworksCodeCompletionParams {
languageId: string
user: string | null
}

export interface AgentToolboxSettings {
/**
* The agent ID that they user has currently enabled..
abeatrix marked this conversation as resolved.
Show resolved Hide resolved
*/
agent?: string
abeatrix marked this conversation as resolved.
Show resolved Hide resolved
/**
* Whether the user has enabled terminal context.
* Defaulted to undefined if shell context is not enabled by site admin via feature flag.
*/
shell?: boolean
abeatrix marked this conversation as resolved.
Show resolved Hide resolved
abeatrix marked this conversation as resolved.
Show resolved Hide resolved
}
3 changes: 3 additions & 0 deletions lib/shared/src/experimentation/FeatureFlagProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ export enum FeatureFlag {
/** Enable Shell Context for Deep Cody */
DeepCodyShellContext = 'deep-cody-shell-context',

/** Whether Context Agent (Deep Cody) should use the default chat model or 3.5 Haiku */
ContextAgentDefaultChatModel = 'context-agent-use-default-chat-model',

/** Enable Rate Limit for Deep Cody */
DeepCodyRateLimitBase = 'deep-cody-experimental-rate-limit',
DeepCodyRateLimitMultiplier = 'deep-cody-experimental-rate-limit-multiplier',
Expand Down
19 changes: 18 additions & 1 deletion lib/shared/src/misc/rpc/webviewAPI.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Observable } from 'observable-fns'
import type { AuthStatus, ModelsData, ResolvedConfiguration, UserProductSubscription } from '../..'
import type {
AgentToolboxSettings,
AuthStatus,
ModelsData,
ResolvedConfiguration,
UserProductSubscription,
} from '../..'
import type { SerializedPromptEditorState } from '../..'
import type { ChatMessage, UserLocalHistory } from '../../chat/transcript/messages'
import type { ContextItem, DefaultContext } from '../../codebase-context/messages'
Expand Down Expand Up @@ -104,6 +110,15 @@ export interface WebviewToExtensionAPI {
* The current user's product subscription information (Cody Free/Pro).
*/
userProductSubscription(): Observable<UserProductSubscription | null>

/**
* The current user's toolbox settings.
*/
toolboxSettings(): Observable<AgentToolboxSettings | null>
/**
* Update the current user's toolbox settings.
*/
updateToolboxSettings(settings: AgentToolboxSettings): Observable<void>
}

export function createExtensionAPI(
Expand Down Expand Up @@ -138,6 +153,8 @@ export function createExtensionAPI(
transcript: proxyExtensionAPI(messageAPI, 'transcript'),
userHistory: proxyExtensionAPI(messageAPI, 'userHistory'),
userProductSubscription: proxyExtensionAPI(messageAPI, 'userProductSubscription'),
toolboxSettings: proxyExtensionAPI(messageAPI, 'toolboxSettings'),
updateToolboxSettings: proxyExtensionAPI(messageAPI, 'updateToolboxSettings'),
}
}

Expand Down
64 changes: 0 additions & 64 deletions lib/shared/src/models/sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,70 +462,6 @@ describe('syncModels', () => {
}
)

it('sets DeepCody as default chat model when feature flag is enabled', async () => {
const serverSonnet: ServerModel = {
modelRef: 'anthropic::unknown::sonnet',
displayName: 'Sonnet',
modelName: 'anthropic.claude-3-5-sonnet',
capabilities: ['chat'],
category: 'balanced' as ModelCategory,
status: 'stable',
tier: 'enterprise' as ModelTier,
contextWindow: {
maxInputTokens: 9000,
maxOutputTokens: 4000,
},
}

const SERVER_MODELS: ServerModelConfiguration = {
schemaVersion: '0.0',
revision: '-',
providers: [],
models: [serverSonnet],
defaultModels: {
chat: serverSonnet.modelRef,
fastChat: serverSonnet.modelRef,
codeCompletion: serverSonnet.modelRef,
},
}

const mockFetchServerSideModels = vi.fn(() => Promise.resolve(SERVER_MODELS))
vi.mocked(featureFlagProvider).evaluatedFeatureFlag.mockReturnValue(Observable.of(true))

const result = await firstValueFrom(
syncModels({
resolvedConfig: Observable.of({
configuration: {},
clientState: { modelPreferences: {} },
} satisfies PartialDeep<ResolvedConfiguration> as ResolvedConfiguration),
authStatus: Observable.of(AUTH_STATUS_FIXTURE_AUTHED),
configOverwrites: Observable.of(null),
clientConfig: Observable.of({
modelsAPIEnabled: true,
} satisfies Partial<CodyClientConfig> as CodyClientConfig),
fetchServerSideModels_: mockFetchServerSideModels,
userProductSubscription: Observable.of({ userCanUpgrade: true }),
}).pipe(skipPendingOperation())
)

const storage = new TestLocalStorageForModelPreferences()
modelsService.setStorage(storage)
mockAuthStatus(AUTH_STATUS_FIXTURE_AUTHED)
expect(storage.data?.[AUTH_STATUS_FIXTURE_AUTHED.endpoint]!.selected.chat).toBe(undefined)
vi.spyOn(modelsService, 'modelsChanges', 'get').mockReturnValue(Observable.of(result))

// Check if Deep Cody model is in the primary models list.
expect(result.primaryModels.some(model => model.id.includes('deep-cody'))).toBe(true)

// Deep Cody should not replace the default chat / edit model.
expect(result.preferences.defaults.chat?.includes('deep-cody')).toBe(false)
expect(result.preferences.defaults.edit?.includes('deep-cody')).toBe(false)

// preference should not be affected and remains unchanged as this is handled in a later step.
expect(result.preferences.selected.chat).toBe(undefined)
expect(storage.data?.[AUTH_STATUS_FIXTURE_AUTHED.endpoint]!.selected.chat).toBe(undefined)
})

describe('model selection based on user tier and feature flags', () => {
const serverHaiku: ServerModel = {
modelRef: 'anthropic::unknown::claude-3-5-haiku',
Expand Down
89 changes: 28 additions & 61 deletions lib/shared/src/models/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { RestClient } from '../sourcegraph-api/rest/client'
import type { UserProductSubscription } from '../sourcegraph-api/userProductSubscription'
import { CHAT_INPUT_TOKEN_BUDGET } from '../token/constants'
import { isError } from '../utils'
import { getExperimentalClientModelByFeatureFlag } from './client'
import { type Model, type ServerModel, createModel, createModelFromServerModel } from './model'
import type {
DefaultsAndUserPreferencesForEndpoint,
Expand Down Expand Up @@ -201,74 +200,42 @@ export function syncModels({
featureFlagProvider.evaluatedFeatureFlag(
FeatureFlag.CodyEarlyAccess
),
featureFlagProvider.evaluatedFeatureFlag(FeatureFlag.DeepCody),
featureFlagProvider.evaluatedFeatureFlag(
FeatureFlag.CodyChatDefaultToClaude35Haiku
)
).pipe(
switchMap(
([hasEarlyAccess, hasDeepCodyFlag, defaultToHaiku]) => {
// TODO(sqs): remove waitlist from localStorage when user has access
const isOnWaitlist = config.clientState.waitlist_o1
if (isDotComUser && (hasEarlyAccess || isOnWaitlist)) {
data.primaryModels = data.primaryModels.map(
model => {
if (model.tags.includes(ModelTag.Waitlist)) {
const newTags = model.tags.filter(
tag => tag !== ModelTag.Waitlist
)
newTags.push(
hasEarlyAccess
? ModelTag.EarlyAccess
: ModelTag.OnWaitlist
)
return { ...model, tags: newTags }
}
return model
}
)
}
switchMap(([hasEarlyAccess, defaultToHaiku]) => {
// TODO(sqs): remove waitlist from localStorage when user has access
const isOnWaitlist = config.clientState.waitlist_o1
if (isDotComUser && (hasEarlyAccess || isOnWaitlist)) {
data.primaryModels = data.primaryModels.map(model => {
if (model.tags.includes(ModelTag.Waitlist)) {
const newTags = model.tags.filter(
tag => tag !== ModelTag.Waitlist
)
newTags.push(
hasEarlyAccess
? ModelTag.EarlyAccess
: ModelTag.OnWaitlist
)
return { ...model, tags: newTags }
}
return model
})
}

// Replace user's current sonnet model with deep-cody model.
const sonnetModel = data.primaryModels.find(m =>
m.id.includes('sonnet')
// set the default model to Haiku for free users
if (isDotComUser && isCodyFreeUser && defaultToHaiku) {
const haikuModel = data.primaryModels.find(m =>
m.id.includes('claude-3-5-haiku')
)
// DEEP CODY is enabled for all PLG users.
// Enterprise users need to have the feature flag enabled.
const isDeepCodyEnabled =
(isDotComUser && !isCodyFreeUser) || hasDeepCodyFlag
if (
isDeepCodyEnabled &&
sonnetModel &&
// Ensure the deep-cody model is only added once.
!data.primaryModels.some(m =>
m.id.includes('deep-cody')
)
) {
const DEEPCODY_MODEL =
getExperimentalClientModelByFeatureFlag(
FeatureFlag.DeepCody
)!
data.primaryModels.push(
...maybeAdjustContextWindows([
DEEPCODY_MODEL,
]).map(createModelFromServerModel)
)
if (haikuModel) {
data.preferences!.defaults.chat = haikuModel.id
}

// set the default model to Haiku for free users
if (isDotComUser && isCodyFreeUser && defaultToHaiku) {
const haikuModel = data.primaryModels.find(m =>
m.id.includes('claude-3-5-haiku')
)
if (haikuModel) {
data.preferences!.defaults.chat = haikuModel.id
}
}

return Observable.of(data)
}
)

return Observable.of(data)
})
)
})
)
Expand Down
14 changes: 6 additions & 8 deletions lib/shared/src/prompt/prompt-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@ export class PromptMixin {
mixins.push(PromptMixin.hedging)
}

// Handle Deep Cody specific prompts
const isDeepCodyEnabled = modelID?.includes('deep-cody')
if (isDeepCodyEnabled && !newMixins.length) {
// Handle Agent specific prompts
if (humanMessage.agent === 'deep-cody' && !newMixins.length) {
mixins.push(new PromptMixin(HEDGES_PREVENTION.concat(DEEP_CODY)))
}

// Add new mixins to the list of mixins to be prepended to the next human message.
mixins.push(...newMixins)

const prompt = PromptMixin.buildPrompt(mixins)
return PromptMixin.mixedMessage(humanMessage, prompt, mixins, isDeepCodyEnabled)
return PromptMixin.mixedMessage(humanMessage, prompt, mixins)
}

private static buildPrompt(mixins: PromptMixin[]): PromptString {
Expand All @@ -67,17 +66,16 @@ export class PromptMixin {
private static mixedMessage(
humanMessage: ChatMessage,
prompt: PromptString,
mixins: PromptMixin[],
isDeepCodyEnabled = false
mixins: PromptMixin[]
): ChatMessage {
if (!mixins.length || !humanMessage.text) {
return humanMessage
}

if (isDeepCodyEnabled) {
if (humanMessage.agent === 'deep-cody' && prompt.includes('{{USER_INPUT_TEXT}}')) {
return {
...humanMessage,
text: ps`${prompt}\n\n[QUESTION]\n`.concat(humanMessage.text),
text: prompt.replace('{{USER_INPUT_TEXT}}', humanMessage.text),
}
}

Expand Down
5 changes: 3 additions & 2 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1280,8 +1280,9 @@
},
"cody.agentic.context.experimentalShell": {
"type": "boolean",
"markdownDescription": "Enable Agents like Deep Cody to autonomously execute shell commands in your environment for context. Enable with caution as mistakes are possible.",
"default": false
"value": false,
"markdownDeprecationMessage": "**Deprecated** Enable Agents like Deep Cody to autonomously execute shell commands in your environment for context. Enable with caution as mistakes are possible.",
"deprecationMessage": "Deprecated. Now configurable via UI."
abeatrix marked this conversation as resolved.
Show resolved Hide resolved
},
"cody.agentic.context.experimentalOptions": {
"type": "object",
Expand Down
Loading
Loading