Skip to content

Commit bd8812b

Browse files
committed
update workflow code
1 parent ef86d64 commit bd8812b

File tree

6 files changed

+17
-32
lines changed

6 files changed

+17
-32
lines changed

templates/components/agents/typescript/financial_report/app/api/chat/workflow/finReport.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
ChatMemoryBuffer,
1111
ChatMessage,
1212
ChatResponseChunk,
13-
MessageContent,
1413
Settings,
1514
ToolCall,
1615
ToolCallLLM,
@@ -41,7 +40,7 @@ For the query engine tool, you should break down the user request into a list of
4140

4241
export class FinancialReportWorkflow extends Workflow<
4342
null,
44-
string | MessageContent,
43+
AgentInput,
4544
ChatResponseChunk
4645
> {
4746
llm: ToolCallLLM;
@@ -132,7 +131,7 @@ export class FinancialReportWorkflow extends Workflow<
132131
ctx: HandlerContext<null>,
133132
ev: StartEvent<AgentInput>,
134133
) {
135-
const message = ev.data;
134+
const { message } = ev.data;
136135

137136
if (this.systemPrompt) {
138137
this.memory.put({ role: "system", content: this.systemPrompt });

templates/components/agents/typescript/form_filling/app/api/chat/workflow/factory.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ const prepareChatHistory = (chatHistory: Message[]): ChatMessage[] => {
4444
export async function createWorkflow(options: {
4545
chatHistory: Message[];
4646
llm?: ToolCallLLM;
47-
writeEvents?: boolean;
4847
}) {
4948
const enhancedChatHistory = prepareChatHistory(options.chatHistory);
5049

@@ -71,7 +70,6 @@ export async function createWorkflow(options: {
7170
queryEngineTool,
7271
fillMissingCellsTool,
7372
llm: options.llm,
74-
writeEvents: options.writeEvents,
7573
timeout: TIMEOUT,
7674
});
7775

templates/components/agents/typescript/form_filling/app/api/chat/workflow/formFilling.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
Context,
32
HandlerContext,
43
StartEvent,
54
StopEvent,
@@ -11,7 +10,6 @@ import {
1110
ChatMemoryBuffer,
1211
ChatMessage,
1312
ChatResponseChunk,
14-
MessageContent,
1513
Settings,
1614
ToolCall,
1715
ToolCallLLM,
@@ -35,15 +33,16 @@ class FillMissingCellsEvent extends WorkflowEvent<{
3533
}> {}
3634

3735
const DEFAULT_SYSTEM_PROMPT = `
38-
You are a helpful assistant who helps fill missing cells in a CSV file. Only use the local file path for the tools.
39-
Only use provided data - never make up any information yourself. Fill N/A if an answer is not found.
36+
You are a helpful assistant who helps fill missing cells in a CSV file.
37+
Only use the information from the query engine tool - don't make up any information yourself. Fill N/A if an answer is not found.
4038
If there is no query engine tool or the gathered information has many N/A values indicating the questions don't match the data, respond with a warning and ask the user to upload a different file or connect to a knowledge base.
4139
You can make multiple tool calls at once but only call with the same tool.
40+
Only use the local file path for the tools.
4241
`;
4342

4443
export class FormFillingWorkflow extends Workflow<
4544
null,
46-
string | MessageContent,
45+
AgentInput,
4746
ChatResponseChunk
4847
> {
4948
llm: ToolCallLLM;
@@ -52,7 +51,6 @@ export class FormFillingWorkflow extends Workflow<
5251
queryEngineTool?: BaseToolWithCall;
5352
fillMissingCellsTool: BaseToolWithCall;
5453
systemPrompt?: string;
55-
writeEvents?: boolean;
5654

5755
constructor(options: {
5856
llm?: ToolCallLLM;
@@ -72,7 +70,6 @@ export class FormFillingWorkflow extends Workflow<
7270

7371
this.llm = options.llm ?? (Settings.llm as ToolCallLLM);
7472
this.systemPrompt = options.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
75-
this.writeEvents = options.writeEvents;
7673
this.extractorTool = options.extractorTool;
7774
this.queryEngineTool = options.queryEngineTool;
7875
this.fillMissingCellsTool = options.fillMissingCellsTool;
@@ -133,7 +130,7 @@ export class FormFillingWorkflow extends Workflow<
133130
ctx: HandlerContext<null>,
134131
ev: StartEvent<AgentInput>,
135132
) {
136-
const message = ev.data;
133+
const { message } = ev.data;
137134

138135
if (this.systemPrompt) {
139136
this.memory.put({ role: "system", content: this.systemPrompt });
@@ -190,7 +187,7 @@ export class FormFillingWorkflow extends Workflow<
190187
}
191188

192189
private async handleExtractMissingCells(
193-
ctx: Context,
190+
ctx: HandlerContext<null>,
194191
ev: ExtractMissingCellsEvent,
195192
) {
196193
ctx.sendEvent(
@@ -213,7 +210,10 @@ export class FormFillingWorkflow extends Workflow<
213210
return new InputEvent({ input: this.memory.getMessages() });
214211
}
215212

216-
private async handleFindAnswers(ctx: Context, ev: FindAnswersEvent) {
213+
private async handleFindAnswers(
214+
ctx: HandlerContext<null>,
215+
ev: FindAnswersEvent,
216+
) {
217217
const { toolCalls } = ev.data;
218218
if (!this.queryEngineTool) {
219219
throw new Error("Query engine tool is not available");

templates/components/llamaindex/typescript/documents/upload.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Document, LLamaCloudFileService, VectorStoreIndex } from "llamaindex";
22
import { LlamaCloudIndex } from "llamaindex/cloud/LlamaCloudIndex";
3-
import fs from "node:fs/promises";
4-
import path from "node:path";
53
import { DocumentFile } from "../streaming/annotations";
64
import { parseFile, storeFile } from "./helper";
75
import { runPipeline } from "./pipeline";
@@ -61,14 +59,3 @@ export async function uploadDocument(
6159
fileMetadata.refs = documentIds;
6260
return fileMetadata;
6361
}
64-
65-
const hasCodeExecutorTool = async () => {
66-
const codeExecutorTools = ["interpreter", "artifact"];
67-
68-
const configFile = path.join("config", "tools.json");
69-
const toolConfig = JSON.parse(await fs.readFile(configFile, "utf8"));
70-
71-
const localTools = toolConfig.local || {};
72-
// Check if local tools contains codeExecutorTools
73-
return codeExecutorTools.some((tool) => localTools[tool] !== undefined);
74-
};

templates/components/multiagent/typescript/nextjs/route.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { initObservability } from "@/app/observability";
22
import { StreamingTextResponse, type Message } from "ai";
3-
import { MessageContent } from "llamaindex";
43
import { NextRequest, NextResponse } from "next/server";
54
import { initSettings } from "./engine/settings";
65
import {
@@ -33,10 +32,12 @@ export async function POST(request: NextRequest) {
3332
const userMessageContent = retrieveMessageContent(messages);
3433
const workflow = await createWorkflow({
3534
chatHistory: messages,
36-
writeEvents: true,
3735
});
3836

39-
const context = workflow.run(userMessageContent as MessageContent);
37+
const context = workflow.run({
38+
message: userMessageContent,
39+
streaming: true,
40+
});
4041
const { stream, streamData } =
4142
await createStreamFromWorkflowContext(context);
4243

templates/components/multiagent/typescript/workflow/type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { WorkflowEvent } from "@llamaindex/workflow";
22
import { MessageContent } from "llamaindex";
33

44
export type AgentInput = {
5-
message: string | MessageContent;
5+
message: MessageContent;
66
streaming?: boolean;
77
};
88

0 commit comments

Comments
 (0)