Skip to content

Commit 7848b83

Browse files
committed
improve code
1 parent 3cae9d7 commit 7848b83

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export async function createWorkflow(options: {
5454
const chatHistoryWithAgentMessages = prepareChatHistory(options.chatHistory);
5555

5656
const tools = await getAvailableTools();
57-
const retrieverTools = tools.filter((tool) =>
57+
const queryEngineTool = tools.find((tool) =>
5858
tool.metadata.name.startsWith("retriever"),
5959
);
6060
const documentGeneratorTool = tools.find(
@@ -64,15 +64,15 @@ export async function createWorkflow(options: {
6464
(tool) => tool.metadata.name === "interpreter",
6565
);
6666

67-
if (!documentGeneratorTool || !codeInterpreterTool || !retrieverTools) {
67+
if (!documentGeneratorTool || !codeInterpreterTool || !queryEngineTool) {
6868
throw new Error(
6969
"These tools are required: document_generator, code_interpreter, retriever",
7070
);
7171
}
7272

7373
return new FinancialReportWorkflow({
7474
chatHistory: chatHistoryWithAgentMessages,
75-
queryEngineTools: retrieverTools,
75+
queryEngineTool: queryEngineTool,
7676
codeInterpreterTool,
7777
documentGeneratorTool,
7878
llm: options.llm,

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ For the query engine tool, you should break down the user request into a list of
4040
export class FinancialReportWorkflow extends Workflow {
4141
llm: ToolCallLLM;
4242
memory: ChatMemoryBuffer;
43-
queryEngineTools: BaseToolWithCall[];
43+
queryEngineTool: BaseToolWithCall;
4444
codeInterpreterTool: BaseToolWithCall;
4545
documentGeneratorTool: BaseToolWithCall;
4646
systemPrompt?: string;
@@ -49,7 +49,7 @@ export class FinancialReportWorkflow extends Workflow {
4949
constructor(options: {
5050
llm?: ToolCallLLM;
5151
chatHistory: ChatMessage[];
52-
queryEngineTools: BaseToolWithCall[];
52+
queryEngineTool: BaseToolWithCall;
5353
codeInterpreterTool: BaseToolWithCall;
5454
documentGeneratorTool: BaseToolWithCall;
5555
systemPrompt?: string;
@@ -65,7 +65,7 @@ export class FinancialReportWorkflow extends Workflow {
6565
this.llm = options.llm ?? (Settings.llm as ToolCallLLM);
6666
this.systemPrompt = options.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
6767
this.writeEvents = options.writeEvents;
68-
this.queryEngineTools = options.queryEngineTools;
68+
this.queryEngineTool = options.queryEngineTool;
6969
this.codeInterpreterTool = options.codeInterpreterTool;
7070
this.documentGeneratorTool = options.documentGeneratorTool;
7171
this.memory = new ChatMemoryBuffer({
@@ -112,8 +112,8 @@ export class FinancialReportWorkflow extends Workflow {
112112
const chatHistory = ev.data.input;
113113

114114
const tools = [this.codeInterpreterTool, this.documentGeneratorTool];
115-
if (this.queryEngineTools) {
116-
tools.push(...this.queryEngineTools);
115+
if (this.queryEngineTool) {
116+
tools.push(this.queryEngineTool);
117117
}
118118

119119
const toolCallResponse = await chatWithTools(this.llm, tools, chatHistory);
@@ -169,7 +169,7 @@ export class FinancialReportWorkflow extends Workflow {
169169

170170
const toolMsgs = await callTools(
171171
toolCalls,
172-
this.queryEngineTools,
172+
[this.queryEngineTool],
173173
ctx,
174174
"Researcher",
175175
);
@@ -197,7 +197,7 @@ export class FinancialReportWorkflow extends Workflow {
197197
);
198198
// Request by workflow LLM, input is a list of tool calls
199199
let toolCalls: ToolCall[] = [];
200-
if (ev.data.input instanceof Array) {
200+
if (Array.isArray(ev.data.input)) {
201201
toolCalls = ev.data.input;
202202
} else {
203203
// Requested by Researcher, input is a ChatMessage

templates/components/engines/typescript/agent/tools/form-filling.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ export class FillMissingCellsTool
240240
skipEmptyLines: false, // Ensure empty lines are not skipped
241241
});
242242

243+
if (parseResult.errors.length) {
244+
throw new Error(
245+
"Failed to parse CSV file: " + parseResult.errors[0].message,
246+
);
247+
}
248+
243249
const rows = parseResult.data;
244250

245251
// Fill the cells with answers

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ export const callTools = async (
8383
return toolMsgs;
8484
}
8585
if (toolCalls.length === 1) {
86+
const tool = tools.find((tool) => tool.metadata.name === toolCalls[0].name);
87+
if (!tool) {
88+
throw new Error(`Tool ${toolCalls[0].name} not found`);
89+
}
8690
return [
87-
(await callSingleTool(toolCalls[0], tools[0], (msg: string) => {
91+
(await callSingleTool(toolCalls[0], tool, (msg: string) => {
8892
if (writeEvent) {
8993
ctx.writeEventToStream(
9094
new AgentRunEvent({

0 commit comments

Comments
 (0)