Skip to content

Commit

Permalink
Use .invoke for all agent docs and examples (langchain-ai#3319)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 authored Nov 17, 2023
1 parent ff7ef3d commit d2ec312
Show file tree
Hide file tree
Showing 53 changed files with 103 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ console.log("Loaded executor");

const input = "What is the weather in SF?";
console.log(`Calling executor with input: ${input}`);
const response = await executor.call({ input, tools });
const response = await executor.invoke({ input, tools });
console.log(response);
```

Expand Down
2 changes: 1 addition & 1 deletion docs/core_docs/docs/integrations/toolkits/json.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const run = async () => {

console.log(`Executing with input "${input}"...`);

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

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

Expand Down
2 changes: 1 addition & 1 deletion docs/core_docs/docs/integrations/toolkits/openapi.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const run = async () => {
const input = `Make a POST request to openai /completions. The prompt should be 'tell me a joke.'`;
console.log(`Executing with input "${input}"...`);

const result = await executor.call({ input });
const result = await executor.invoke({ input });
console.log(`Got output ${result.output}`);

console.log(
Expand Down
2 changes: 1 addition & 1 deletion docs/core_docs/docs/integrations/tools/lambda_agent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ const executor = await initializeAgentExecutorWithOptions(tools, model, {
});

const input = `Find out the capital of Croatia. Once you have it, email the answer to [email protected].`;
const result = await executor.call({ input });
const result = await executor.invoke({ input });
console.log(result);
```
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Finally we can call the agent, and save the output after the response is returne
```typescript
const query = "What is the weather in New York?";
console.log(`Calling agent executor with query: ${query}`);
const result = await executor.call({
const result = await executor.invoke({
input: query,
});
console.log(result);
Expand All @@ -109,7 +109,7 @@ await memory.saveContext(
);

const query2 = "Do I need a jacket?";
const result2 = await executor.call({
const result2 = await executor.invoke({
input: query2,
});
console.log(result2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const query =

console.log(`Calling agent executor with query: ${query}`);

const result = await executor.call({
const result = await executor.invoke({
input: query,
});

Expand All @@ -130,7 +130,7 @@ await memory.saveContext(

const query2 = "Do I need a jacket in New York?";

const result2 = await executor.call({
const result2 = await executor.invoke({
input: query2,
});
console.log(result2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ Once we have our `executor` calling the agent is simple!
console.log("Loaded agent.");
const input = `How many people live in canada as of 2023?`;
console.log(`Executing with input "${input}"...`);
const result = await executor.call({ input });
const result = await executor.invoke({ input });
console.log(`Got output ${result.output}`);
/**
Loaded agent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const input = `What did biden say about ketanji brown jackson is the state of th

console.log(`Executing with input "${input}"...`);

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

console.log(`Got output ${result.output}`);
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const run = async () => {

console.log(`Executing with input "${input}"...`);

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

console.log(`Got output ${result.output}`);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const executor = await createConversationalRetrievalAgent(model, [tool], {
We can now try it out!

```typescript
const result = await executor.call({
const result = await executor.invoke({
input: "Hi, I'm Bob!",
});

Expand All @@ -85,7 +85,7 @@ console.log(result);
}
*/

const result2 = await executor.call({
const result2 = await executor.invoke({
input: "What's my name?",
});

Expand All @@ -95,7 +95,7 @@ console.log(result2);
{ output: 'Your name is Bob.', intermediateSteps: [] }
*/

const result3 = await executor.call({
const result3 = await executor.invoke({
input:
"What did the president say about Ketanji Brown Jackson in the most recent state of the union?",
});
Expand All @@ -111,7 +111,7 @@ console.log(result3);
}
*/

const result4 = await executor.call({
const result4 = await executor.invoke({
input: "How long ago did he nominate her?",
});

Expand Down
29 changes: 17 additions & 12 deletions examples/src/agents/agent_callbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@ const executor = await initializeAgentExecutorWithOptions(tools, model, {
});

const input = `Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?`;
const result = await executor.run(input, [
const result = await executor.invoke(
{ input },
{
handleAgentAction(action, runId) {
console.log("\nhandleAgentAction", action, runId);
},
handleAgentEnd(action, runId) {
console.log("\nhandleAgentEnd", action, runId);
},
handleToolEnd(output, runId) {
console.log("\nhandleToolEnd", output, runId);
},
},
]);
callbacks: [
{
handleAgentAction(action, runId) {
console.log("\nhandleAgentAction", action, runId);
},
handleAgentEnd(action, runId) {
console.log("\nhandleAgentEnd", action, runId);
},
handleToolEnd(output, runId) {
console.log("\nhandleToolEnd", output, runId);
},
},
],
}
);
/*
handleAgentAction {
tool: 'search',
Expand Down
2 changes: 1 addition & 1 deletion examples/src/agents/agent_cancellation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ setTimeout(() => {

try {
const input = `Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?`;
const result = await executor.call({ input, signal: controller.signal });
const result = await executor.invoke({ input, signal: controller.signal });
} catch (e) {
console.log(e);
/*
Expand Down
2 changes: 1 addition & 1 deletion examples/src/agents/agent_timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const executor = await initializeAgentExecutorWithOptions(tools, model, {

try {
const input = `Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?`;
const result = await executor.call({ input, timeout: 2000 }); // 2 seconds
const result = await executor.invoke({ input, timeout: 2000 }); // 2 seconds
} catch (e) {
console.log(e);
/*
Expand Down
4 changes: 2 additions & 2 deletions examples/src/agents/aiplugin-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export const run = async () => {
"https://www.klarna.com/.well-known/ai-plugin.json"
),
];
const agent = await initializeAgentExecutorWithOptions(
const executor = await initializeAgentExecutorWithOptions(
tools,
new ChatOpenAI({ temperature: 0 }),
{ agentType: "chat-zero-shot-react-description", verbose: true }
);

const result = await agent.call({
const result = await executor.invoke({
input: "what t shirts are available in klarna?",
});

Expand Down
2 changes: 1 addition & 1 deletion examples/src/agents/aws_sfn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const run = async () => {

console.log(`Executing with input "${input}"...`);

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

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

Expand Down
6 changes: 3 additions & 3 deletions examples/src/agents/chat_convo_with_tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ export const run = async () => {

const input0 = "hi, i am bob";

const result0 = await executor.call({ input: input0 });
const result0 = await executor.invoke({ input: input0 });

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

const input1 = "whats my name?";

const result1 = await executor.call({ input: input1 });
const result1 = await executor.invoke({ input: input1 });

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

const input2 = "whats the weather in pomfret?";

const result2 = await executor.call({ input: input2 });
const result2 = await executor.invoke({ input: input2 });

console.log(`Got output ${result2.output}`);
};
6 changes: 3 additions & 3 deletions examples/src/agents/chat_convo_with_tracing_runnable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ const executor = AgentExecutor.fromAgentAndTools({
console.log("Loaded agent.");

const input0 = "hi, i am bob";
const result0 = await executor.call({ input: input0 });
const result0 = await executor.invoke({ input: input0 });
console.log(`Got output ${result0.output}`);

const input1 = "whats my name?";
const result1 = await executor.call({ input: input1 });
const result1 = await executor.invoke({ input: input1 });
console.log(`Got output ${result1.output}`);

const input2 = "whats the weather in pomfret?";
const result2 = await executor.call({ input: input2 });
const result2 = await executor.invoke({ input: input2 });
console.log(`Got output ${result2.output}`);
/**
* Loaded agent.
Expand Down
2 changes: 1 addition & 1 deletion examples/src/agents/chat_mrkl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const run = async () => {

console.log(`Executing with input "${input}"...`);

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

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

Expand Down
2 changes: 1 addition & 1 deletion examples/src/agents/chat_mrkl_with_tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const run = async () => {

console.log(`Executing with input "${input}"...`);

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

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

Expand Down
6 changes: 3 additions & 3 deletions examples/src/agents/concurrent_mrkl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export const run = async () => {

// This will result in a lot of errors, because the shared Tracer is not concurrency-safe.
const [resultA, resultB, resultC] = await Promise.all([
executor.call({ input }),
executor.call({ input }),
executor.call({ input }),
executor.invoke({ input }),
executor.invoke({ input }),
executor.invoke({ input }),
]);

console.log(`Got output ${resultA.output} ${resultA.__run.runId}`);
Expand Down
2 changes: 1 addition & 1 deletion examples/src/agents/custom_agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Question: {input}

console.log(`Executing with input "${input}"...`);

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

console.log(`Got output ${result.output}`);
};
2 changes: 1 addition & 1 deletion examples/src/agents/custom_llm_agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const run = async () => {

console.log(`Executing with input "${input}"...`);

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

console.log(`Got output ${result.output}`);
};
2 changes: 1 addition & 1 deletion examples/src/agents/custom_llm_agent_chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export const run = async () => {

console.log(`Executing with input "${input}"...`);

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

console.log(`Got output ${result.output}`);
};
Expand Down
2 changes: 1 addition & 1 deletion examples/src/agents/custom_llm_agent_chat_runnable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const input = `Who is Olivia Wilde's boyfriend? What is his current age raised t

console.log(`Executing with input "${input}"...`);

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

console.log(`Got output ${result.output}`);
/**
Expand Down
4 changes: 2 additions & 2 deletions examples/src/agents/custom_llm_agent_runnable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function customOutputParser(text: string): AgentAction | AgentFinish {
const finalAnswers = { output: input };
return { log: text, returnValues: finalAnswers };
}
/** Use RegEx to extract any actions and their values */
/** Use regex to extract any actions and their values */
const match = /Action: (.*)\nAction Input: (.*)/s.exec(text);
if (!match) {
throw new Error(`Could not parse LLM output: ${text}`);
Expand Down Expand Up @@ -145,7 +145,7 @@ const input = `Who is Olivia Wilde's boyfriend? What is his current age raised t

console.log(`Executing with input "${input}"...`);

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

console.log(`Got output ${result.output}`);
/**
Expand Down
2 changes: 1 addition & 1 deletion examples/src/agents/custom_tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const run = async () => {

console.log(`Executing with input "${input}"...`);

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

console.log(`Got output ${result.output}`);
};
2 changes: 1 addition & 1 deletion examples/src/agents/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const run = async () => {

console.log(`Executing with input "${input}"...`);

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

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

Expand Down
2 changes: 1 addition & 1 deletion examples/src/agents/load_from_hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const run = async () => {
const input = `Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?`;
console.log(`Executing with input "${input}"...`);

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

console.log(`Got output ${result.output}`);
};
8 changes: 7 additions & 1 deletion examples/src/agents/mrkl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ const executor = await initializeAgentExecutorWithOptions(tools, model, {

const input = `Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?`;

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

console.log(result);

/*
{ output: '2.2800773226742175' }
*/
2 changes: 1 addition & 1 deletion examples/src/agents/mrkl_browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const run = async () => {

console.log(`Executing with input "${input}"...`);

const result = await executor.call({ input });
const result = await executor.invoke({ input });
/*
Entering new agent_executor chain...
I need to find the word of the day on Merriam Webster and then search for it on Google
Expand Down
2 changes: 1 addition & 1 deletion examples/src/agents/mrkl_runnable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ console.log("Loaded agent executor");

const input = `Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?`;
console.log(`Calling agent with prompt: ${input}`);
const result = await executor.call({ input });
const result = await executor.invoke({ input });
console.log(result);
/**
Loaded agent executor
Expand Down
Loading

0 comments on commit d2ec312

Please sign in to comment.