Skip to content

Commit 613af08

Browse files
committed
remove @core package and refactor tools code
1 parent ab6e5dc commit 613af08

File tree

6 files changed

+29
-83
lines changed

6 files changed

+29
-83
lines changed

templates/components/agents/typescript/financial_report/workflow/factory.ts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,19 @@
11
import { ChatMessage, ToolCallLLM } from "llamaindex";
2+
import { getTool } from "../engine/tools";
23
import { FinancialReportWorkflow } from "./fin-report";
3-
import { getAvailableTools } from "./tools";
4+
import { getQueryEngineTools } from "./tools";
45

56
const TIMEOUT = 360 * 1000;
67

78
export async function createWorkflow(options: {
89
chatHistory: ChatMessage[];
910
llm?: ToolCallLLM;
1011
}) {
11-
const tools = await getAvailableTools();
12-
const queryEngineTools = tools.filter((tool) =>
13-
tool.metadata.name.includes("retriever"),
14-
);
15-
const documentGeneratorTool = tools.find(
16-
(tool) => tool.metadata.name === "document_generator",
17-
);
18-
const codeInterpreterTool = tools.find(
19-
(tool) => tool.metadata.name === "interpreter",
20-
);
21-
if (!queryEngineTools?.length) {
22-
throw new Error("Query engine tools array must not be empty");
23-
}
24-
if (!documentGeneratorTool) {
25-
throw new Error("Document generator tool not found");
26-
}
27-
if (!codeInterpreterTool) {
28-
throw new Error("Code interpreter tool not found");
29-
}
30-
3112
return new FinancialReportWorkflow({
3213
chatHistory: options.chatHistory,
33-
queryEngineTools,
34-
codeInterpreterTool,
35-
documentGeneratorTool,
14+
queryEngineTools: (await getQueryEngineTools()) || [],
15+
codeInterpreterTool: (await getTool("interpreter"))!,
16+
documentGeneratorTool: (await getTool("document_generator"))!,
3617
llm: options.llm,
3718
timeout: TIMEOUT,
3819
});
Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,20 @@
11
import { ChatMessage, ToolCallLLM } from "llamaindex";
2+
import { getQueryEngineTools } from "../../../../multiagent/typescript/workflow/tools";
3+
import { getTool } from "../engine/tools";
24
import { FormFillingWorkflow } from "./form-filling";
3-
import { getAvailableTools } from "./tools";
45

56
const TIMEOUT = 360 * 1000;
67

78
export async function createWorkflow(options: {
89
chatHistory: ChatMessage[];
910
llm?: ToolCallLLM;
1011
}) {
11-
const tools = await getAvailableTools();
12-
const extractorTool = tools.find(
13-
(tool) => tool.metadata.name === "extract_missing_cells",
14-
);
15-
const queryEngineTools = tools.filter((tool) =>
16-
tool.metadata.name.includes("retriever"),
17-
);
18-
const fillMissingCellsTool = tools.find(
19-
(tool) => tool.metadata.name === "fill_missing_cells",
20-
);
21-
22-
if (!extractorTool) {
23-
throw new Error("Extractor tool not found");
24-
}
25-
if (!fillMissingCellsTool) {
26-
throw new Error("Fill missing cells tool not found");
27-
}
28-
29-
const formFilling = new FormFillingWorkflow({
12+
return new FormFillingWorkflow({
3013
chatHistory: options.chatHistory,
31-
extractorTool,
32-
queryEngineTools,
33-
fillMissingCellsTool,
14+
queryEngineTools: (await getQueryEngineTools()) || [],
15+
extractorTool: (await getTool("extract_missing_cells"))!,
16+
fillMissingCellsTool: (await getTool("fill_missing_cells"))!,
3417
llm: options.llm,
3518
timeout: TIMEOUT,
3619
});
37-
38-
return formFilling;
3920
}

templates/components/engines/typescript/agent/tools/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { BaseToolWithCall } from "llamaindex";
22
import { ToolsFactory } from "llamaindex/tools/ToolsFactory";
3+
import fs from "node:fs/promises";
4+
import path from "node:path";
35
import { CodeGeneratorTool, CodeGeneratorToolParams } from "./code-generator";
46
import {
57
DocumentGenerator,
@@ -82,3 +84,19 @@ async function createLocalTools(
8284

8385
return tools;
8486
}
87+
88+
export async function getConfiguredTools(
89+
configPath?: string,
90+
): Promise<BaseToolWithCall[]> {
91+
const configFile = path.join(configPath ?? "config", "tools.json");
92+
const toolConfig = JSON.parse(await fs.readFile(configFile, "utf8"));
93+
const tools = await createTools(toolConfig);
94+
return tools;
95+
}
96+
97+
export async function getTool(
98+
toolName: string,
99+
): Promise<BaseToolWithCall | undefined> {
100+
const tools = await getConfiguredTools();
101+
return tools.find((tool) => tool.metadata.name === toolName);
102+
}

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

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { HandlerContext } from "@llamaindex/workflow";
2-
import fs from "fs/promises";
32
import {
43
BaseToolWithCall,
54
callTool,
@@ -14,9 +13,7 @@ import {
1413
ToolCallLLMMessageOptions,
1514
} from "llamaindex";
1615
import crypto from "node:crypto";
17-
import path from "path";
1816
import { getDataSource } from "../engine";
19-
import { createTools } from "../engine/tools/index";
2017
import { AgentRunEvent } from "./type";
2118

2219
export const getQueryEngineTools = async (): Promise<
@@ -71,35 +68,6 @@ export const getQueryEngineTools = async (): Promise<
7168
}
7269
};
7370

74-
export const getAvailableTools = async (): Promise<BaseToolWithCall[]> => {
75-
const configFile = path.join("config", "tools.json");
76-
let toolConfig: any;
77-
const tools: BaseToolWithCall[] = [];
78-
try {
79-
toolConfig = JSON.parse(await fs.readFile(configFile, "utf8"));
80-
} catch (e) {
81-
console.info(`Could not read ${configFile} file. Using no tools.`);
82-
}
83-
if (toolConfig) {
84-
tools.push(...(await createTools(toolConfig)));
85-
}
86-
const queryEngineTools = await getQueryEngineTools();
87-
if (queryEngineTools) {
88-
tools.push(...queryEngineTools);
89-
}
90-
91-
return tools;
92-
};
93-
94-
export const lookupTools = async (
95-
toolNames: string[],
96-
): Promise<BaseToolWithCall[]> => {
97-
const availableTools = await getAvailableTools();
98-
return availableTools.filter((tool) =>
99-
toolNames.includes(tool.metadata.name),
100-
);
101-
};
102-
10371
/**
10472
* Call multiple tools and return the tool messages
10573
*/

templates/types/streaming/express/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"@types/cors": "^2.8.16",
3535
"@types/express": "^4.17.21",
3636
"@types/node": "^20.9.5",
37-
"@llamaindex/core": "^0.4.5",
3837
"@llamaindex/workflow": "^0.0.3",
3938
"@types/papaparse": "^5.3.15",
4039
"concurrently": "^8.2.2",

templates/types/streaming/nextjs/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"@types/react": "^18.2.42",
4646
"@types/react-dom": "^18.2.17",
4747
"@types/uuid": "^9.0.8",
48-
"@llamaindex/core": "^0.4.5",
4948
"@llamaindex/workflow": "^0.0.3",
5049
"@types/papaparse": "^5.3.15",
5150
"autoprefixer": "^10.4.16",

0 commit comments

Comments
 (0)