Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get rid of instanceof check in agent executor #725

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions langchain/src/agents/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export abstract class BaseAgent {
throw new Error("Not implemented");
}

/**
* Return the string type key uniquely identifying multi or single action agents.
*/
abstract _agentActionType(): string;

/**
* Return response when agent has been stopped due to max iterations
*/
Expand Down Expand Up @@ -73,6 +78,10 @@ export abstract class BaseAgent {
}

export abstract class BaseSingleActionAgent extends BaseAgent {
_agentActionType(): string {
return "single" as const;
}

/**
* Decide what to do, given some input.
*
Expand All @@ -88,6 +97,10 @@ export abstract class BaseSingleActionAgent extends BaseAgent {
}

export abstract class BaseMultiActionAgent extends BaseAgent {
_agentActionType(): string {
return "multi" as const;
}

/**
* Decide what to do, given some input.
*
Expand Down
3 changes: 1 addition & 2 deletions langchain/src/agents/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export class AgentExecutor extends BaseChain {
super(input.memory, input.verbose, input.callbackManager);
this.agent = input.agent;
this.tools = input.tools;
// eslint-disable-next-line no-instanceof/no-instanceof
if (this.agent instanceof BaseMultiActionAgent) {
if (this.agent._agentActionType() === "multi") {
for (const tool of this.tools) {
if (tool.returnDirect) {
throw new Error(
Expand Down