From e7ba7e900e3b952cebee0d631f8d94d0e74ac401 Mon Sep 17 00:00:00 2001 From: Stanislas Polu Date: Fri, 15 Nov 2024 07:54:40 +0100 Subject: [PATCH] rename --- front/components/actions/types.ts | 2 +- .../{jit => conversation}/list_files.ts | 31 +++++++-------- front/lib/api/assistant/agent.ts | 39 ++++++++++++------- sdks/js/src/types.ts | 38 +++++++++--------- .../{jit => conversation}/list_files.ts | 9 ++--- types/src/front/assistant/conversation.ts | 10 +++-- .../front/lib/api/assistant/actions/index.ts | 2 +- types/src/index.ts | 2 +- 8 files changed, 70 insertions(+), 63 deletions(-) rename front/lib/api/assistant/actions/{jit => conversation}/list_files.ts (80%) rename types/src/front/assistant/actions/{jit => conversation}/list_files.ts (61%) diff --git a/front/components/actions/types.ts b/front/components/actions/types.ts index 915e6bcb31b97..2ebb5865e018c 100644 --- a/front/components/actions/types.ts +++ b/front/components/actions/types.ts @@ -52,7 +52,7 @@ const actionsSpecification: ActionSpecifications = { detailsComponent: BrowseActionDetails, runningLabel: ACTION_RUNNING_LABELS.browse_action, }, - jit_list_files_action: { + conversation_list_files_action: { detailsComponent: () => null, runningLabel: ACTION_RUNNING_LABELS.jit_list_files_action, }, diff --git a/front/lib/api/assistant/actions/jit/list_files.ts b/front/lib/api/assistant/actions/conversation/list_files.ts similarity index 80% rename from front/lib/api/assistant/actions/jit/list_files.ts rename to front/lib/api/assistant/actions/conversation/list_files.ts index a9d7925830520..d78899805a8f4 100644 --- a/front/lib/api/assistant/actions/jit/list_files.ts +++ b/front/lib/api/assistant/actions/conversation/list_files.ts @@ -1,10 +1,10 @@ import type { AgentMessageType, + ConversationFileType, + ConversationListFilesActionType, ConversationType, FunctionCallType, FunctionMessageTypeModel, - JITFileType, - JITListFilesActionType, ModelId, } from "@dust-tt/types"; import { @@ -15,30 +15,27 @@ import { isTablesQueryActionType, } from "@dust-tt/types"; -interface JITListFilesActionBlob { +interface ConversationListFilesActionBlob { agentMessageId: ModelId; functionCallId: string | null; functionCallName: string | null; - files: JITFileType[]; - step: number; + files: ConversationFileType[]; } -export class JITListFilesAction extends BaseAction { +export class ConversationListFilesAction extends BaseAction { readonly agentMessageId: ModelId; - readonly files: JITFileType[]; + readonly files: ConversationFileType[]; readonly functionCallId: string | null; readonly functionCallName: string | null; - readonly step: number; - readonly type = "jit_list_files_action"; + readonly type = "conversation_list_files_action"; - constructor(blob: JITListFilesActionBlob) { - super(-1, "jit_list_files_action"); + constructor(blob: ConversationListFilesActionBlob) { + super(-1, "conversation_list_files_action"); this.agentMessageId = blob.agentMessageId; this.files = blob.files; this.functionCallId = blob.functionCallId; this.functionCallName = blob.functionCallName; - this.step = blob.step; } renderForFunctionCall(): FunctionCallType { @@ -64,12 +61,11 @@ export class JITListFilesAction extends BaseAction { } } -export function makeJITListFilesAction( - step: number, +export function makeConversationListFilesAction( agentMessage: AgentMessageType, conversation: ConversationType -): JITListFilesActionType | null { - const jitFiles: JITFileType[] = []; +): ConversationListFilesActionType | null { + const jitFiles: ConversationFileType[] = []; for (const m of conversation.content.flat(1)) { if (isContentFragmentType(m)) { @@ -99,11 +95,10 @@ export function makeJITListFilesAction( return null; } - return new JITListFilesAction({ + return new ConversationListFilesAction({ functionCallId: "call_" + Math.random().toString(36).substring(7), functionCallName: "list_conversation_files", files: jitFiles, agentMessageId: agentMessage.agentMessageId, - step: step, }); } diff --git a/front/lib/api/assistant/agent.ts b/front/lib/api/assistant/agent.ts index c5585c4cdf009..9e89cbbe3c483 100644 --- a/front/lib/api/assistant/agent.ts +++ b/front/lib/api/assistant/agent.ts @@ -4,6 +4,7 @@ import type { AgentActionSpecification, AgentActionSpecificEvent, AgentActionSuccessEvent, + AgentActionType, AgentChainOfThoughtEvent, AgentConfigurationType, AgentContentEvent, @@ -51,6 +52,9 @@ import { AgentMessageContent } from "@app/lib/models/assistant/agent_message_con import { cloneBaseConfig, DustProdActionRegistry } from "@app/lib/registry"; import logger from "@app/logger/logger"; +import { makeConversationListFilesAction } from "./actions/conversation/list_files"; +import { isJITActionsEnabled } from "./jit_actions"; + const CANCELLATION_CHECK_INTERVAL = 500; const MAX_ACTIONS_PER_STEP = 16; @@ -292,6 +296,23 @@ async function* runMultiActionsAgentLoop( } } +async function getEmulatedAgentMessageActions( + auth: Authenticator, + { + agentMessage, + conversation, + }: { agentMessage: AgentMessageType; conversation: ConversationType } +): Promise { + const actions: AgentActionType[] = []; + if (await isJITActionsEnabled(auth)) { + const a = makeConversationListFilesAction(agentMessage, conversation); + if (a) { + actions.push(a); + } + } + return actions; +} + // This method is used by the multi-actions execution loop to pick the next action to execute and // generate its inputs. async function* runMultiActionsAgent( @@ -362,15 +383,10 @@ async function* runMultiActionsAgent( const MIN_GENERATION_TOKENS = 2048; - const fakeJITListFiles = makeJITListFilesAction( - 0, - agentMessage, - conversation - ); - - if (fakeJITListFiles) { - agentMessage.actions.unshift(fakeJITListFiles); - } + // const emulatedActions = await getEmulatedAgentMessageActions(auth, { + // agentMessage, + // conversation, + // }); // Turn the conversation into a digest that can be presented to the model. const modelConversationRes = await renderConversationForModel(auth, { @@ -380,11 +396,6 @@ async function* runMultiActionsAgent( allowedTokenCount: model.contextSize - MIN_GENERATION_TOKENS, }); - // remove the fake JIT action from the agentMessage.actions - if (fakeJITListFiles) { - agentMessage.actions.shift(); - } - if (modelConversationRes.isErr()) { logger.error( { diff --git a/sdks/js/src/types.ts b/sdks/js/src/types.ts index 3b5086967dc4e..0c4723e579050 100644 --- a/sdks/js/src/types.ts +++ b/sdks/js/src/types.ts @@ -460,6 +460,24 @@ const BrowseActionTypeSchema = BaseActionSchema.extend({ }); type BrowseActionPublicType = z.infer; +const ConversationFileTypeSchema = z.object({ + fileId: z.string(), + title: z.string(), + contentType: z.string(), +}); + +const ConversationListFilesActionTypeSchema = BaseActionSchema.extend({ + files: z.array(ConversationFileTypeSchema), + functionCallId: z.string().nullable(), + functionCallName: z.string().nullable(), + agentMessageId: ModelIdSchema, + step: z.number(), + type: z.literal("conversation_list_files_action"), +}); +// type ConversationListFIlesActionPublicType = z.infer< +// typeof ConversationListFilesActionTypeSchema +// >; + const DustAppParametersSchema = z.record( z.union([z.string(), z.number(), z.boolean()]) ); @@ -610,24 +628,6 @@ const TablesQueryActionTypeSchema = BaseActionSchema.extend({ }); type TablesQueryActionPublicType = z.infer; -const JITFileTypeSchema = z.object({ - fileId: z.string(), - title: z.string(), - contentType: z.string(), -}); - -const JITListFilesActionTypeSchema = BaseActionSchema.extend({ - files: z.array(JITFileTypeSchema), - functionCallId: z.string().nullable(), - functionCallName: z.string().nullable(), - agentMessageId: ModelIdSchema, - step: z.number(), - type: z.literal("jit_list_files_action"), -}); -// type JITListFIlesActionPublicType = z.infer< -// typeof JITListFilesActionTypeSchema -// >; - const WhitelistableFeaturesSchema = FlexibleEnumSchema([ "usage_data_api", "okta_enterprise_connection", @@ -857,7 +857,7 @@ const AgentActionTypeSchema = z.union([ ProcessActionTypeSchema, WebsearchActionTypeSchema, BrowseActionTypeSchema, - JITListFilesActionTypeSchema, + ConversationListFilesActionTypeSchema, ]); export type AgentActionPublicType = z.infer; diff --git a/types/src/front/assistant/actions/jit/list_files.ts b/types/src/front/assistant/actions/conversation/list_files.ts similarity index 61% rename from types/src/front/assistant/actions/jit/list_files.ts rename to types/src/front/assistant/actions/conversation/list_files.ts index 6a400aa0e75f4..ed1ebbc1235f0 100644 --- a/types/src/front/assistant/actions/jit/list_files.ts +++ b/types/src/front/assistant/actions/conversation/list_files.ts @@ -1,17 +1,16 @@ import { BaseAction } from "../../../../front/lib/api/assistant/actions/index"; import { ModelId } from "../../../../shared/model_id"; -export type JITFileType = { +export type ConversationFileType = { fileId: string; title: string; contentType: string; }; -export interface JITListFilesActionType extends BaseAction { +export interface ConversationListFilesActionType extends BaseAction { agentMessageId: ModelId; - files: JITFileType[]; + files: ConversationFileType[]; functionCallId: string | null; functionCallName: string | null; - step: number; - type: "jit_list_files_action"; + type: "conversation_list_files_action"; } diff --git a/types/src/front/assistant/conversation.ts b/types/src/front/assistant/conversation.ts index 6c4364879af30..1bf83a1f18ae7 100644 --- a/types/src/front/assistant/conversation.ts +++ b/types/src/front/assistant/conversation.ts @@ -7,7 +7,7 @@ import { UserType, WorkspaceType } from "../../front/user"; import { ModelId } from "../../shared/model_id"; import { ContentFragmentType } from "../content_fragment"; import { BrowseActionType } from "./actions/browse"; -import { JITListFilesActionType } from "./actions/jit/list_files"; +import { ConversationListFilesActionType } from "./actions/conversation/list_files"; import { WebsearchActionType } from "./actions/websearch"; /** @@ -112,9 +112,11 @@ export type ConfigurableAgentActionType = | WebsearchActionType | BrowseActionType; -export type JITAgentActionType = JITListFilesActionType; +export type ConversationAgentActionType = ConversationListFilesActionType; -export type AgentActionType = ConfigurableAgentActionType | JITAgentActionType; +export type AgentActionType = + | ConfigurableAgentActionType + | ConversationAgentActionType; export type AgentMessageStatus = | "created" @@ -129,7 +131,7 @@ export const ACTION_RUNNING_LABELS: Record = { tables_query_action: "Querying tables", websearch_action: "Searching the web", browse_action: "Browsing page", - jit_list_files_action: "Listing conversation files", + conversation_list_files_action: "Listing conversation files", }; /** diff --git a/types/src/front/lib/api/assistant/actions/index.ts b/types/src/front/lib/api/assistant/actions/index.ts index 0af2a6fdf25d1..ceaf4c7c0bbef 100644 --- a/types/src/front/lib/api/assistant/actions/index.ts +++ b/types/src/front/lib/api/assistant/actions/index.ts @@ -9,7 +9,7 @@ type BaseActionType = | "websearch_action" | "browse_action" | "visualization_action" - | "jit_list_files_action"; + | "conversation_list_files_action"; export abstract class BaseAction { readonly id: ModelId; diff --git a/types/src/index.ts b/types/src/index.ts index 319851cab40bc..57c97ba80867c 100644 --- a/types/src/index.ts +++ b/types/src/index.ts @@ -21,9 +21,9 @@ export * from "./front/api_handlers/public/data_sources"; export * from "./front/api_handlers/public/spaces"; export * from "./front/app"; export * from "./front/assistant/actions/browse"; +export * from "./front/assistant/actions/conversation/list_files"; export * from "./front/assistant/actions/dust_app_run"; export * from "./front/assistant/actions/guards"; -export * from "./front/assistant/actions/jit/list_files"; export * from "./front/assistant/actions/process"; export * from "./front/assistant/actions/retrieval"; export * from "./front/assistant/actions/tables_query";