From d2ec312f48f07fd900a9e8ceb2790eea2c740476 Mon Sep 17 00:00:00 2001 From: Jacob Lee Date: Fri, 17 Nov 2023 08:14:53 -0800 Subject: [PATCH] Use .invoke for all agent docs and examples (#3319) --- .../expression_language/cookbook/agents.mdx | 2 +- .../docs/integrations/toolkits/json.mdx | 2 +- .../docs/integrations/toolkits/openapi.mdx | 2 +- .../docs/integrations/tools/lambda_agent.mdx | 2 +- .../agent_types/openai_functions_agent.mdx | 4 +-- .../agents/agent_types/openai_tools_agent.mdx | 4 +-- .../agents/how_to/custom_mrkl_agent.mdx | 2 +- .../tools/how_to/agents_with_vectorstores.mdx | 2 +- .../modules/agents/tools/how_to/dynamic.mdx | 2 +- .../conversational_retrieval_agents.mdx | 8 ++--- examples/src/agents/agent_callbacks.ts | 29 +++++++++++-------- examples/src/agents/agent_cancellation.ts | 2 +- examples/src/agents/agent_timeout.ts | 2 +- examples/src/agents/aiplugin-tool.ts | 4 +-- examples/src/agents/aws_sfn.ts | 2 +- .../src/agents/chat_convo_with_tracing.ts | 6 ++-- .../chat_convo_with_tracing_runnable.ts | 6 ++-- examples/src/agents/chat_mrkl.ts | 2 +- examples/src/agents/chat_mrkl_with_tracing.ts | 2 +- examples/src/agents/concurrent_mrkl.ts | 6 ++-- examples/src/agents/custom_agent.ts | 2 +- examples/src/agents/custom_llm_agent.ts | 2 +- examples/src/agents/custom_llm_agent_chat.ts | 2 +- .../agents/custom_llm_agent_chat_runnable.ts | 2 +- .../src/agents/custom_llm_agent_runnable.ts | 4 +-- examples/src/agents/custom_tool.ts | 2 +- examples/src/agents/json.ts | 2 +- examples/src/agents/load_from_hub.ts | 2 +- examples/src/agents/mrkl.ts | 8 ++++- examples/src/agents/mrkl_browser.ts | 2 +- examples/src/agents/mrkl_runnable.ts | 2 +- examples/src/agents/mrkl_with_tracing.ts | 2 +- examples/src/agents/openai.ts | 4 ++- examples/src/agents/openai_custom_prompt.ts | 4 ++- examples/src/agents/openai_runnable.ts | 2 +- examples/src/agents/openapi.ts | 2 +- examples/src/agents/plan_and_execute.ts | 2 +- examples/src/agents/sql.ts | 2 +- examples/src/agents/sql_sap_hana.ts | 2 +- examples/src/agents/streaming.ts | 4 +-- examples/src/agents/structured_chat.ts | 2 +- .../src/agents/structured_chat_runnable.ts | 2 +- .../src/agents/structured_chat_with_memory.ts | 6 ++-- examples/src/agents/vectorstore.ts | 2 +- examples/src/agents/xml.ts | 2 +- examples/src/agents/xml_runnable.ts | 2 +- examples/src/agents/zapier_mrkl.ts | 2 +- examples/src/chat/agent.ts | 6 ++-- examples/src/chat/overview.ts | 6 ++-- .../guides/conversational_retrieval/agent.ts | 8 ++--- .../evaluation/agent_trajectory/trajectory.ts | 2 +- examples/src/models/llm/raycast.ts | 2 +- examples/src/tools/searxng_search.ts | 2 +- 53 files changed, 103 insertions(+), 86 deletions(-) diff --git a/docs/core_docs/docs/expression_language/cookbook/agents.mdx b/docs/core_docs/docs/expression_language/cookbook/agents.mdx index 2d1bbf283102..2cf097e35ee6 100644 --- a/docs/core_docs/docs/expression_language/cookbook/agents.mdx +++ b/docs/core_docs/docs/expression_language/cookbook/agents.mdx @@ -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); ``` diff --git a/docs/core_docs/docs/integrations/toolkits/json.mdx b/docs/core_docs/docs/integrations/toolkits/json.mdx index f197159a0ddf..cc436c7f919b 100644 --- a/docs/core_docs/docs/integrations/toolkits/json.mdx +++ b/docs/core_docs/docs/integrations/toolkits/json.mdx @@ -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}`); diff --git a/docs/core_docs/docs/integrations/toolkits/openapi.mdx b/docs/core_docs/docs/integrations/toolkits/openapi.mdx index e748b2989148..1f05dce25ef8 100644 --- a/docs/core_docs/docs/integrations/toolkits/openapi.mdx +++ b/docs/core_docs/docs/integrations/toolkits/openapi.mdx @@ -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( diff --git a/docs/core_docs/docs/integrations/tools/lambda_agent.mdx b/docs/core_docs/docs/integrations/tools/lambda_agent.mdx index bbdc0d5a2f7f..13e53748a69a 100644 --- a/docs/core_docs/docs/integrations/tools/lambda_agent.mdx +++ b/docs/core_docs/docs/integrations/tools/lambda_agent.mdx @@ -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 testing123@gmail.com.`; -const result = await executor.call({ input }); +const result = await executor.invoke({ input }); console.log(result); ``` diff --git a/docs/core_docs/docs/modules/agents/agent_types/openai_functions_agent.mdx b/docs/core_docs/docs/modules/agents/agent_types/openai_functions_agent.mdx index 6d59911d0c5b..b55b35ab8f46 100644 --- a/docs/core_docs/docs/modules/agents/agent_types/openai_functions_agent.mdx +++ b/docs/core_docs/docs/modules/agents/agent_types/openai_functions_agent.mdx @@ -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); @@ -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); diff --git a/docs/core_docs/docs/modules/agents/agent_types/openai_tools_agent.mdx b/docs/core_docs/docs/modules/agents/agent_types/openai_tools_agent.mdx index 79da730a2de9..d999fb07b182 100644 --- a/docs/core_docs/docs/modules/agents/agent_types/openai_tools_agent.mdx +++ b/docs/core_docs/docs/modules/agents/agent_types/openai_tools_agent.mdx @@ -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, }); @@ -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); diff --git a/docs/core_docs/docs/modules/agents/how_to/custom_mrkl_agent.mdx b/docs/core_docs/docs/modules/agents/how_to/custom_mrkl_agent.mdx index d880e087df8b..f67552a0ddbe 100644 --- a/docs/core_docs/docs/modules/agents/how_to/custom_mrkl_agent.mdx +++ b/docs/core_docs/docs/modules/agents/how_to/custom_mrkl_agent.mdx @@ -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. diff --git a/docs/core_docs/docs/modules/agents/tools/how_to/agents_with_vectorstores.mdx b/docs/core_docs/docs/modules/agents/tools/how_to/agents_with_vectorstores.mdx index ea1f4172dee6..c023ad84b400 100644 --- a/docs/core_docs/docs/modules/agents/tools/how_to/agents_with_vectorstores.mdx +++ b/docs/core_docs/docs/modules/agents/tools/how_to/agents_with_vectorstores.mdx @@ -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}`); ``` diff --git a/docs/core_docs/docs/modules/agents/tools/how_to/dynamic.mdx b/docs/core_docs/docs/modules/agents/tools/how_to/dynamic.mdx index 89a91601c678..6650a0f4ad80 100644 --- a/docs/core_docs/docs/modules/agents/tools/how_to/dynamic.mdx +++ b/docs/core_docs/docs/modules/agents/tools/how_to/dynamic.mdx @@ -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}`); }; diff --git a/docs/core_docs/docs/use_cases/question_answering/conversational_retrieval_agents.mdx b/docs/core_docs/docs/use_cases/question_answering/conversational_retrieval_agents.mdx index 53ce137c1e2c..1f0094fd6222 100644 --- a/docs/core_docs/docs/use_cases/question_answering/conversational_retrieval_agents.mdx +++ b/docs/core_docs/docs/use_cases/question_answering/conversational_retrieval_agents.mdx @@ -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!", }); @@ -85,7 +85,7 @@ console.log(result); } */ -const result2 = await executor.call({ +const result2 = await executor.invoke({ input: "What's my name?", }); @@ -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?", }); @@ -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?", }); diff --git a/examples/src/agents/agent_callbacks.ts b/examples/src/agents/agent_callbacks.ts index 03861a0e9875..a69f7256c74a 100644 --- a/examples/src/agents/agent_callbacks.ts +++ b/examples/src/agents/agent_callbacks.ts @@ -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', diff --git a/examples/src/agents/agent_cancellation.ts b/examples/src/agents/agent_cancellation.ts index 228996d27207..99e9c9ab1173 100644 --- a/examples/src/agents/agent_cancellation.ts +++ b/examples/src/agents/agent_cancellation.ts @@ -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); /* diff --git a/examples/src/agents/agent_timeout.ts b/examples/src/agents/agent_timeout.ts index 0ecbe322a99d..358e1be407d1 100644 --- a/examples/src/agents/agent_timeout.ts +++ b/examples/src/agents/agent_timeout.ts @@ -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); /* diff --git a/examples/src/agents/aiplugin-tool.ts b/examples/src/agents/aiplugin-tool.ts index 02b3ed2c44fa..e5e90d5718cd 100644 --- a/examples/src/agents/aiplugin-tool.ts +++ b/examples/src/agents/aiplugin-tool.ts @@ -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?", }); diff --git a/examples/src/agents/aws_sfn.ts b/examples/src/agents/aws_sfn.ts index 640fefd08081..b0eeb4aff8a5 100644 --- a/examples/src/agents/aws_sfn.ts +++ b/examples/src/agents/aws_sfn.ts @@ -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}`); diff --git a/examples/src/agents/chat_convo_with_tracing.ts b/examples/src/agents/chat_convo_with_tracing.ts index ad47f4020cff..042441a4fcda 100644 --- a/examples/src/agents/chat_convo_with_tracing.ts +++ b/examples/src/agents/chat_convo_with_tracing.ts @@ -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}`); }; diff --git a/examples/src/agents/chat_convo_with_tracing_runnable.ts b/examples/src/agents/chat_convo_with_tracing_runnable.ts index d5f86afbcaeb..06f654bd8cdf 100644 --- a/examples/src/agents/chat_convo_with_tracing_runnable.ts +++ b/examples/src/agents/chat_convo_with_tracing_runnable.ts @@ -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. diff --git a/examples/src/agents/chat_mrkl.ts b/examples/src/agents/chat_mrkl.ts index e4f4b489d884..e7d32d0c8158 100644 --- a/examples/src/agents/chat_mrkl.ts +++ b/examples/src/agents/chat_mrkl.ts @@ -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}`); diff --git a/examples/src/agents/chat_mrkl_with_tracing.ts b/examples/src/agents/chat_mrkl_with_tracing.ts index c837bc2fe442..99aae22fbf7d 100644 --- a/examples/src/agents/chat_mrkl_with_tracing.ts +++ b/examples/src/agents/chat_mrkl_with_tracing.ts @@ -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}`); diff --git a/examples/src/agents/concurrent_mrkl.ts b/examples/src/agents/concurrent_mrkl.ts index e0effd8058be..a68e898ec002 100644 --- a/examples/src/agents/concurrent_mrkl.ts +++ b/examples/src/agents/concurrent_mrkl.ts @@ -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}`); diff --git a/examples/src/agents/custom_agent.ts b/examples/src/agents/custom_agent.ts index 67490a0d60e0..e2a8085e97a8 100644 --- a/examples/src/agents/custom_agent.ts +++ b/examples/src/agents/custom_agent.ts @@ -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}`); }; diff --git a/examples/src/agents/custom_llm_agent.ts b/examples/src/agents/custom_llm_agent.ts index 37bfd3be8b54..a019be998843 100644 --- a/examples/src/agents/custom_llm_agent.ts +++ b/examples/src/agents/custom_llm_agent.ts @@ -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}`); }; diff --git a/examples/src/agents/custom_llm_agent_chat.ts b/examples/src/agents/custom_llm_agent_chat.ts index f09d4f069a56..06b917e408cb 100644 --- a/examples/src/agents/custom_llm_agent_chat.ts +++ b/examples/src/agents/custom_llm_agent_chat.ts @@ -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}`); }; diff --git a/examples/src/agents/custom_llm_agent_chat_runnable.ts b/examples/src/agents/custom_llm_agent_chat_runnable.ts index 85af613fdc01..0b73752ef7c6 100644 --- a/examples/src/agents/custom_llm_agent_chat_runnable.ts +++ b/examples/src/agents/custom_llm_agent_chat_runnable.ts @@ -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}`); /** diff --git a/examples/src/agents/custom_llm_agent_runnable.ts b/examples/src/agents/custom_llm_agent_runnable.ts index 44b3f944cb9b..37facfaa4dd7 100644 --- a/examples/src/agents/custom_llm_agent_runnable.ts +++ b/examples/src/agents/custom_llm_agent_runnable.ts @@ -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}`); @@ -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}`); /** diff --git a/examples/src/agents/custom_tool.ts b/examples/src/agents/custom_tool.ts index d8c0336b60b9..8ead5958e670 100644 --- a/examples/src/agents/custom_tool.ts +++ b/examples/src/agents/custom_tool.ts @@ -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}`); }; diff --git a/examples/src/agents/json.ts b/examples/src/agents/json.ts index 9d61dea29c5e..b2b64a0a8655 100644 --- a/examples/src/agents/json.ts +++ b/examples/src/agents/json.ts @@ -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}`); diff --git a/examples/src/agents/load_from_hub.ts b/examples/src/agents/load_from_hub.ts index 31d90d586969..a07c106d50c5 100644 --- a/examples/src/agents/load_from_hub.ts +++ b/examples/src/agents/load_from_hub.ts @@ -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}`); }; diff --git a/examples/src/agents/mrkl.ts b/examples/src/agents/mrkl.ts index b1e2a6e0b736..c485d7c6bb76 100644 --- a/examples/src/agents/mrkl.ts +++ b/examples/src/agents/mrkl.ts @@ -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' } +*/ diff --git a/examples/src/agents/mrkl_browser.ts b/examples/src/agents/mrkl_browser.ts index b25821ece38f..850f33a52d23 100644 --- a/examples/src/agents/mrkl_browser.ts +++ b/examples/src/agents/mrkl_browser.ts @@ -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 diff --git a/examples/src/agents/mrkl_runnable.ts b/examples/src/agents/mrkl_runnable.ts index 667c938f3462..b9898fb7a8f4 100644 --- a/examples/src/agents/mrkl_runnable.ts +++ b/examples/src/agents/mrkl_runnable.ts @@ -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 diff --git a/examples/src/agents/mrkl_with_tracing.ts b/examples/src/agents/mrkl_with_tracing.ts index e13e7c164801..078091343a94 100644 --- a/examples/src/agents/mrkl_with_tracing.ts +++ b/examples/src/agents/mrkl_with_tracing.ts @@ -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}`); }; diff --git a/examples/src/agents/openai.ts b/examples/src/agents/openai.ts index 10e009bb0f1e..df372a9b85d4 100644 --- a/examples/src/agents/openai.ts +++ b/examples/src/agents/openai.ts @@ -11,7 +11,9 @@ const executor = await initializeAgentExecutorWithOptions(tools, chat, { verbose: true, }); -const result = await executor.run("What is the weather in New York?"); +const result = await executor.invoke({ + input: "What is the weather in New York?", +}); console.log(result); /* diff --git a/examples/src/agents/openai_custom_prompt.ts b/examples/src/agents/openai_custom_prompt.ts index 2efd210d1ca4..b0873e5f780b 100644 --- a/examples/src/agents/openai_custom_prompt.ts +++ b/examples/src/agents/openai_custom_prompt.ts @@ -16,7 +16,9 @@ const executor = await initializeAgentExecutorWithOptions(tools, chat, { }, }); -const result = await executor.run("What is the weather in New York?"); +const result = await executor.invoke({ + input: "What is the weather in New York?", +}); console.log(result); // Arr matey, in New York, it be feelin' like 75 degrees, with a gentle breeze blowin' from the northwest at 3 knots. The air be 77% full o' water, and the clouds be coverin' 35% of the sky. There be no rain in sight, yarr! diff --git a/examples/src/agents/openai_runnable.ts b/examples/src/agents/openai_runnable.ts index 8cc0f22a6190..fd57cbd9871e 100644 --- a/examples/src/agents/openai_runnable.ts +++ b/examples/src/agents/openai_runnable.ts @@ -81,7 +81,7 @@ console.log("Loaded agent executor"); 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); diff --git a/examples/src/agents/openapi.ts b/examples/src/agents/openapi.ts index 130a61cc186f..fc32c7011f38 100644 --- a/examples/src/agents/openapi.ts +++ b/examples/src/agents/openapi.ts @@ -28,7 +28,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( diff --git a/examples/src/agents/plan_and_execute.ts b/examples/src/agents/plan_and_execute.ts index 5c09c198939b..096b7492449b 100644 --- a/examples/src/agents/plan_and_execute.ts +++ b/examples/src/agents/plan_and_execute.ts @@ -14,7 +14,7 @@ const executor = await PlanAndExecuteAgentExecutor.fromLLMAndTools({ tools, }); -const result = await executor.call({ +const result = await executor.invoke({ input: `Who is the current president of the United States? What is their current age raised to the second power?`, }); diff --git a/examples/src/agents/sql.ts b/examples/src/agents/sql.ts index da6b3ea058d9..8da25af83396 100644 --- a/examples/src/agents/sql.ts +++ b/examples/src/agents/sql.ts @@ -23,7 +23,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}`); diff --git a/examples/src/agents/sql_sap_hana.ts b/examples/src/agents/sql_sap_hana.ts index 24624d364222..c5765c052361 100644 --- a/examples/src/agents/sql_sap_hana.ts +++ b/examples/src/agents/sql_sap_hana.ts @@ -55,7 +55,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}`); diff --git a/examples/src/agents/streaming.ts b/examples/src/agents/streaming.ts index de1ec12bba4a..a614ba5e9126 100644 --- a/examples/src/agents/streaming.ts +++ b/examples/src/agents/streaming.ts @@ -83,11 +83,11 @@ export const run = async () => { * The `handler2` callback handler will only be used for callbacks related to the * LLMChain and LLM, since we passed it to the LLMChain and LLM objects upon creation. */ - const result = await agentExecutor.call( + const result = await agentExecutor.invoke( { input: "What is 2 to the power of 8", }, - [handler1] + { callbacks: [handler1] } ); // this is needed to see handleAgentAction /* handleChainStart { chain: { name: 'agent_executor' } } diff --git a/examples/src/agents/structured_chat.ts b/examples/src/agents/structured_chat.ts index db1449f38f3a..6ab834abeb3c 100644 --- a/examples/src/agents/structured_chat.ts +++ b/examples/src/agents/structured_chat.ts @@ -31,7 +31,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({ result }); diff --git a/examples/src/agents/structured_chat_runnable.ts b/examples/src/agents/structured_chat_runnable.ts index 32523aad4f89..266f62bdd182 100644 --- a/examples/src/agents/structured_chat_runnable.ts +++ b/examples/src/agents/structured_chat_runnable.ts @@ -179,7 +179,7 @@ console.log("Loaded agent."); const input = `What is a random number between 5 and 10 raised to the second power?`; console.log(`Executing with input "${input}"...`); -const result = await executor.call({ input }); +const result = await executor.invoke({ input }); console.log(result); /* diff --git a/examples/src/agents/structured_chat_with_memory.ts b/examples/src/agents/structured_chat_with_memory.ts index 5580a8aa6cc2..74a3e948987e 100644 --- a/examples/src/agents/structured_chat_with_memory.ts +++ b/examples/src/agents/structured_chat_with_memory.ts @@ -21,7 +21,9 @@ export const run = async () => { }, }); - const result = await executor.call({ input: `what is 9 to the 2nd power?` }); + const result = await executor.invoke({ + input: `what is 9 to the 2nd power?`, + }); console.log(result); @@ -31,7 +33,7 @@ export const run = async () => { } */ - const result2 = await executor.call({ + const result2 = await executor.invoke({ input: `what is that number squared?`, }); diff --git a/examples/src/agents/vectorstore.ts b/examples/src/agents/vectorstore.ts index 880806629c8c..274ec75402e3 100644 --- a/examples/src/agents/vectorstore.ts +++ b/examples/src/agents/vectorstore.ts @@ -32,7 +32,7 @@ const input = "What did biden say about Ketanji Brown Jackson is the state of the union address?"; console.log(`Executing: ${input}`); -const result = await agent.call({ input }); +const result = await agent.invoke({ input }); console.log(`Got output ${result.output}`); console.log( `Got intermediate steps ${JSON.stringify(result.intermediateSteps, null, 2)}` diff --git a/examples/src/agents/xml.ts b/examples/src/agents/xml.ts index edc855655bbf..06fcb08dd153 100644 --- a/examples/src/agents/xml.ts +++ b/examples/src/agents/xml.ts @@ -13,7 +13,7 @@ console.log("Loaded agent."); const input = `What is the weather in Honolulu?`; -const result = await executor.call({ input }); +const result = await executor.invoke({ input }); console.log(result); diff --git a/examples/src/agents/xml_runnable.ts b/examples/src/agents/xml_runnable.ts index d02fadf67fa9..4420e730ea85 100644 --- a/examples/src/agents/xml_runnable.ts +++ b/examples/src/agents/xml_runnable.ts @@ -92,7 +92,7 @@ console.log("Loaded agent."); const input = `What is the weather in Honolulu?`; console.log(`Calling executor with input: ${input}`); -const result = await executor.call({ input, tools }); +const result = await executor.invoke({ input, tools }); console.log(result); /* diff --git a/examples/src/agents/zapier_mrkl.ts b/examples/src/agents/zapier_mrkl.ts index 30b0b8cbe8ec..d806ea3cd50f 100644 --- a/examples/src/agents/zapier_mrkl.ts +++ b/examples/src/agents/zapier_mrkl.ts @@ -23,6 +23,6 @@ const input = `Summarize the last email I received regarding Silicon Valley Bank console.log(`Executing with input "${input}"...`); -const result = await executor.call({ input }); +const result = await executor.invoke({ input }); console.log(`Got output ${result.output}`); diff --git a/examples/src/chat/agent.ts b/examples/src/chat/agent.ts index 54cf831cc902..6c8f30fb4a86 100644 --- a/examples/src/chat/agent.ts +++ b/examples/src/chat/agent.ts @@ -44,9 +44,9 @@ This was your previous work (but I haven't seen any of it! I only see what you r const executor = AgentExecutor.fromAgentAndTools({ agent, tools }); - const response = await executor.run( - "How many people live in canada as of 2023?" - ); + const response = await executor.invoke({ + input: "How many people live in canada as of 2023?", + }); console.log(response); }; diff --git a/examples/src/chat/overview.ts b/examples/src/chat/overview.ts index 652c96486c54..65d6dbd6d102 100644 --- a/examples/src/chat/overview.ts +++ b/examples/src/chat/overview.ts @@ -137,9 +137,9 @@ export const run = async () => { // Create an executor, which calls to the agent until an answer is found const executor = AgentExecutor.fromAgentAndTools({ agent, tools }); - const responseG = await executor.run( - "How many people live in canada as of 2023?" - ); + const responseG = await executor.invoke({ + input: "How many people live in canada as of 2023?", + }); console.log(responseG); }; diff --git a/examples/src/guides/conversational_retrieval/agent.ts b/examples/src/guides/conversational_retrieval/agent.ts index 1ea0ca68d6ab..53f6d07f3403 100644 --- a/examples/src/guides/conversational_retrieval/agent.ts +++ b/examples/src/guides/conversational_retrieval/agent.ts @@ -36,7 +36,7 @@ const executor = await createConversationalRetrievalAgent(model, [tool], { verbose: true, }); -const result = await executor.call({ +const result = await executor.invoke({ input: "Hi, I'm Bob!", }); @@ -49,7 +49,7 @@ console.log(result); } */ -const result2 = await executor.call({ +const result2 = await executor.invoke({ input: "What's my name?", }); @@ -59,7 +59,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?", }); @@ -75,7 +75,7 @@ console.log(result3); } */ -const result4 = await executor.call({ +const result4 = await executor.invoke({ input: "How long ago did he nominate her?", }); diff --git a/examples/src/guides/evaluation/agent_trajectory/trajectory.ts b/examples/src/guides/evaluation/agent_trajectory/trajectory.ts index 2c6d77e910c0..de36cb2b59c2 100644 --- a/examples/src/guides/evaluation/agent_trajectory/trajectory.ts +++ b/examples/src/guides/evaluation/agent_trajectory/trajectory.ts @@ -27,7 +27,7 @@ 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 }); // Evaluate Trajectory diff --git a/examples/src/models/llm/raycast.ts b/examples/src/models/llm/raycast.ts index 686d98a79485..d96c50cb12a8 100644 --- a/examples/src/models/llm/raycast.ts +++ b/examples/src/models/llm/raycast.ts @@ -22,7 +22,7 @@ export default async function main() { const input = `Describe my today's schedule as Gabriel Garcia Marquez would describe it`; - const answer = await executor.call({ input }); + const answer = await executor.invoke({ input }); await showHUD(answer.output); } diff --git a/examples/src/tools/searxng_search.ts b/examples/src/tools/searxng_search.ts index 22246d38d9a1..9919a896f2df 100644 --- a/examples/src/tools/searxng_search.ts +++ b/examples/src/tools/searxng_search.ts @@ -46,7 +46,7 @@ const executor = AgentExecutor.fromAgentAndTools({ console.log("Loaded agent."); const input = `What is Langchain? Describe in 50 words`; console.log(`Executing with input "${input}"...`); -const result = await executor.call({ input }); +const result = await executor.invoke({ input }); console.log(result); /** * Langchain is a framework for developing applications powered by language models, such as chatbots, Generative Question-Answering, summarization, and more. It provides a standard interface, integrations with other tools, and end-to-end chains for common applications. Langchain enables data-aware and powerful applications.