Skip to content

Commit

Permalink
Merge pull request langchain-ai#902 from jacobrosenthal/jacob/async-c…
Browse files Browse the repository at this point in the history
…onstruct

feat: agent make constructScratchPad async
  • Loading branch information
nfcampos authored Apr 20, 2023
2 parents 7b9b67d + 058f20a commit f78f2e9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions langchain/src/agents/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ export abstract class Agent extends BaseSingleActionAgent {
/**
* Construct a scratchpad to let the agent continue its thought process
*/
constructScratchPad(steps: AgentStep[]): string | BaseChatMessage[] {
async constructScratchPad(
steps: AgentStep[]
): Promise<string | BaseChatMessage[]> {
return steps.reduce(
(thoughts, { action, observation }) =>
thoughts +
Expand All @@ -280,7 +282,7 @@ export abstract class Agent extends BaseSingleActionAgent {
inputs: ChainValues,
suffix?: string
): Promise<AgentAction | AgentFinish> {
const thoughts = this.constructScratchPad(steps);
const thoughts = await this.constructScratchPad(steps);
const newInputs: ChainValues = {
...inputs,
agent_scratchpad: suffix ? `${thoughts}${suffix}` : thoughts,
Expand Down
4 changes: 2 additions & 2 deletions langchain/src/agents/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export class ChatAgent extends Agent {
return new ChatAgentOutputParser();
}

constructScratchPad(steps: AgentStep[]): string {
const agentScratchpad = super.constructScratchPad(steps);
async constructScratchPad(steps: AgentStep[]): Promise<string> {
const agentScratchpad = await super.constructScratchPad(steps);
if (agentScratchpad) {
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}`;
}
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/agents/chat_convo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class ChatConversationalAgent extends Agent {
}
}

constructScratchPad(steps: AgentStep[]): BaseChatMessage[] {
async constructScratchPad(steps: AgentStep[]): Promise<BaseChatMessage[]> {
const thoughts: BaseChatMessage[] = [];
for (const step of steps) {
thoughts.push(new AIChatMessage(step.action.log));
Expand Down

0 comments on commit f78f2e9

Please sign in to comment.