Skip to content

Commit f07e58e

Browse files
committed
remove bind
1 parent e16426b commit f07e58e

File tree

3 files changed

+231
-125
lines changed

3 files changed

+231
-125
lines changed

templates/components/agents/typescript/financial_report/workflow/fin-report.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class FinancialReportWorkflow extends Workflow<
8585
inputs: [StartEvent<AgentInput>],
8686
outputs: [InputEvent],
8787
},
88-
this.prepareChatHistory.bind(this),
88+
this.prepareChatHistory,
8989
);
9090

9191
this.addStep(
@@ -99,38 +99,38 @@ export class FinancialReportWorkflow extends Workflow<
9999
StopEvent,
100100
],
101101
},
102-
this.handleLLMInput.bind(this),
102+
this.handleLLMInput,
103103
);
104104

105105
this.addStep(
106106
{
107107
inputs: [ResearchEvent],
108108
outputs: [AnalyzeEvent],
109109
},
110-
this.handleResearch.bind(this),
110+
this.handleResearch,
111111
);
112112

113113
this.addStep(
114114
{
115115
inputs: [AnalyzeEvent],
116116
outputs: [InputEvent],
117117
},
118-
this.handleAnalyze.bind(this),
118+
this.handleAnalyze,
119119
);
120120

121121
this.addStep(
122122
{
123123
inputs: [ReportGenerationEvent],
124124
outputs: [InputEvent],
125125
},
126-
this.handleReportGeneration.bind(this),
126+
this.handleReportGeneration,
127127
);
128128
}
129129

130-
private async prepareChatHistory(
130+
prepareChatHistory = async (
131131
ctx: HandlerContext<null>,
132132
ev: StartEvent<AgentInput>,
133-
) {
133+
): Promise<InputEvent> => {
134134
const { message } = ev.data;
135135

136136
if (this.systemPrompt) {
@@ -139,9 +139,18 @@ export class FinancialReportWorkflow extends Workflow<
139139
this.memory.put({ role: "user", content: message });
140140

141141
return new InputEvent({ input: this.memory.getMessages() });
142-
}
142+
};
143143

144-
private async handleLLMInput(ctx: HandlerContext<null>, ev: InputEvent) {
144+
handleLLMInput = async (
145+
ctx: HandlerContext<null>,
146+
ev: InputEvent,
147+
): Promise<
148+
| InputEvent
149+
| ResearchEvent
150+
| AnalyzeEvent
151+
| ReportGenerationEvent
152+
| StopEvent
153+
> => {
145154
const chatHistory = ev.data.input;
146155

147156
const tools = [this.codeInterpreterTool, this.documentGeneratorTool];
@@ -190,9 +199,12 @@ export class FinancialReportWorkflow extends Workflow<
190199
}
191200
throw new Error(`Unknown tool: ${toolName}`);
192201
}
193-
}
202+
};
194203

195-
private async handleResearch(ctx: HandlerContext<null>, ev: ResearchEvent) {
204+
handleResearch = async (
205+
ctx: HandlerContext<null>,
206+
ev: ResearchEvent,
207+
): Promise<AnalyzeEvent> => {
196208
ctx.sendEvent(
197209
new AgentRunEvent({
198210
agent: "Researcher",
@@ -219,12 +231,15 @@ export class FinancialReportWorkflow extends Workflow<
219231
"I have finished researching the data, please analyze the data.",
220232
},
221233
});
222-
}
234+
};
223235

224236
/**
225237
* Analyze a research result or a tool call for code interpreter from the LLM
226238
*/
227-
private async handleAnalyze(ctx: HandlerContext<null>, ev: AnalyzeEvent) {
239+
handleAnalyze = async (
240+
ctx: HandlerContext<null>,
241+
ev: AnalyzeEvent,
242+
): Promise<InputEvent> => {
228243
ctx.sendEvent(
229244
new AgentRunEvent({
230245
agent: "Analyst",
@@ -283,12 +298,12 @@ export class FinancialReportWorkflow extends Workflow<
283298
return new InputEvent({
284299
input: this.memory.getMessages(),
285300
});
286-
}
301+
};
287302

288-
private async handleReportGeneration(
303+
handleReportGeneration = async (
289304
ctx: HandlerContext<null>,
290305
ev: ReportGenerationEvent,
291-
) {
306+
): Promise<InputEvent> => {
292307
const { toolCalls } = ev.data;
293308

294309
const toolMsgs = await callTools({
@@ -301,5 +316,5 @@ export class FinancialReportWorkflow extends Workflow<
301316
this.memory.put(toolMsg);
302317
}
303318
return new InputEvent({ input: this.memory.getMessages() });
304-
}
319+
};
305320
}

templates/components/agents/typescript/form_filling/workflow/form-filling.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class FormFillingWorkflow extends Workflow<
8787
inputs: [StartEvent<AgentInput>],
8888
outputs: [InputEvent],
8989
},
90-
this.prepareChatHistory.bind(this),
90+
this.prepareChatHistory,
9191
);
9292

9393
this.addStep(
@@ -101,38 +101,38 @@ export class FormFillingWorkflow extends Workflow<
101101
StopEvent,
102102
],
103103
},
104-
this.handleLLMInput.bind(this),
104+
this.handleLLMInput,
105105
);
106106

107107
this.addStep(
108108
{
109109
inputs: [ExtractMissingCellsEvent],
110110
outputs: [InputEvent],
111111
},
112-
this.handleExtractMissingCells.bind(this),
112+
this.handleExtractMissingCells,
113113
);
114114

115115
this.addStep(
116116
{
117117
inputs: [FindAnswersEvent],
118118
outputs: [InputEvent],
119119
},
120-
this.handleFindAnswers.bind(this),
120+
this.handleFindAnswers,
121121
);
122122

123123
this.addStep(
124124
{
125125
inputs: [FillMissingCellsEvent],
126126
outputs: [InputEvent],
127127
},
128-
this.handleFillMissingCells.bind(this),
128+
this.handleFillMissingCells,
129129
);
130130
}
131131

132-
private async prepareChatHistory(
132+
prepareChatHistory = async (
133133
ctx: HandlerContext<null>,
134134
ev: StartEvent<AgentInput>,
135-
) {
135+
): Promise<InputEvent> => {
136136
const { message } = ev.data;
137137

138138
if (this.systemPrompt) {
@@ -141,9 +141,18 @@ export class FormFillingWorkflow extends Workflow<
141141
this.memory.put({ role: "user", content: message });
142142

143143
return new InputEvent({ input: this.memory.getMessages() });
144-
}
144+
};
145145

146-
private async handleLLMInput(ctx: HandlerContext<null>, ev: InputEvent) {
146+
handleLLMInput = async (
147+
ctx: HandlerContext<null>,
148+
ev: InputEvent,
149+
): Promise<
150+
| InputEvent
151+
| ExtractMissingCellsEvent
152+
| FindAnswersEvent
153+
| FillMissingCellsEvent
154+
| StopEvent
155+
> => {
147156
const chatHistory = ev.data.input;
148157

149158
const tools = [this.extractorTool, this.fillMissingCellsTool];
@@ -192,12 +201,12 @@ export class FormFillingWorkflow extends Workflow<
192201
}
193202
throw new Error(`Unknown tool: ${toolName}`);
194203
}
195-
}
204+
};
196205

197-
private async handleExtractMissingCells(
206+
handleExtractMissingCells = async (
198207
ctx: HandlerContext<null>,
199208
ev: ExtractMissingCellsEvent,
200-
) {
209+
): Promise<InputEvent> => {
201210
ctx.sendEvent(
202211
new AgentRunEvent({
203212
agent: "CSVExtractor",
@@ -216,12 +225,12 @@ export class FormFillingWorkflow extends Workflow<
216225
this.memory.put(toolMsg);
217226
}
218227
return new InputEvent({ input: this.memory.getMessages() });
219-
}
228+
};
220229

221-
private async handleFindAnswers(
230+
handleFindAnswers = async (
222231
ctx: HandlerContext<null>,
223232
ev: FindAnswersEvent,
224-
) {
233+
): Promise<InputEvent> => {
225234
const { toolCalls } = ev.data;
226235
if (!this.queryEngineTools) {
227236
throw new Error("Query engine tool is not available");
@@ -244,12 +253,12 @@ export class FormFillingWorkflow extends Workflow<
244253
this.memory.put(toolMsg);
245254
}
246255
return new InputEvent({ input: this.memory.getMessages() });
247-
}
256+
};
248257

249-
private async handleFillMissingCells(
258+
handleFillMissingCells = async (
250259
ctx: HandlerContext<null>,
251260
ev: FillMissingCellsEvent,
252-
) {
261+
): Promise<InputEvent> => {
253262
const { toolCalls } = ev.data;
254263

255264
const toolMsgs = await callTools({
@@ -262,5 +271,5 @@ export class FormFillingWorkflow extends Workflow<
262271
this.memory.put(toolMsg);
263272
}
264273
return new InputEvent({ input: this.memory.getMessages() });
265-
}
274+
};
266275
}

0 commit comments

Comments
 (0)