Skip to content

Commit

Permalink
fix: bring back output parser
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Oct 16, 2023
1 parent 9546e50 commit dc4320d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
15 changes: 6 additions & 9 deletions langchain/src/agents/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
StoppingMethod,
} from "./types.js";
import { Runnable } from "../schema/runnable/base.js";
import { StringOutputParser } from "../schema/output_parser.js";

/**
* Record type for arguments passed to output parsers.
Expand Down Expand Up @@ -416,15 +417,11 @@ export abstract class Agent<
}

const output = await this.runnable.invoke(newInputs, callbackManager);
console.log({
newInputs,
output,
});
return output;
// if (!this.outputParser) {
// throw new Error("Output parser not set");
// }
// return this.outputParser.parse(output, callbackManager);

if (!this.outputParser) {
throw new Error("Output parser not set");
}
return this.outputParser.parse(output, callbackManager);
}

/**
Expand Down
31 changes: 24 additions & 7 deletions langchain/src/agents/tests/agent.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ test("Run agent from hub", async () => {
input:
"Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?",
});
console.log(res);
console.log(
{
res,
},
"Run agent from hub response"
);
});

test("Pass runnable to agent executor", async () => {
Expand Down Expand Up @@ -75,7 +80,12 @@ test("Pass runnable to agent executor", async () => {
input:
"Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?",
});
console.log(res);
console.log(
{
res,
},
"Pass runnable to agent executor"
);
});

test("Run agent locally", async () => {
Expand All @@ -98,8 +108,12 @@ test("Run agent locally", async () => {
console.log(`Executing with input "${input}"...`);

const result = await executor.call({ input });

console.log(`Got output ${result.output}`);
console.log(
{
result,
},
"Run agent locally"
);
});

test("Run agent with an abort signal", async () => {
Expand Down Expand Up @@ -184,9 +198,12 @@ test("Run tool web-browser", async () => {
console.log(`Executing with input "${input}"...`);

const result = await executor.call({ input });

console.log(`Got output ${result.output}`);

console.log(
{
result,
},
"Run tool web-browser"
);
expect(result.intermediateSteps.length).toBeGreaterThanOrEqual(1);
expect(result.intermediateSteps[0].action.tool).toEqual("web-browser");
expect(result.output).not.toEqual("");
Expand Down

0 comments on commit dc4320d

Please sign in to comment.