Skip to content

Commit f78f2e9

Browse files
authored
Merge pull request langchain-ai#902 from jacobrosenthal/jacob/async-construct
feat: agent make constructScratchPad async
2 parents 7b9b67d + 058f20a commit f78f2e9

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

langchain/src/agents/agent.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ export abstract class Agent extends BaseSingleActionAgent {
262262
/**
263263
* Construct a scratchpad to let the agent continue its thought process
264264
*/
265-
constructScratchPad(steps: AgentStep[]): string | BaseChatMessage[] {
265+
async constructScratchPad(
266+
steps: AgentStep[]
267+
): Promise<string | BaseChatMessage[]> {
266268
return steps.reduce(
267269
(thoughts, { action, observation }) =>
268270
thoughts +
@@ -280,7 +282,7 @@ export abstract class Agent extends BaseSingleActionAgent {
280282
inputs: ChainValues,
281283
suffix?: string
282284
): Promise<AgentAction | AgentFinish> {
283-
const thoughts = this.constructScratchPad(steps);
285+
const thoughts = await this.constructScratchPad(steps);
284286
const newInputs: ChainValues = {
285287
...inputs,
286288
agent_scratchpad: suffix ? `${thoughts}${suffix}` : thoughts,

langchain/src/agents/chat/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ export class ChatAgent extends Agent {
6565
return new ChatAgentOutputParser();
6666
}
6767

68-
constructScratchPad(steps: AgentStep[]): string {
69-
const agentScratchpad = super.constructScratchPad(steps);
68+
async constructScratchPad(steps: AgentStep[]): Promise<string> {
69+
const agentScratchpad = await super.constructScratchPad(steps);
7070
if (agentScratchpad) {
7171
return `This was your previous work (but I haven't seen any of it! I only see what you return as final answer):\n${agentScratchpad}`;
7272
}

langchain/src/agents/chat_convo/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class ChatConversationalAgent extends Agent {
7575
}
7676
}
7777

78-
constructScratchPad(steps: AgentStep[]): BaseChatMessage[] {
78+
async constructScratchPad(steps: AgentStep[]): Promise<BaseChatMessage[]> {
7979
const thoughts: BaseChatMessage[] = [];
8080
for (const step of steps) {
8181
thoughts.push(new AIChatMessage(step.action.log));

0 commit comments

Comments
 (0)