-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathagent-function-configurator.ts
More file actions
125 lines (115 loc) · 3.81 KB
/
Copy pathagent-function-configurator.ts
File metadata and controls
125 lines (115 loc) · 3.81 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { ok } from "@breadboard-ai/utils";
import { A2ModuleArgs } from "../runnable-module-factory.js";
import type { FunctionGroupConfigurator } from "./types.js";
import { getGenerateFunctionGroup } from "./functions/generate.js";
import { getSystemFunctionGroup } from "./functions/system.js";
import { getMemoryFunctionGroup } from "./functions/memory.js";
import { getNotebookLMFunctionGroup } from "./functions/notebooklm.js";
import { CHAT_LOG_PATH, getChatFunctionGroup } from "./functions/chat.js";
import { getA2UIFunctionGroup } from "./functions/a2ui.js";
import { getNoUiFunctionGroup } from "./functions/no-ui.js";
import { TaskTreeManager } from "./task-tree-manager.js";
import { Generators } from "./types.js";
export { createAgentConfigurator };
import type { AgentEventSink } from "./agent-event-sink.js";
function createAgentConfigurator(
moduleArgs: A2ModuleArgs,
generators: Generators,
sink: AgentEventSink
): FunctionGroupConfigurator {
return async (deps, flags) => {
const runtimeFlags = await moduleArgs.context.flags?.flags();
const groups = [];
const taskTreeManager = new TaskTreeManager(deps.fileSystem);
groups.push(
getSystemFunctionGroup({
fileSystem: deps.fileSystem,
translator: deps.translator,
taskTreeManager,
successCallback: flags.onSuccess,
failureCallback: flags.onFailure,
})
);
groups.push(
getGenerateFunctionGroup({
fileSystem: deps.fileSystem,
moduleArgs,
translator: deps.translator,
taskTreeManager,
generators,
sink,
runtimeFlags,
})
);
if (flags.useMemory) {
groups.push(
getMemoryFunctionGroup({
context: moduleArgs.context,
translator: deps.translator,
fileSystem: deps.fileSystem,
memoryManager: moduleArgs.agentContext.memoryManager,
taskTreeManager,
})
);
}
if (flags.useNotebookLM && runtimeFlags?.enableNotebookLm) {
groups.push(
getNotebookLMFunctionGroup({
notebookLmApiClient: moduleArgs.notebookLmApiClient,
fileSystem: deps.fileSystem,
taskTreeManager,
})
);
}
if (flags.uiType === "a2ui") {
const a2uiFunctionGroup = await getA2UIFunctionGroup({
moduleArgs,
fileSystem: deps.fileSystem,
translator: deps.translator,
ui: deps.ui,
uiPrompt: flags.uiPrompt,
objective: flags.objective,
params: flags.params,
});
if (!ok(a2uiFunctionGroup)) return a2uiFunctionGroup;
groups.push(a2uiFunctionGroup);
} else if (flags.uiType === "chat") {
deps.fileSystem.addSystemFile(CHAT_LOG_PATH, () =>
JSON.stringify(deps.ui.chatLog)
);
if (flags.useMemory) {
const memoryManager = moduleArgs.agentContext.memoryManager;
deps.ui.setMemoryManager(memoryManager, moduleArgs.context);
// Ensure the __chat_log__ sheet exists, then load historical entries.
const ensured = await memoryManager.ensureSystemSheet(
moduleArgs.context,
"__chat_log__",
["timestamp", "session_id", "role", "content"]
);
if (ok(ensured)) {
const sheetData = await memoryManager.readSheet(moduleArgs.context, {
range: "__chat_log__!A:D",
});
if (ok(sheetData) && "values" in sheetData && sheetData.values) {
deps.ui.seedChatLog(sheetData.values);
}
}
}
groups.push(
getChatFunctionGroup({
chatManager: deps.ui,
translator: deps.translator,
taskTreeManager,
})
);
} else {
groups.push(getNoUiFunctionGroup());
}
return groups;
};
}