Skip to content

Commit c11bcff

Browse files
fix: pass apiKeys from AgentContext to ReasoningContext for LLM calls
1 parent 5b49401 commit c11bcff

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

app/lib/agent-sdk/core/agent.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export class Agent {
258258
}
259259
}
260260

261-
private async _generatePlan(task: string, _context: AgentContext): Promise<Plan> {
261+
private async _generatePlan(task: string, context: AgentContext): Promise<Plan> {
262262
if (!this._reasoningPattern) {
263263
throw new Error('Reasoning pattern not initialized');
264264
}
@@ -268,6 +268,10 @@ export class Agent {
268268
currentState: this._state,
269269
availableTools: this._toolExecutor?.getAvailableTools() || [],
270270
previousResults: [],
271+
apiKeys: context.apiKeys,
272+
files: context.files,
273+
webcontainer: context.webcontainer,
274+
workingDirectory: context.workingDirectory,
271275
};
272276

273277
return await this._reasoningPattern.generatePlan(task, reasoningContext);
@@ -292,7 +296,7 @@ export class Agent {
292296
return results;
293297
}
294298

295-
private async _executeStep(step: PlanStep, _context: AgentContext): Promise<any> {
299+
private async _executeStep(step: PlanStep, context: AgentContext): Promise<any> {
296300
if (!this._reasoningPattern) {
297301
throw new Error('Reasoning pattern not initialized');
298302
}
@@ -302,12 +306,16 @@ export class Agent {
302306
currentState: this._state,
303307
availableTools: this._toolExecutor?.getAvailableTools() || [],
304308
previousResults: [],
309+
apiKeys: context.apiKeys,
310+
files: context.files,
311+
webcontainer: context.webcontainer,
312+
workingDirectory: context.workingDirectory,
305313
};
306314

307315
return await this._reasoningPattern.executeStep(step, reasoningContext);
308316
}
309317

310-
private async _reflect(results: any[], task: string, _context: AgentContext): Promise<Reflection> {
318+
private async _reflect(results: any[], task: string, context: AgentContext): Promise<Reflection> {
311319
if (!this._reasoningPattern) {
312320
throw new Error('Reasoning pattern not initialized');
313321
}
@@ -317,6 +325,10 @@ export class Agent {
317325
currentState: this._state,
318326
availableTools: this._toolExecutor?.getAvailableTools() || [],
319327
previousResults: results,
328+
apiKeys: context.apiKeys,
329+
files: context.files,
330+
webcontainer: context.webcontainer,
331+
workingDirectory: context.workingDirectory,
320332
};
321333

322334
return await this._reasoningPattern.reflect(results, task, reasoningContext);

app/lib/agent-sdk/reasoning/plan-execute.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class PlanExecuteReasoning implements ReasoningPattern {
9090
},
9191
],
9292

93-
apiKeys: {},
93+
apiKeys: context.apiKeys || {},
9494
options: {},
9595
});
9696

@@ -129,7 +129,7 @@ export class PlanExecuteReasoning implements ReasoningPattern {
129129
};
130130
}
131131

132-
async reflect(results: StepResult[], goal: string, _context: ReasoningContext): Promise<Reflection> {
132+
async reflect(results: StepResult[], goal: string, context: ReasoningContext): Promise<Reflection> {
133133
logger.info('Reflecting on execution results');
134134

135135
const executedSteps = results.map((r) => `Step ${r.stepNumber}: ${r.success ? 'Success' : 'Failed'}`).join('\n');
@@ -154,7 +154,7 @@ export class PlanExecuteReasoning implements ReasoningPattern {
154154
},
155155
],
156156

157-
apiKeys: {},
157+
apiKeys: context.apiKeys || {},
158158
options: {},
159159
});
160160

0 commit comments

Comments
 (0)