diff --git a/docs/core_docs/docs/integrations/toolkits/openapi.ipynb b/docs/core_docs/docs/integrations/toolkits/openapi.ipynb index aed7938407f4..12851b13fe99 100644 --- a/docs/core_docs/docs/integrations/toolkits/openapi.ipynb +++ b/docs/core_docs/docs/integrations/toolkits/openapi.ipynb @@ -216,8 +216,6 @@ "source": [ "import { createReactAgent } from \"@langchain/langgraph/prebuilt\"\n", "\n", - "import { ChatOpenAI } from \"@langchain/openai\";\n", - "\n", "const agentExecutor = createReactAgent({ llm, tools });" ] }, diff --git a/docs/core_docs/docs/integrations/tools/duckduckgo_search.ipynb b/docs/core_docs/docs/integrations/tools/duckduckgo_search.ipynb index 972f48899208..939a9471be48 100644 --- a/docs/core_docs/docs/integrations/tools/duckduckgo_search.ipynb +++ b/docs/core_docs/docs/integrations/tools/duckduckgo_search.ipynb @@ -31,7 +31,7 @@ "\n", "| Class | Package | Serializable | [PY support](https://python.langchain.com/docs/integrations/tools/ddg/) | Package latest |\n", "| :--- | :--- | :---: | :---: | :---: |\n", - "| [DuckDuckGoSearch](https://api.js.langchain.com/classes/langchain_community_tools_duckduckgo_search.DuckDuckGoSearch.html) | [@langchain/community](https://api.js.langchain.com/modules/langchain_community_tools_duckduckgo_search.html) | beta | ✅ | ![NPM - Version](https://img.shields.io/npm/v/@langchain/community?style=flat-square&label=%20&) |\n", + "| [DuckDuckGoSearch](https://api.js.langchain.com/classes/langchain_community_tools_duckduckgo_search.DuckDuckGoSearch.html) | [@langchain/community](https://api.js.langchain.com/modules/langchain_community_tools_duckduckgo_search.html) | ❌ | ✅ | ![NPM - Version](https://img.shields.io/npm/v/@langchain/community?style=flat-square&label=%20&) |\n", "\n", "## Setup\n", "\n", @@ -169,7 +169,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 1, "id": "af3123ad-7a02-40e5-b58e-7d56e23e5830", "metadata": {}, "outputs": [], @@ -261,61 +261,70 @@ "source": [ "## With an agent\n", "\n", - "We can also pass the `DuckDuckGoSearch` tool to an agent:" + "We can also pass the `DuckDuckGoSearch` tool to an agent. First, ensure you have the LangGraph package installed.\n", + "\n", + "```{=mdx}\n", + "\n", + " @langchain/langgraph\n", + "\n", + "```" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 3, "id": "77a05a61", "metadata": {}, + "outputs": [], + "source": [ + "import { DuckDuckGoSearch } from \"@langchain/community/tools/duckduckgo_search\";\n", + "import { createReactAgent } from \"@langchain/langgraph/prebuilt\";\n", + "\n", + "// Define the tools the agent will have access to.\n", + "const toolsForAgent = [new DuckDuckGoSearch({ maxResults: 1 })];\n", + "\n", + "const agentExecutor = createReactAgent({ llm, tools: toolsForAgent });" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "3130e547", + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{\n", - " input: \"What is Anthropic's estimated revenue for 2024?\",\n", - " output: 'Anthropic has projected that it will generate more than $850 million in annualized revenue by the end of 2024.'\n", - "}\n" + "[\n", + " {\n", + " name: 'duckduckgo-search',\n", + " args: { input: 'Anthropic estimated revenue 2024' },\n", + " type: 'tool_call',\n", + " id: 'call_eZwbyemMAu8tgQw4VqJs65hF'\n", + " }\n", + "]\n", + "[{\"title\":\"Anthropic forecasts more than $850 mln in annualized revenue rate by ...\",\"link\":\"https://www.reuters.com/technology/anthropic-forecasts-more-than-850-mln-annualized-revenue-rate-by-2024-end-report-2023-12-26/\",\"snippet\":\"Dec 26 (Reuters) - Artificial intelligence startup Anthropic has projected it will generate more than $850 million in annualized revenue by the end of 2024, the Information reported on Tuesday ...\"}]\n", + "Anthropic is projected to generate more than $850 million in annualized revenue by the end of 2024.\n" ] } ], "source": [ - "import { DuckDuckGoSearch } from \"@langchain/community/tools/duckduckgo_search\";\n", - "import { ChatOpenAI } from \"@langchain/openai\";\n", - "import type { ChatPromptTemplate } from \"@langchain/core/prompts\";\n", - "\n", - "import { pull } from \"langchain/hub\";\n", - "import { AgentExecutor, createOpenAIFunctionsAgent } from \"langchain/agents\";\n", + "const exampleQuery = \"What is Anthropic's estimated revenue for 2024?\"\n", "\n", - "// Define the tools the agent will have access to.\n", - "const toolsForAgent = [new DuckDuckGoSearch({ maxResults: 1 })];\n", + "const events = await agentExecutor.stream(\n", + " { messages: [[\"user\", exampleQuery]]},\n", + " { streamMode: \"values\", }\n", + ")\n", "\n", - "// Get the prompt to use - you can modify this!\n", - "// If you want to see the prompt in full, you can at:\n", - "// https://smith.langchain.com/hub/hwchase17/openai-functions-agent\n", - "const promptForAgent = await pull(\n", - " \"hwchase17/openai-functions-agent\"\n", - ");\n", - "const llmForAgent = new ChatOpenAI({\n", - " model: \"gpt-4-turbo-preview\",\n", - " temperature: 0,\n", - "});\n", - "const agent = await createOpenAIFunctionsAgent({\n", - " llm: llmForAgent,\n", - " tools: toolsForAgent,\n", - " prompt: promptForAgent,\n", - "});\n", - "const agentExecutor = new AgentExecutor({\n", - " agent,\n", - " tools: toolsForAgent,\n", - "});\n", - "const agentResult = await agentExecutor.invoke({\n", - " input: \"What is Anthropic's estimated revenue for 2024?\",\n", - "});\n", - "\n", - "console.log(agentResult);" + "for await (const event of events) {\n", + " const lastMsg = event.messages[event.messages.length - 1];\n", + " if (lastMsg.tool_calls?.length) {\n", + " console.dir(lastMsg.tool_calls, { depth: null });\n", + " } else if (lastMsg.content) {\n", + " console.log(lastMsg.content);\n", + " }\n", + "}" ] }, {