id
stringlengths
14
16
text
stringlengths
45
2.05k
source
stringlengths
53
111
a1cb1f3c2793-0
.ipynb .pdf Search Tools Contents Google Serper API Wrapper SerpAPI GoogleSearchAPIWrapper SearxNG Meta Search Engine Search Tools# This notebook shows off usage of various search tools. from langchain.agents import load_tools from langchain.agents import initialize_agent from langchain.llms import OpenAI llm = OpenA...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/search_tools.html
a1cb1f3c2793-1
Action: Search Action Input: "weather in Pomfret" Observation: Partly cloudy skies during the morning hours will give way to cloudy skies with light rain and snow developing in the afternoon. High 42F. Winds WNW at 10 to 15 ... Thought: I now know the current weather in Pomfret. Final Answer: Partly cloudy skies during...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/search_tools.html
a1cb1f3c2793-2
Action: Google Search Action Input: "weather in Pomfret" Observation: Showers early becoming a steady light rain later in the day. Near record high temperatures. High around 60F. Winds SW at 10 to 15 mph. Chance of rain 60%. Pomfret, CT Weather Forecast, with current conditions, wind, air quality, and what to expect fo...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/search_tools.html
a1cb1f3c2793-3
> Finished AgentExecutor chain. 'Showers early becoming a steady light rain later in the day. Near record high temperatures. High around 60F. Winds SW at 10 to 15 mph. Chance of rain 60%.' SearxNG Meta Search Engine# Here we will be using a self hosted SearxNG meta search engine. tools = load_tools(["searx-search"], se...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/search_tools.html
a1cb1f3c2793-4
Pomfret, CT ; Current Weather. 1:06 AM. 35°F · RealFeel® 32° ; TODAY'S WEATHER FORECAST. 3/3. 44°Hi. RealFeel® 50° ; TONIGHT'S WEATHER FORECAST. 3/3. 32°Lo. Pomfret, MD Forecast Today Hourly Daily Morning 41° 1% Afternoon 43° 0% Evening 35° 3% Overnight 34° 2% Don't Miss Finally, Here’s Why We Get More Colds and Flu Wh...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/search_tools.html
a1cb1f3c2793-5
Thought: I now know the final answer Final Answer: The current weather in Pomfret is mainly cloudy with snow showers around in the morning. The temperature is around 40F with winds NNW at 5 to 10 mph. Chance of snow is 40%. > Finished chain. 'The current weather in Pomfret is mainly cloudy with snow showers around in t...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/search_tools.html
241d6728892e-0
.ipynb .pdf Adding SharedMemory to an Agent and its Tools Adding SharedMemory to an Agent and its Tools# This notebook goes over adding memory to both of an Agent and its tools. Before going through this notebook, please walk through the following notebooks, as this will build on top of both of them: Adding memory to a...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/sharedmemory_for_tools.html
241d6728892e-1
Tool( name = "Summary", func=summry_chain.run, description="useful for when you summarize a conversation. The input to this tool should be a string, representing who will read this summary." ) ] prefix = """Have a conversation with a human, answering the following questions as best you can. ...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/sharedmemory_for_tools.html
241d6728892e-2
Action: Search Action Input: "ChatGPT" Observation: Nov 30, 2022 ... We've trained a model called ChatGPT which interacts in a conversational way. The dialogue format makes it possible for ChatGPT to answer ... ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built ...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/sharedmemory_for_tools.html
241d6728892e-3
Thought: I now know the final answer. Final Answer: ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built on top of OpenAI's GPT-3 family of large language models and is optimized for dialogue by using Reinforcement Learning with Human-in-the-Loop. It is also capab...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/sharedmemory_for_tools.html
241d6728892e-4
Action Input: Who developed ChatGPT Observation: ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built on top of OpenAI's GPT-3 family of large ... Feb 15, 2023 ... Who owns Chat GPT? Chat GPT is owned and developed by AI research and deployment company, OpenAI. Th...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/sharedmemory_for_tools.html
241d6728892e-5
Thought: I now know the final answer Final Answer: ChatGPT was developed by OpenAI. > Finished chain. 'ChatGPT was developed by OpenAI.' agent_chain.run(input="Thanks. Summarize the conversation, for my daughter 5 years old.") > Entering new AgentExecutor chain... Thought: I need to simplify the conversation for a 5 ye...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/sharedmemory_for_tools.html
241d6728892e-6
print(agent_chain.memory.buffer) Human: What is ChatGPT? AI: ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built on top of OpenAI's GPT-3 family of large language models and is optimized for dialogue by using Reinforcement Learning with Human-in-the-Loop. It is a...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/sharedmemory_for_tools.html
241d6728892e-7
Tool( name = "Summary", func=summry_chain.run, description="useful for when you summarize a conversation. The input to this tool should be a string, representing who will read this summary." ) ] prefix = """Have a conversation with a human, answering the following questions as best you can. ...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/sharedmemory_for_tools.html
241d6728892e-8
Action: Search Action Input: "ChatGPT" Observation: Nov 30, 2022 ... We've trained a model called ChatGPT which interacts in a conversational way. The dialogue format makes it possible for ChatGPT to answer ... ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built ...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/sharedmemory_for_tools.html
241d6728892e-9
Thought: I now know the final answer. Final Answer: ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built on top of OpenAI's GPT-3 family of large language models and is optimized for dialogue by using Reinforcement Learning with Human-in-the-Loop. It is also capab...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/sharedmemory_for_tools.html
241d6728892e-10
Action Input: Who developed ChatGPT Observation: ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built on top of OpenAI's GPT-3 family of large ... Feb 15, 2023 ... Who owns Chat GPT? Chat GPT is owned and developed by AI research and deployment company, OpenAI. Th...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/sharedmemory_for_tools.html
241d6728892e-11
Thought: I now know the final answer Final Answer: ChatGPT was developed by OpenAI. > Finished chain. 'ChatGPT was developed by OpenAI.' agent_chain.run(input="Thanks. Summarize the conversation, for my daughter 5 years old.") > Entering new AgentExecutor chain... Thought: I need to simplify the conversation for a 5 ye...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/sharedmemory_for_tools.html
241d6728892e-12
print(agent_chain.memory.buffer) Human: What is ChatGPT? AI: ChatGPT is an artificial intelligence chatbot developed by OpenAI and launched in November 2022. It is built on top of OpenAI's GPT-3 family of large language models and is optimized for dialogue by using Reinforcement Learning with Human-in-the-Loop. It is a...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/sharedmemory_for_tools.html
b5b0408ee424-0
.ipynb .pdf Defining Custom Tools Contents Completely New Tools Tool dataclass Subclassing the BaseTool class Using the tool decorator Modify existing tools Defining the priorities among Tools Using tools to return directly Defining Custom Tools# When constructing your own agent, you will need to provide it with a li...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/custom_tools.html
b5b0408ee424-1
Tool( name="Calculator", func=llm_math_chain.run, description="useful for when you need to answer questions about math" ) ] # Construct the agent. We will use the default agent type here. # See documentation for a full list of options. agent = initialize_agent(tools, llm, agent="zero-shot-re...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/custom_tools.html
b5b0408ee424-2
def _run(self, query: str) -> str: """Use the tool.""" return search.run(query) async def _arun(self, query: str) -> str: """Use the tool asynchronously.""" raise NotImplementedError("BingSearchRun does not support async") class CustomCalculatorTool(BaseTool): name = "C...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/custom_tools.html
b5b0408ee424-3
> Finished chain. Observation: Answer: 3.777824273683966 Thought: I now know the final answer Final Answer: Camila Morrone's age raised to the 0.43 power is 3.777824273683966. > Finished chain. "Camila Morrone's age raised to the 0.43 power is 3.777824273683966." Using the tool decorator# To make it easier to define cu...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/custom_tools.html
b5b0408ee424-4
"""Searches the API for the query.""" return "Results" search_api Tool(name='search', description='search(query: str) -> str - Searches the API for the query.', return_direct=True, verbose=False, callback_manager=<langchain.callbacks.shared.SharedCallbackManager object at 0x1184e0cd0>, func=<function search_api at ...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/custom_tools.html
b5b0408ee424-5
Thought: I now know the final answer Final Answer: Camila Morrone is Leo DiCaprio's girlfriend and her current age raised to the 0.43 power is 3.991298452658078. > Finished chain. "Camila Morrone is Leo DiCaprio's girlfriend and her current age raised to the 0.43 power is 3.991298452658078." Defining the priorities amo...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/custom_tools.html
b5b0408ee424-6
) ] agent = initialize_agent(tools, OpenAI(temperature=0), agent="zero-shot-react-description", verbose=True) agent.run("what is the most famous song of christmas") > Entering new AgentExecutor chain... I should use a music search engine to find the answer Action: Music Search Action Input: most famous song of christm...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/custom_tools.html
b5b0408ee424-7
Contents Completely New Tools Tool dataclass Subclassing the BaseTool class Using the tool decorator Modify existing tools Defining the priorities among Tools Using tools to return directly By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Mar 22, 2023.
https://langchain.readthedocs.io/en/latest/modules/agents/examples/custom_tools.html
df831441e784-0
.ipynb .pdf Custom Agent Contents Custom LLMChain Multiple inputs Custom Agent Class Custom Agent# This notebook goes through how to create your own custom agent. An agent consists of three parts: - Tools: The tools the agent has available to use. - LLMChain: The LLMChain that produces the text that is parsed in a ce...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/custom_agent.html
df831441e784-1
prefix: String to put before the list of tools. suffix: String to put after the list of tools. input_variables: List of input variables the final prompt will expect. For this exercise, we will give our agent access to Google Search, and we will customize it in that we will have it answer as a pirate. from langchain.age...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/custom_agent.html
df831441e784-2
Action Input: the input to the action Observation: the result of the action ... (this Thought/Action/Action Input/Observation can repeat N times) Thought: I now know the final answer Final Answer: the final answer to the original input question Begin! Remember to speak as a pirate when giving your final answer. Use lot...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/custom_agent.html
df831441e784-3
Thought: I now know the final answer Final Answer: Arrr, Canada be havin' 38,610,447 scallywags livin' there as of 2023! > Finished chain. "Arrr, Canada be havin' 38,610,447 scallywags livin' there as of 2023!" Multiple inputs# Agents can also work with prompts that require multiple inputs. prefix = """Answer the follo...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/custom_agent.html
df831441e784-4
Thought: I now know the final answer. Final Answer: La popolazione del Canada nel 2023 è stimata in 38.610.447 persone. > Finished chain. 'La popolazione del Canada nel 2023 è stimata in 38.610.447 persone.' Custom Agent Class# Coming soon. previous Conversation Agent (for Chat Models) next Defining Custom Tools Conte...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/custom_agent.html
34a694f827e1-0
.ipynb .pdf Async API for Agent Contents Serial vs. Concurrent Execution Using Tracing with Asynchronous Agents Async API for Agent# LangChain provides async support for Agents by leveraging the asyncio library. Async methods are currently supported for the following Tools: SerpAPIWrapper and LLMMathChain. Async supp...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/async_agent.html
34a694f827e1-1
] def generate_serially(): for q in questions: llm = OpenAI(temperature=0) tools = load_tools(["llm-math", "serpapi"], llm=llm) agent = initialize_agent( tools, llm, agent="zero-shot-react-description", verbose=True ) agent.run(q) s = time.perf_counter() generate_...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/async_agent.html
34a694f827e1-2
Action Input: "Olivia Wilde boyfriend" Observation: Jason Sudeikis Thought: I need to find out Jason Sudeikis' age Action: Search Action Input: "Jason Sudeikis age" Observation: 47 years Thought: I need to calculate 47 raised to the 0.23 power Action: Calculator Action Input: 47^0.23 Observation: Answer: 2.424278485567...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/async_agent.html
34a694f827e1-3
Action: Search Action Input: "US Open women's final 2019 winner" Observation: Bianca Andreescu defeated Serena Williams in the final, 6–3, 7–5 to win the women's singles tennis title at the 2019 US Open. It was her first major title, and she became the first Canadian, as well as the first player born in the 2000s, to w...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/async_agent.html
34a694f827e1-4
Thought: I now know the final answer Final Answer: Jay-Z is Beyonce's husband and his age raised to the 0.19 power is 2.12624064206896. > Finished chain. Serial executed in 65.11 seconds. async def generate_concurrently(): agents = [] # To make async requests in Tools more efficient, you can pass in your own ai...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/async_agent.html
34a694f827e1-5
Action: Search Action Input: "Olivia Wilde boyfriend" I need to find out who Beyonce's husband is and then calculate his age raised to the 0.19 power. Action: Search Action Input: "Who is Beyonce's husband?" Observation: Jay-Z Thought: I need to find out who won the grand prix and then calculate their age raised to the...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/async_agent.html
34a694f827e1-6
Action: Search Action Input: "US Open men's final 2019 winner" Observation: Rafael Nadal defeated Daniil Medvedev in the final, 7–5, 6–3, 5–7, 4–6, 6–4 to win the men's singles tennis title at the 2019 US Open. It was his fourth US ... Thought: Observation: 47 years Thought: I need to find out Max Verstappen's age Acti...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/async_agent.html
34a694f827e1-7
Action: Calculator Action Input: 36^0.334 Observation: Answer: 2.8603798598506933 Thought: I now know the final answer Final Answer: Jay-Z is Beyonce's husband and his age raised to the 0.19 power is 2.12624064206896. > Finished chain. I now know the final answer Final Answer: Max Verstappen, 25 years old, raised to t...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/async_agent.html
34a694f827e1-8
# but you must manually close the client session at the end of your program/event loop aiosession = ClientSession() tracer = LangChainTracer() tracer.load_default_session() manager = CallbackManager([StdOutCallbackHandler(), tracer]) # Pass the manager into the llm if you want llm calls traced. llm = OpenAI(temperature...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/async_agent.html
34a694f827e1-9
next Conversation Agent (for Chat Models) Contents Serial vs. Concurrent Execution Using Tracing with Asynchronous Agents By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Mar 22, 2023.
https://langchain.readthedocs.io/en/latest/modules/agents/examples/async_agent.html
17b8a3d5faac-0
.ipynb .pdf Agents and Vectorstores Contents Create the Vectorstore Create the Agent Use the Agent solely as a router Multi-Hop vectorstore reasoning Agents and Vectorstores# This notebook covers how to combine agents and vectorstores. The use case for this is that you’ve ingested your data into a vectorstore and wan...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/agent_vectorstore.html
17b8a3d5faac-1
from langchain.document_loaders import WebBaseLoader loader = WebBaseLoader("https://beta.ruff.rs/docs/faq/") docs = loader.load() ruff_texts = text_splitter.split_documents(docs) ruff_db = Chroma.from_documents(ruff_texts, embeddings, collection_name="ruff") ruff = VectorDBQA.from_chain_type(llm=llm, chain_type="stuff...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/agent_vectorstore.html
17b8a3d5faac-2
Action: State of Union QA System Action Input: What did Biden say about Ketanji Brown Jackson in the State of the Union address? Observation: Biden said that Jackson is one of the nation's top legal minds and that she will continue Justice Breyer's legacy of excellence. Thought: I now know the final answer Final Answe...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/agent_vectorstore.html
17b8a3d5faac-3
Thought: I now know the final answer Final Answer: Ruff can be used as a drop-in replacement for Flake8 when used (1) without or with a small number of plugins, (2) alongside Black, and (3) on Python 3 code. It also re-implements some of the most popular Flake8 plugins and related code quality tools natively, including...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/agent_vectorstore.html
17b8a3d5faac-4
Tool( name = "Ruff QA System", func=ruff.run, description="useful for when you need to answer questions about ruff (a python linter). Input should be a fully formed question.", return_direct=True ), ] agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=T...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/agent_vectorstore.html
17b8a3d5faac-5
Action Input: What are the advantages of using ruff over flake8? Observation: Ruff can be used as a drop-in replacement for Flake8 when used (1) without or with a small number of plugins, (2) alongside Black, and (3) on Python 3 code. It also re-implements some of the most popular Flake8 plugins and related code quali...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/agent_vectorstore.html
17b8a3d5faac-6
Tool( name = "Ruff QA System", func=ruff.run, description="useful for when you need to answer questions about ruff (a python linter). Input should be a fully formed question, not referencing any obscure pronouns from the conversation before." ), ] # Construct the agent. We will use the defau...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/agent_vectorstore.html
17b8a3d5faac-7
previous How-To Guides next Async API for Agent Contents Create the Vectorstore Create the Agent Use the Agent solely as a router Multi-Hop vectorstore reasoning By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Mar 22, 2023.
https://langchain.readthedocs.io/en/latest/modules/agents/examples/agent_vectorstore.html
a3e65075799d-0
.ipynb .pdf Intermediate Steps Intermediate Steps# In order to get more visibility into what an agent is doing, we can also return intermediate steps. This comes in the form of an extra key in the return value, which is a list of (action, observation) tuples. from langchain.agents import load_tools from langchain.agent...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/intermediate_steps.html
a3e65075799d-1
# The actual return type is a NamedTuple for the agent action, and then an observation print(response["intermediate_steps"]) [(AgentAction(tool='Search', tool_input='Leo DiCaprio girlfriend', log=' I should look up who Leo DiCaprio is dating\nAction: Search\nAction Input: "Leo DiCaprio girlfriend"'), 'Camila Morrone'),...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/intermediate_steps.html
a3e65075799d-2
], "Answer: 3.991298452658078\n" ] ] previous Defining Custom Tools next Loading from LangChainHub By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Mar 22, 2023.
https://langchain.readthedocs.io/en/latest/modules/agents/examples/intermediate_steps.html
6fc992f342a4-0
.ipynb .pdf Conversation Agent (for Chat Models) Conversation Agent (for Chat Models)# This notebook walks through using an agent optimized for conversation, using ChatModels. Other agents are often optimized for using tools to figure out the best response, which is not ideal in a conversational setting where you may w...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/chat_conversation_agent.html
6fc992f342a4-1
> Entering new AgentExecutor chain... { "action": "Final Answer", "action_input": "Your name is Bob." } > Finished chain. 'Your name is Bob.' agent_chain.run("what are some good dinners to make this week, if i like thai food?") > Entering new AgentExecutor chain... { "action": "Current Search", "action_...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/chat_conversation_agent.html
6fc992f342a4-2
"action_input": "who won the world cup in 1978" } ``` Observation: The Argentina national football team represents Argentina in men's international football and is administered by the Argentine Football Association, the governing body for football in Argentina. Nicknamed La Albiceleste, they are the reigning world cham...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/chat_conversation_agent.html
6fc992f342a4-3
previous Async API for Agent next Custom Agent By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Mar 22, 2023.
https://langchain.readthedocs.io/en/latest/modules/agents/examples/chat_conversation_agent.html
16acd0d0d753-0
.ipynb .pdf Loading from LangChainHub Contents Loading from LangChainHub Pinning Dependencies Loading from LangChainHub# This notebook covers how to load agents from LangChainHub. from langchain import OpenAI, SerpAPIWrapper from langchain.agents import initialize_agent, Tool llm = OpenAI(temperature=0) search = Serp...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/load_from_hub.html
16acd0d0d753-1
Specific versions of LangChainHub agents can be pinned with the lc@<ref>:// syntax. self_ask_with_search = initialize_agent(tools, llm, agent_path="lc@2826ef9e8acdf88465e1e5fc8a7bf59e0f9d0a85://agents/self-ask-with-search/agent.json", verbose=True) No `_type` key found, defaulting to `prompt`. previous Intermediate Ste...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/load_from_hub.html
70154fce5887-0
.ipynb .pdf Max Iterations Max Iterations# This notebook walks through how to cap an agent at taking a certain number of steps. This can be useful to ensure that they do not go haywire and take too many steps. from langchain.agents import load_tools from langchain.agents import initialize_agent from langchain.llms impo...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/max_iterations.html
70154fce5887-1
I should try Jester again Action: Jester Action Input: foo Observation: foo is not a valid tool, try another one. > Finished chain. 'Agent stopped due to max iterations.' By default, the early stopping uses method force which just returns that constant string. Alternatively, you could specify method generate which then...
https://langchain.readthedocs.io/en/latest/modules/agents/examples/max_iterations.html
fddb143421dc-0
.ipynb .pdf Self Ask With Search Self Ask With Search# This notebook showcases the Self Ask With Search chain. from langchain import OpenAI, SerpAPIWrapper from langchain.agents import initialize_agent, Tool llm = OpenAI(temperature=0) search = SerpAPIWrapper() tools = [ Tool( name="Intermediate Answer", ...
https://langchain.readthedocs.io/en/latest/modules/agents/implementations/self_ask_with_search.html
587c9e0b66a3-0
.ipynb .pdf MRKL Chat MRKL Chat# This notebook showcases using an agent to replicate the MRKL chain using an agent optimized for chat models. This uses the example Chinook database. To set it up follow the instructions on https://database.guide/2-sample-databases-sqlite/, placing the .db file in a notebooks folder at t...
https://langchain.readthedocs.io/en/latest/modules/agents/implementations/mrkl_chat.html
587c9e0b66a3-1
mrkl.run("Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?") > Entering new AgentExecutor chain... Thought: The first question requires a search, while the second question requires a calculator. Action: ``` { "action": "Search", "action_input": "Who is Leo DiCaprio's girlfriend?" ...
https://langchain.readthedocs.io/en/latest/modules/agents/implementations/mrkl_chat.html
587c9e0b66a3-2
Thought: I should use the Search tool to find the answer to the first part of the question and then use the FooBar DB tool to find the answer to the second part of the question. Action: ``` { "action": "Search", "action_input": "Who recently released an album called 'The Storm Before the Calm'" } ``` Observation: A...
https://langchain.readthedocs.io/en/latest/modules/agents/implementations/mrkl_chat.html
587c9e0b66a3-3
Thought:I have found the answer to both parts of the question. Final Answer: The artist who recently released an album called 'The Storm Before the Calm' is Alanis Morissette. The album 'Jagged Little Pill' is in the FooBar database. > Finished chain. "The artist who recently released an album called 'The Storm Before ...
https://langchain.readthedocs.io/en/latest/modules/agents/implementations/mrkl_chat.html
562debe2a166-0
.ipynb .pdf ReAct ReAct# This notebook showcases using an agent to implement the ReAct logic. from langchain import OpenAI, Wikipedia from langchain.agents import initialize_agent, Tool from langchain.agents.react.base import DocstoreExplorer docstore=DocstoreExplorer(Wikipedia()) tools = [ Tool( name="Sear...
https://langchain.readthedocs.io/en/latest/modules/agents/implementations/react.html
562debe2a166-1
Thought 2: The U.S. Navy admiral David Chanoff collaborated with is William J. Crowe. Action 2: Search[William J. Crowe] Observation 2: William James Crowe Jr. (January 2, 1925 – October 18, 2007) was a United States Navy admiral and diplomat who served as the 11th chairman of the Joint Chiefs of Staff under Presidents...
https://langchain.readthedocs.io/en/latest/modules/agents/implementations/react.html
d87ba273c9f9-0
.ipynb .pdf MRKL MRKL# This notebook showcases using an agent to replicate the MRKL chain. This uses the example Chinook database. To set it up follow the instructions on https://database.guide/2-sample-databases-sqlite/, placing the .db file in a notebooks folder at the root of this repository. from langchain import L...
https://langchain.readthedocs.io/en/latest/modules/agents/implementations/mrkl.html
d87ba273c9f9-1
> Entering new AgentExecutor chain... I need to find out who Leo DiCaprio's girlfriend is and then calculate her age raised to the 0.43 power. Action: Search Action Input: "Who is Leo DiCaprio's girlfriend?" Observation: Camila Morrone Thought: I need to find out Camila Morrone's age Action: Search Action Input: "How ...
https://langchain.readthedocs.io/en/latest/modules/agents/implementations/mrkl.html
d87ba273c9f9-2
Action: Search Action Input: "The Storm Before the Calm" artist Observation: The Storm Before the Calm (stylized in all lowercase) is the tenth (and eighth international) studio album by Canadian-American singer-songwriter Alanis ... Thought: I now need to search the FooBar database for Alanis Morissette's albums Actio...
https://langchain.readthedocs.io/en/latest/modules/agents/implementations/mrkl.html
d4eebcb52bb8-0
.ipynb .pdf Vectorstore Agent Contents Create the Vectorstores Initialize Toolkit and Agent Examples Multiple Vectorstores Examples Vectorstore Agent# This notebook showcases an agent designed to retrieve information from one or more vectorstores, either with or without sources. Create the Vectorstores# from langchai...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/vectorstore.html
d4eebcb52bb8-1
) vectorstore_info = VectorStoreInfo( name="state_of_union_address", description="the most recent state of the Union adress", vectorstore=state_of_union_store ) toolkit = VectorStoreToolkit(vectorstore_info=vectorstore_info) agent_executor = create_vectorstore_agent( llm=llm, toolkit=toolkit, ve...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/vectorstore.html
d4eebcb52bb8-2
Action Input: What did biden say about ketanji brown jackson Observation: {"answer": " Biden said that he nominated Circuit Court of Appeals Judge Ketanji Brown Jackson to the United States Supreme Court, and that she is one of the nation's top legal minds who will continue Justice Breyer's legacy of excellence.\n", "s...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/vectorstore.html
d4eebcb52bb8-3
toolkit=router_toolkit, verbose=True ) Examples# agent_executor.run("What did biden say about ketanji brown jackson is the state of the union address?") > Entering new AgentExecutor chain... I need to use the state_of_union_address tool to answer this question. Action: state_of_union_address Action Input: What did...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/vectorstore.html
d4eebcb52bb8-4
Thought: I now know the final answer Final Answer: Ruff is integrated into nbQA, a tool for running linters and code formatters over Jupyter Notebooks. After installing ruff and nbqa, you can run Ruff over a notebook like so: > nbqa ruff Untitled.ipynb > Finished chain. 'Ruff is integrated into nbQA, a tool for running...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/vectorstore.html
d4eebcb52bb8-5
previous SQL Database Agent next MRKL Contents Create the Vectorstores Initialize Toolkit and Agent Examples Multiple Vectorstores Examples By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Mar 22, 2023.
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/vectorstore.html
238550d9f924-0
.ipynb .pdf OpenAPI Agent Contents Initialization Example: agent capable of analyzing OpenAPI spec and making requests OpenAPI Agent# This notebook showcases an agent designed to interact with an OpenAPI spec and make a correct API request based on the information it has gathered from the spec. In the below example, ...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/openapi.html
238550d9f924-1
> Entering new AgentExecutor chain... Action: json_spec_list_keys Action Input: data Observation: ['openapi', 'info', 'servers', 'tags', 'paths', 'components', 'x-oaiMeta'] Thought: I should look at the servers key to see what the base url is Action: json_spec_list_keys Action Input: data["servers"][0] Observation: Val...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/openapi.html
238550d9f924-2
Action: json_spec_list_keys Action Input: data["paths"] Observation: ['/engines', '/engines/{engine_id}', '/completions', '/edits', '/images/generations', '/images/edits', '/images/variations', '/embeddings', '/engines/{engine_id}/search', '/files', '/files/{file_id}', '/files/{file_id}/content', '/answers', '/classifi...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/openapi.html
238550d9f924-3
Action: json_spec_list_keys Action Input: data["paths"] Observation: ['/engines', '/engines/{engine_id}', '/completions', '/edits', '/images/generations', '/images/edits', '/images/variations', '/embeddings', '/engines/{engine_id}/search', '/files', '/files/{file_id}', '/files/{file_id}/content', '/answers', '/classifi...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/openapi.html
238550d9f924-4
Action: json_spec_list_keys Action Input: data["paths"]["/completions"]["post"]["requestBody"]["content"]["application/json"] Observation: ['schema'] Thought: I should look at the schema key to see what parameters are required Action: json_spec_list_keys Action Input: data["paths"]["/completions"]["post"]["requestBody"...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/openapi.html
238550d9f924-5
> Finished chain. Observation: The required parameters for a POST request to the /completions endpoint are 'model'. Thought: I now know the parameters needed to make the request. Action: requests_post Action Input: { "url": "https://api.openai.com/v1/completions", "data": { "model": "davinci", "prompt": "tell me a joke...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/openapi.html
424c3964a7b8-0
.ipynb .pdf Python Agent Contents Python Agent Fibonacci Example Training neural net Python Agent# This notebook showcases an agent designed to write and execute python code to answer a question. from langchain.agents.agent_toolkits import create_python_agent from langchain.tools.python.tool import PythonREPLTool fro...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/python.html
424c3964a7b8-1
I need to write a neural network in PyTorch and train it on the given data. Action: Python REPL Action Input: import torch # Define the model model = torch.nn.Sequential( torch.nn.Linear(1, 1) ) # Define the loss loss_fn = torch.nn.MSELoss() # Define the optimizer optimizer = torch.optim.SGD(model.parameters(), lr...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/python.html
424c3964a7b8-2
Thought: I now know the final answer Final Answer: The prediction for x = 5 is 10.0. > Finished chain. 'The prediction for x = 5 is 10.0.' previous Pandas Dataframe Agent next SQL Database Agent Contents Python Agent Fibonacci Example Training neural net By Harrison Chase © Copyright 2023, Harrison Chase...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/python.html
f5da6cbc114f-0
.ipynb .pdf JSON Agent Contents Initialization Example: getting the required POST parameters for a request JSON Agent# This notebook showcases an agent designed to interact with large JSON/dict objects. This is useful when you want to answer questions about a JSON blob that’s too large to fit in the context window of...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/json.html
f5da6cbc114f-1
Thought: I should look at the paths key to see what endpoints exist Action: json_spec_list_keys Action Input: data["paths"] Observation: ['/engines', '/engines/{engine_id}', '/completions', '/edits', '/images/generations', '/images/edits', '/images/variations', '/embeddings', '/engines/{engine_id}/search', '/files', '/...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/json.html
f5da6cbc114f-2
Action: json_spec_list_keys Action Input: data["paths"]["/completions"]["post"]["requestBody"]["content"] Observation: ['application/json'] Thought: I should look at the application/json key to see what parameters are required Action: json_spec_list_keys Action Input: data["paths"]["/completions"]["post"]["requestBody"...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/json.html
f5da6cbc114f-3
Initialization Example: getting the required POST parameters for a request By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Mar 22, 2023.
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/json.html
3ca9f3fd24b6-0
.ipynb .pdf Pandas Dataframe Agent Pandas Dataframe Agent# This notebook shows how to use agents to interact with a pandas dataframe. It is mostly optimized for question answering. NOTE: this agent calls the Python agent under the hood, which executes LLM generated Python code - this can be bad if the LLM generated Pyt...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/pandas.html
3ca9f3fd24b6-1
Action: python_repl_ast Action Input: df['Age'].mean() Observation: 29.69911764705882 Thought: I can now calculate the square root Action: python_repl_ast Action Input: math.sqrt(df['Age'].mean()) Observation: name 'math' is not defined Thought: I need to import the math library Action: python_repl_ast Action Input: im...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/pandas.html
49e72c90359a-0
.ipynb .pdf CSV Agent CSV Agent# This notebook shows how to use agents to interact with a csv. It is mostly optimized for question answering. NOTE: this agent calls the Pandas DataFrame agent under the hood, which in turn calls the Python agent, which executes LLM generated Python code - this can be bad if the LLM gene...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/csv.html
49e72c90359a-1
Observation: 29.69911764705882 Thought: I can now calculate the square root Action: python_repl_ast Action Input: math.sqrt(df['Age'].mean()) Observation: name 'math' is not defined Thought: I need to import the math library Action: python_repl_ast Action Input: import math Observation: None Thought: I can now calculat...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/csv.html
dd6daa9d75f6-0
.ipynb .pdf SQL Database Agent Contents Initialization Example: describing a table Example: describing a table, recovering from an error Example: running queries Recovering from an error SQL Database Agent# This notebook showcases an agent designed to interact with a sql databases. The agent builds off of SQLDatabase...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/sql_database.html
dd6daa9d75f6-1
Action: schema_sql_db Action Input: "PlaylistTrack" Observation: CREATE TABLE "PlaylistTrack" ( "PlaylistId" INTEGER NOT NULL, "TrackId" INTEGER NOT NULL, PRIMARY KEY ("PlaylistId", "TrackId"), FOREIGN KEY("TrackId") REFERENCES "Track" ("TrackId"), FOREIGN KEY("PlaylistId") REFERENCES "Playlist" ("PlaylistId"...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/sql_database.html
dd6daa9d75f6-2
Thought: The table is called PlaylistTrack Action: schema_sql_db Action Input: "PlaylistTrack" Observation: CREATE TABLE "PlaylistTrack" ( "PlaylistId" INTEGER NOT NULL, "TrackId" INTEGER NOT NULL, PRIMARY KEY ("PlaylistId", "TrackId"), FOREIGN KEY("TrackId") REFERENCES "Track" ("TrackId"), FOREIGN KEY("Playl...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/sql_database.html
dd6daa9d75f6-3
"Address" NVARCHAR(70), "City" NVARCHAR(40), "State" NVARCHAR(40), "Country" NVARCHAR(40), "PostalCode" NVARCHAR(10), "Phone" NVARCHAR(24), "Fax" NVARCHAR(24), "Email" NVARCHAR(60) NOT NULL, "SupportRepId" INTEGER, PRIMARY KEY ("CustomerId"), FOREIGN KEY("SupportRepId") REFERENCES "Employee" ("Emplo...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/sql_database.html
dd6daa9d75f6-4
"BillingCity" NVARCHAR(40), "BillingState" NVARCHAR(40), "BillingCountry" NVARCHAR(40), "BillingPostalCode" NVARCHAR(10), "Total" NUMERIC(10, 2) NOT NULL, PRIMARY KEY ("InvoiceId"), FOREIGN KEY("CustomerId") REFERENCES "Customer" ("CustomerId") ) SELECT * FROM 'Invoice' LIMIT 3; InvoiceId CustomerId Invoice...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/sql_database.html
dd6daa9d75f6-5
Observation: [('USA', 523.0600000000003), ('Canada', 303.9599999999999), ('France', 195.09999999999994), ('Brazil', 190.09999999999997), ('Germany', 156.48), ('United Kingdom', 112.85999999999999), ('Czech Republic', 90.24000000000001), ('Portugal', 77.23999999999998), ('India', 75.25999999999999), ('Chile', 46.62)] Th...
https://langchain.readthedocs.io/en/latest/modules/agents/agent_toolkits/sql_database.html