Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
spolu committed Nov 15, 2024
1 parent 952f8f1 commit e7ba7e9
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 63 deletions.
2 changes: 1 addition & 1 deletion front/components/actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type {
AgentMessageType,
ConversationFileType,
ConversationListFilesActionType,
ConversationType,
FunctionCallType,
FunctionMessageTypeModel,
JITFileType,
JITListFilesActionType,
ModelId,
} from "@dust-tt/types";
import {
Expand All @@ -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 {
Expand All @@ -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)) {
Expand Down Expand Up @@ -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,
});
}
39 changes: 25 additions & 14 deletions front/lib/api/assistant/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
AgentActionSpecification,
AgentActionSpecificEvent,
AgentActionSuccessEvent,
AgentActionType,
AgentChainOfThoughtEvent,
AgentConfigurationType,
AgentContentEvent,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -292,6 +296,23 @@ async function* runMultiActionsAgentLoop(
}
}

async function getEmulatedAgentMessageActions(
auth: Authenticator,
{
agentMessage,
conversation,
}: { agentMessage: AgentMessageType; conversation: ConversationType }
): Promise<AgentActionType[]> {
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(
Expand Down Expand Up @@ -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, {
Expand All @@ -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(
{
Expand Down
38 changes: 19 additions & 19 deletions sdks/js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,24 @@ const BrowseActionTypeSchema = BaseActionSchema.extend({
});
type BrowseActionPublicType = z.infer<typeof BrowseActionTypeSchema>;

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()])
);
Expand Down Expand Up @@ -610,24 +628,6 @@ const TablesQueryActionTypeSchema = BaseActionSchema.extend({
});
type TablesQueryActionPublicType = z.infer<typeof TablesQueryActionTypeSchema>;

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",
Expand Down Expand Up @@ -857,7 +857,7 @@ const AgentActionTypeSchema = z.union([
ProcessActionTypeSchema,
WebsearchActionTypeSchema,
BrowseActionTypeSchema,
JITListFilesActionTypeSchema,
ConversationListFilesActionTypeSchema,
]);
export type AgentActionPublicType = z.infer<typeof AgentActionTypeSchema>;

Expand Down
Original file line number Diff line number Diff line change
@@ -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";
}
10 changes: 6 additions & 4 deletions types/src/front/assistant/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand Down Expand Up @@ -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"
Expand All @@ -129,7 +131,7 @@ export const ACTION_RUNNING_LABELS: Record<AgentActionType["type"], string> = {
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",
};

/**
Expand Down
2 changes: 1 addition & 1 deletion types/src/front/lib/api/assistant/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit e7ba7e9

Please sign in to comment.