-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
load.ts
33 lines (30 loc) · 945 Bytes
/
load.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Agent } from "./agent.js";
import { Tool } from "../tools/base.js";
import { BaseLanguageModel } from "../base_language/index.js";
import { loadFromHub } from "../util/hub.js";
import { FileLoader, loadFromFile } from "../util/load.js";
import { parseFileConfig } from "../util/parse.js";
const loadAgentFromFile: FileLoader<Agent> = async (
file: string,
path: string,
llmAndTools?: { llm?: BaseLanguageModel; tools?: Tool[] }
) => {
const serialized = parseFileConfig(file, path);
return Agent.deserialize({ ...serialized, ...llmAndTools });
};
export const loadAgent = async (
uri: string,
llmAndTools?: { llm?: BaseLanguageModel; tools?: Tool[] }
): Promise<Agent> => {
const hubResult = await loadFromHub(
uri,
loadAgentFromFile,
"agents",
new Set(["json", "yaml"]),
llmAndTools
);
if (hubResult) {
return hubResult;
}
return loadFromFile(uri, loadAgentFromFile, llmAndTools);
};