The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
docs: replace initialize_agent with create_react_agent in bash.ipynb (part of #29277) (#31042)
Michael Liff1602f0fdc0
diff --git a/docs/docs/integrations/tools/bash.ipynb b/docs/docs/integrations/tools/bash.ipynbindex b01f070926..42e5f6df49 100644--- a/docs/docs/integrations/tools/bash.ipynb+++ b/docs/docs/integrations/tools/bash.ipynb@@ -26,7 +26,7 @@},{"cell_type": "code",- "execution_count": null,+ "execution_count": 1,"id": "f7b3767b","metadata": {"tags": []@@ -83,40 +83,39 @@},{"cell_type": "code",- "execution_count": 3,- "id": "851fee9f",- "metadata": {- "tags": []- },+ "execution_count": null,+ "id": "7f056cc3-628d-46ba-b394-ee1d89f8650a",+ "metadata": {},"outputs": [{"name": "stdout","output_type": "stream","text": [+ "================================\u001b[1m Human Message \u001b[0m=================================\n","\n",+ "Download the README here and identify the link for LangChain tutorials: https://raw.githubusercontent.com/langchain-ai/langchain/master/README.md\n",+ "==================================\u001b[1m Ai Message \u001b[0m==================================\n",+ "Tool Calls:\n",+ " terminal (call_mr86V0d6E9nQiJZT7Xw5fH0G)\n",+ " Call ID: call_mr86V0d6E9nQiJZT7Xw5fH0G\n",+ " Args:\n",+ " commands: ['curl -o README.md https://raw.githubusercontent.com/langchain-ai/langchain/master/README.md']\n",+ "Executing command:\n",+ " ['curl -o README.md https://raw.githubusercontent.com/langchain-ai/langchain/master/README.md']\n",+ "=================================\u001b[1m Tool Message \u001b[0m=================================\n",+ "Name: terminal\n","\n",- "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",- "\u001b[32;1m\u001b[1;3mQuestion: What is the task?\n",- "Thought: We need to download the langchain.com webpage and extract all the URLs from it. Then we need to sort the URLs and return them.\n",- "Action:\n",- "```\n",- "{\n",- " \"action\": \"shell\",\n",- " \"action_input\": {\n",- " \"commands\": [\n",- " \"curl -s https://langchain.com | grep -o 'http[s]*://[^\\\" ]*' | sort\"\n",- " ]\n",- " }\n",- "}\n",- "```\n",- "\u001b[0m"+ " % Total % Received % Xferd Average Speed Time Time Time Current\n",+ " Dload Upload Total Spent Left Speed\n",+ "100 5169 100 5169 0 0 114k 0 --:--:-- --:--:-- --:--:-- 114k\n",+ "\n"]},{"name": "stderr","output_type": "stream","text": [- "/Users/wfh/code/lc/lckg/langchain/tools/shell/tool.py:34: UserWarning: The shell tool has no safeguards by default. Use at your own risk.\n",+ "/langchain/libs/community/langchain_community/tools/shell/tool.py:33: UserWarning: The shell tool has no safeguards by default. Use at your own risk.\n"," warnings.warn(\n"]},@@ -124,50 +123,58 @@"name": "stdout","output_type": "stream","text": [+ "==================================\u001b[1m Ai Message \u001b[0m==================================\n",+ "Tool Calls:\n",+ " terminal (call_LF8TGrgS84WvUvaazYnVfib8)\n",+ " Call ID: call_LF8TGrgS84WvUvaazYnVfib8\n",+ " Args:\n",+ " commands: [\"grep -i 'tutorial' README.md\"]\n",+ "Executing command:\n",+ " [\"grep -i 'tutorial' README.md\"]\n",+ "=================================\u001b[1m Tool Message \u001b[0m=================================\n",+ "Name: terminal\n","\n",- "Observation: \u001b[36;1m\u001b[1;3mhttps://blog.langchain.dev/\n",- "https://discord.gg/6adMQxSpJS\n",- "https://docs.langchain.com/docs/\n",- "https://github.com/hwchase17/chat-langchain\n",- "https://github.com/hwchase17/langchain\n",- "https://github.com/hwchase17/langchainjs\n",- "https://github.com/sullivan-sean/chat-langchainjs\n",- "https://js.langchain.com/docs/\n",- "https://python.langchain.com/en/latest/\n",- "https://twitter.com/langchainai\n",- "\u001b[0m\n",- "Thought:\u001b[32;1m\u001b[1;3mThe URLs have been successfully extracted and sorted. We can return the list of URLs as the final answer.\n",- "Final Answer: [\"https://blog.langchain.dev/\", \"https://discord.gg/6adMQxSpJS\", \"https://docs.langchain.com/docs/\", \"https://github.com/hwchase17/chat-langchain\", \"https://github.com/hwchase17/langchain\", \"https://github.com/hwchase17/langchainjs\", \"https://github.com/sullivan-sean/chat-langchainjs\", \"https://js.langchain.com/docs/\", \"https://python.langchain.com/en/latest/\", \"https://twitter.com/langchainai\"]\u001b[0m\n",- "\n",- "\u001b[1m> Finished chain.\u001b[0m\n"+ "- [Tutorials](https://python.langchain.com/docs/tutorials/): Simple walkthroughs with\n",+ "\n"]},{- "data": {- "text/plain": [- "'[\"https://blog.langchain.dev/\", \"https://discord.gg/6adMQxSpJS\", \"https://docs.langchain.com/docs/\", \"https://github.com/hwchase17/chat-langchain\", \"https://github.com/hwchase17/langchain\", \"https://github.com/hwchase17/langchainjs\", \"https://github.com/sullivan-sean/chat-langchainjs\", \"https://js.langchain.com/docs/\", \"https://python.langchain.com/en/latest/\", \"https://twitter.com/langchainai\"]'"- ]- },- "execution_count": 3,- "metadata": {},- "output_type": "execute_result"+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "/langchain/libs/community/langchain_community/tools/shell/tool.py:33: UserWarning: The shell tool has no safeguards by default. Use at your own risk.\n",+ " warnings.warn(\n"+ ]+ },+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "==================================\u001b[1m Ai Message \u001b[0m==================================\n",+ "\n",+ "The link for LangChain tutorials in the README is: https://python.langchain.com/docs/tutorials/\n"+ ]}],"source": [- "from langchain.agents import AgentType, initialize_agent\n",- "from langchain_openai import ChatOpenAI\n",+ "from langgraph.prebuilt import create_react_agent\n",+ "\n",+ "tools = [shell_tool]\n",+ "agent = create_react_agent(\"openai:gpt-4.1-mini\", tools)\n","\n",- "llm = ChatOpenAI(temperature=0)\n",+ "input_message = {\n",+ " \"role\": \"user\",\n",+ " \"content\": (\n",+ " \"Download the README here and identify the link for LangChain tutorials: \"\n",+ " \"https://raw.githubusercontent.com/langchain-ai/langchain/master/README.md\"\n",+ " ),\n",+ "}\n","\n",- "shell_tool.description = shell_tool.description + f\"args {shell_tool.args}\".replace(\n",- " \"{\", \"{{\"\n",- ").replace(\"}\", \"}}\")\n",- "self_ask_with_search = initialize_agent(\n",- " [shell_tool], llm, agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION, verbose=True\n",- ")\n",- "self_ask_with_search.run(\n",- " \"Download the langchain.com webpage and grep for all urls. Return only a sorted list of them. Be sure to use double quotes.\"\n",- ")"+ "for step in agent.stream(\n",+ " {\"messages\": [input_message]},\n",+ " stream_mode=\"values\",\n",+ "):\n",+ " step[\"messages\"][-1].pretty_print()"]},{@@ -195,7 +202,7 @@"name": "python","nbconvert_exporter": "python","pygments_lexer": "ipython3",- "version": "3.10.12"+ "version": "3.10.4"}},"nbformat": 4,