id
stringlengths
14
16
text
stringlengths
44
2.73k
source
stringlengths
73
138
18c25b58ddd0-0
.md .pdf Weaviate Contents Installation and Setup Wrappers VectorStore Weaviate# This page covers how to use the Weaviate ecosystem within LangChain. What is Weaviate? Weaviate in a nutshell: Weaviate is an open-source ​database of the type ​vector search engine. Weaviate allows you to store JSON documents in a class...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\ecosystem\weaviate.html
18c25b58ddd0-1
To import this vectorstore: from langchain.vectorstores import Weaviate For a more detailed walkthrough of the Weaviate wrapper, see this notebook previous Weights & Biases next Wolfram Alpha Wrapper Contents Installation and Setup Wrappers VectorStore By Harrison Chase © Copyright 2023, Harrison Chase. ...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\ecosystem\weaviate.html
309ed9406af0-0
.md .pdf Wolfram Alpha Wrapper Contents Installation and Setup Wrappers Utility Tool Wolfram Alpha Wrapper# This page covers how to use the Wolfram Alpha API within LangChain. It is broken into two parts: installation and setup, and then references to specific Wolfram Alpha wrappers. Installation and Setup# Install r...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\ecosystem\wolfram_alpha.html
0c4b349dcab5-0
.md .pdf Writer Contents Installation and Setup Wrappers LLM Writer# This page covers how to use the Writer ecosystem within LangChain. It is broken into two parts: installation and setup, and then references to specific Writer wrappers. Installation and Setup# Get an Writer api key and set it as an environment varia...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\ecosystem\writer.html
ebdd10ef60df-0
.md .pdf Yeager.ai Contents What is Yeager.ai? yAgents How to use? Creating and Executing Tools with yAgents Yeager.ai# This page covers how to use Yeager.ai to generate LangChain tools and agents. What is Yeager.ai?# Yeager.ai is an ecosystem designed to simplify the process of creating AI agents and tools. It featu...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\ecosystem\yeagerai.html
ebdd10ef60df-1
create a tool that returns the n-th prime number Load the tool into the toolkit: To load a tool into yAgents, simply provide a command to yAgents that says so. For example: load the tool that you just created it into your toolkit Execute the tool: To run a tool or agent, simply provide a command to yAgents that include...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\ecosystem\yeagerai.html
6b2895e82441-0
.md .pdf Zilliz Contents Installation and Setup Wrappers VectorStore Zilliz# This page covers how to use the Zilliz Cloud ecosystem within LangChain. Zilliz uses the Milvus integration. It is broken into two parts: installation and setup, and then references to specific Milvus wrappers. Installation and Setup# Instal...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\ecosystem\zilliz.html
fc8e3872b86e-0
.md .pdf Quickstart Guide Contents Installation Environment Setup Building a Language Model Application: LLMs LLMs: Get predictions from a language model Prompt Templates: Manage prompts for LLMs Chains: Combine LLMs and prompts in multi-step workflows Agents: Dynamically Call Chains Based on User Input Memory: Add S...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\getting_started\getting_started.html
fc8e3872b86e-1
The most basic building block of LangChain is calling an LLM on some input. Let’s walk through a simple example of how to do this. For this purpose, let’s pretend we are building a service that generates a company name based on what the company makes. In order to do this, we first need to import the LLM wrapper. from l...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\getting_started\getting_started.html
fc8e3872b86e-2
template="What is a good name for a company that makes {product}?", ) Let’s now see how this works! We can call the .format method to format it. print(prompt.format(product="colorful socks")) What is a good name for a company that makes colorful socks? For more details, check out the getting started guide for prompts. ...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\getting_started\getting_started.html
fc8e3872b86e-3
There we go! There’s the first chain - an LLM Chain. This is one of the simpler types of chains, but understanding how it works will set you up well for working with more complex chains. For more details, check out the getting started guide for chains. Agents: Dynamically Call Chains Based on User Input# So far the cha...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\getting_started\getting_started.html
fc8e3872b86e-4
Now we can get started! from langchain.agents import load_tools from langchain.agents import initialize_agent from langchain.agents import AgentType from langchain.llms import OpenAI # First, let's load the language model we're going to use to control the agent. llm = OpenAI(temperature=0) # Next, let's load some tools...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\getting_started\getting_started.html
fc8e3872b86e-5
> Finished chain. Memory: Add State to Chains and Agents# So far, all the chains and agents we’ve gone through have been stateless. But often, you may want a chain or agent to have some concept of “memory” so that it may remember information about its previous interactions. The clearest and simple example of this is wh...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\getting_started\getting_started.html
fc8e3872b86e-6
print(output) > Entering new chain... Prompt after formatting: The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know. Current conversation: Huma...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\getting_started\getting_started.html
fc8e3872b86e-7
chat([HumanMessage(content="Translate this sentence from English to French. I love programming.")]) # -> AIMessage(content="J'aime programmer.", additional_kwargs={}) You can also pass in multiple messages for OpenAI’s gpt-3.5-turbo and gpt-4 models. messages = [ SystemMessage(content="You are a helpful assistant t...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\getting_started\getting_started.html
fc8e3872b86e-8
result.llm_output['token_usage'] # -> {'prompt_tokens': 71, 'completion_tokens': 18, 'total_tokens': 89} Chat Prompt Templates# Similar to LLMs, you can make use of templating by using a MessagePromptTemplate. You can build a ChatPromptTemplate from one or more MessagePromptTemplates. You can use ChatPromptTemplate’s f...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\getting_started\getting_started.html
fc8e3872b86e-9
ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, ) chat = ChatOpenAI(temperature=0) template="You are a helpful assistant that translates {input_language} to {output_language}." system_message_prompt = SystemMessagePromptTemplate.from_template(template) human_template="{text}" human_...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\getting_started\getting_started.html
fc8e3872b86e-10
# Now let's test it out! agent.run("Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?") > Entering new AgentExecutor chain... Thought: I need to use a search engine to find Olivia Wilde's boyfriend and a calculator to raise his age to the 0.23 power. Action: { "action": "Search", "a...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\getting_started\getting_started.html
fc8e3872b86e-11
ChatPromptTemplate, MessagesPlaceholder, SystemMessagePromptTemplate, HumanMessagePromptTemplate ) from langchain.chains import ConversationChain from langchain.chat_models import ChatOpenAI from langchain.memory import ConversationBufferMemory prompt = ChatPromptTemplate.from_messages([ SystemMessag...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\getting_started\getting_started.html
fc8e3872b86e-12
Chains: Combine LLMs and prompts in multi-step workflows Agents: Dynamically Call Chains Based on User Input Memory: Add State to Chains and Agents Building a Language Model Application: Chat Models Get Message Completions from a Chat Model Chat Prompt Templates Chains with Chat Models Agents with Chat Models Memory: A...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\getting_started\getting_started.html
995c46011f89-0
.rst .pdf Agents Contents Go Deeper Agents# Note Conceptual Guide Some applications will require not just a predetermined chain of calls to LLMs/other tools, but potentially an unknown chain that depends on the user’s input. In these types of chains, there is a “agent” which has access to a suite of tools. Depending ...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents.html
7efb230e3e3b-0
.rst .pdf Chains Chains# Note Conceptual Guide Using an LLM in isolation is fine for some simple applications, but many more complex ones require chaining LLMs - either with each other or with other experts. LangChain provides a standard interface for Chains, as well as some common implementations of chains for ease of...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\chains.html
727d35daf162-0
.rst .pdf Indexes Contents Go Deeper Indexes# Note Conceptual Guide Indexes refer to ways to structure documents so that LLMs can best interact with them. This module contains utility functions for working with documents, different types of indexes, and then examples for using those indexes in chains. The most common...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\indexes.html
727d35daf162-1
previous Structured Output Parser next Getting Started Contents Go Deeper By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Apr 25, 2023.
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\indexes.html
d6bdd54a4627-0
.rst .pdf Memory Memory# Note Conceptual Guide By default, Chains and Agents are stateless, meaning that they treat each incoming query independently (as are the underlying LLMs and chat models). In some applications (chatbots being a GREAT example) it is highly important to remember previous interactions, both at a sh...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\memory.html
36e19ff4f7d2-0
.rst .pdf Models Contents Go Deeper Models# Note Conceptual Guide This section of the documentation deals with different types of models that are used in LangChain. On this page we will go over the model types at a high level, but we have individual pages for each model type. The pages contain more detailed “how-to” ...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\models.html
2101c0723b7d-0
.rst .pdf Prompts Contents Go Deeper Prompts# Note Conceptual Guide The new way of programming models is through prompts. A “prompt” refers to the input to the model. This input is rarely hard coded, but rather is often constructed from multiple components. A PromptTemplate is responsible for the construction of this...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\prompts.html
cd3b30864bd3-0
.rst .pdf Agents Agents# Note Conceptual Guide In this part of the documentation we cover the different types of agents, disregarding which specific tools they are used with. For a high level overview of the different types of agents, see the below documentation. Agent Types For documentation on how to create a custom ...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents.html
85b22f1e66ba-0
.rst .pdf Agent Executors Agent Executors# Note Conceptual Guide Agent executors take an agent and tools and use the agent to decide which tools to call and in what order. In this part of the documentation we cover other related functionality to agent executors How to combine agents and vectorstores How to use the asyn...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agent_executors.html
8e00f242ac1b-0
.ipynb .pdf Getting Started Getting Started# Agents use an LLM to determine which actions to take and in what order. An action can either be using a tool and observing its output, or returning to the user. When used correctly agents can be extremely powerful. The purpose of this notebook is to show you how to easily us...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\getting_started.html
8e00f242ac1b-1
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True) Now let’s test it out! agent.run("Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?") > Entering new AgentExecutor chain... I need to find out who Leo DiCaprio's girlfriend is and then calc...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\getting_started.html
379e7c088b32-0
.rst .pdf Toolkits Toolkits# Note Conceptual Guide This section of documentation covers agents with toolkits - eg an agent applied to a particular use case. See below for a full list of agent toolkits CSV Agent Jira JSON Agent OpenAPI agents Natural Language APIs Pandas Dataframe Agent PowerBI Dataset Agent Python Agen...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\toolkits.html
52819952003b-0
.rst .pdf Tools Tools# Note Conceptual Guide Tools are ways that an agent can use to interact with the outside world. For an overview of what a tool is, how to use them, and a full list of examples, please see the getting started documentation Getting Started Next, we have some examples of customizing and generically w...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\tools.html
276e1e245e53-0
.md .pdf Agent Types Contents zero-shot-react-description react-docstore self-ask-with-search conversational-react-description Agent Types# Agents use an LLM to determine which actions to take and in what order. An action can either be using a tool and observing its output, or returning a response to the user. Here a...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\agent_types.html
276e1e245e53-1
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Apr 25, 2023.
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\agent_types.html
efeb7992d618-0
.ipynb .pdf Custom Agent 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. - The agent class itself: this decides which action to take. In this notebook we walk through how to create a custom agent. from lan...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_agent.html
efeb7992d618-1
Args: intermediate_steps: Steps the LLM has taken to date, along with observations **kwargs: User inputs. Returns: Action specifying what tool to use. """ return AgentAction(tool="Search", tool_input=kwargs["input"], log="") agent = FakeAgent()...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_agent.html
b3a81c490fcf-0
.ipynb .pdf Custom Agent with Tool Retrieval Contents Set up environment Set up tools Tool Retriever Prompt Template Output Parser Set up LLM, stop sequence, and the agent Use the Agent Custom Agent with Tool Retrieval# This notebook builds off of this notebook and assumes familiarity with how agents work. The novel ...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_agent_with_tool_retrieval.html
b3a81c490fcf-1
return "foo" fake_tools = [ Tool( name=f"foo-{i}", func=fake_func, description=f"a silly function that you can use to get more information about the number {i}" ) for i in range(99) ] ALL_TOOLS = [search_tool] + fake_tools Tool Retriever# We will use a vectorstore to create embedd...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_agent_with_tool_retrieval.html
b3a81c490fcf-2
get_tools("whats the weather?") [Tool(name='Search', description='useful for when you need to answer questions about current events', return_direct=False, verbose=False, callback_manager=<langchain.callbacks.shared.SharedCallbackManager object at 0x114b28a90>, func=<bound method SerpAPIWrapper.run of SerpAPIWrapper(sea...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_agent_with_tool_retrieval.html
b3a81c490fcf-3
get_tools("whats the number 13?") [Tool(name='foo-13', description='a silly function that you can use to get more information about the number 13', return_direct=False, verbose=False, callback_manager=<langchain.callbacks.shared.SharedCallbackManager object at 0x114b28a90>, func=<function fake_func at 0x15e5bd1f0>, cor...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_agent_with_tool_retrieval.html
b3a81c490fcf-4
{tools} Use the following format: Question: the input question you must answer Thought: you should always think about what to do Action: the action to take, should be one of [{tool_names}] Action Input: the input to the action Observation: the result of the action ... (this Thought/Action/Action Input/Observation can r...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_agent_with_tool_retrieval.html
b3a81c490fcf-5
# Create a list of tool names for the tools provided kwargs["tool_names"] = ", ".join([tool.name for tool in tools]) return self.template.format(**kwargs) prompt = CustomPromptTemplate( template=template, tools_getter=get_tools, # This omits the `agent_scratchpad`, `tools`, and `tool_names` ...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_agent_with_tool_retrieval.html
b3a81c490fcf-6
action_input = match.group(2) # Return the action and action input return AgentAction(tool=action, tool_input=action_input.strip(" ").strip('"'), log=llm_output) output_parser = CustomOutputParser() Set up LLM, stop sequence, and the agent# Also the same as the previous notebook llm = OpenAI(temperature...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_agent_with_tool_retrieval.html
b3a81c490fcf-7
> Finished chain. "'Arg, 'tis mostly cloudy skies early, then partly cloudy in the afternoon. High near 60F. ENE winds shiftin' to W at 10 to 15 mph. Humidity71%. UV Index6 of 10." previous Custom MultiAction Agent next Conversation Agent (for Chat Models) Contents Set up environment Set up tools Tool Retriever Pro...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_agent_with_tool_retrieval.html
1385c4d17401-0
.ipynb .pdf Custom LLM Agent Contents Set up environment Set up tool Prompt Template Output Parser Set up LLM Define the stop sequence Set up the Agent Use the Agent Adding Memory Custom LLM Agent# This notebook goes through how to create your own custom LLM agent. An LLM agent consists of three parts: PromptTemplate...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_llm_agent.html
1385c4d17401-1
from langchain.prompts import StringPromptTemplate from langchain import OpenAI, SerpAPIWrapper, LLMChain from typing import List, Union from langchain.schema import AgentAction, AgentFinish import re Set up tool# Set up any tools the agent may want to use. This may be necessary to put in the prompt (so that the agent ...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_llm_agent.html
1385c4d17401-2
Question: {input} {agent_scratchpad}""" # Set up a prompt template class CustomPromptTemplate(StringPromptTemplate): # The template to use template: str # The list of tools available tools: List[Tool] def format(self, **kwargs) -> str: # Get the intermediate steps (AgentAction, Observat...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_llm_agent.html
1385c4d17401-3
class CustomOutputParser(AgentOutputParser): def parse(self, llm_output: str) -> Union[AgentAction, AgentFinish]: # Check if agent should finish if "Final Answer:" in llm_output: return AgentFinish( # Return values is generally always a dictionary with a single `outp...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_llm_agent.html
1385c4d17401-4
Set up the Agent# We can now combine everything to set up our agent # LLM chain consisting of the LLM and a prompt llm_chain = LLMChain(llm=llm, prompt=prompt) tool_names = [tool.name for tool in tools] agent = LLMSingleActionAgent( llm_chain=llm_chain, output_parser=output_parser, stop=["\nObservation:"],...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_llm_agent.html
1385c4d17401-5
{tools} Use the following format: Question: the input question you must answer Thought: you should always think about what to do Action: the action to take, should be one of [{tool_names}] Action Input: the input to the action Observation: the result of the action ... (this Thought/Action/Action Input/Observation can r...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_llm_agent.html
1385c4d17401-6
Thought: I need to find out the population of Canada in 2023 Action: Search Action Input: Population of Canada in 2023 Observation:The current population of Canada is 38,658,314 as of Wednesday, April 12, 2023, based on Worldometer elaboration of the latest United Nations data. I now know the final answer Final Answer:...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_llm_agent.html
eaca291c8c02-0
.ipynb .pdf Custom LLM Agent (with a ChatModel) Contents Set up environment Set up tool Prompt Template Output Parser Set up LLM Define the stop sequence Set up the Agent Use the Agent Custom LLM Agent (with a ChatModel)# This notebook goes through how to create your own custom agent based on a chat model. An LLM cha...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_llm_chat_agent.html
eaca291c8c02-1
Set up environment# Do necessary imports, etc. from langchain.agents import Tool, AgentExecutor, LLMSingleActionAgent, AgentOutputParser from langchain.prompts import BaseChatPromptTemplate from langchain import SerpAPIWrapper, LLMChain from langchain.chat_models import ChatOpenAI from typing import List, Union from la...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_llm_chat_agent.html
eaca291c8c02-2
... (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 lots of "Arg"s Question: {input} {agent_scratchpad}""" # Set up a prompt templa...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_llm_chat_agent.html
eaca291c8c02-3
input_variables=["input", "intermediate_steps"] ) Output Parser# The output parser is responsible for parsing the LLM output into AgentAction and AgentFinish. This usually depends heavily on the prompt used. This is where you can change the parsing to do retries, handle whitespace, etc class CustomOutputParser(AgentOut...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_llm_chat_agent.html
eaca291c8c02-4
This is important because it tells the LLM when to stop generation. This depends heavily on the prompt and model you are using. Generally, you want this to be whatever token you use in the prompt to denote the start of an Observation (otherwise, the LLM may hallucinate an observation for you). Set up the Agent# We can ...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_llm_chat_agent.html
eaca291c8c02-5
Final Answer: Arrrr, thar be 38,649,283 scallywags in Canada as of 2023. > Finished chain. 'Arrrr, thar be 38,649,283 scallywags in Canada as of 2023.' previous Custom LLM Agent next Custom MRKL Agent Contents Set up environment Set up tool Prompt Template Output Parser Set up LLM Define the stop sequence Set up th...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_llm_chat_agent.html
f5c9eef120e4-0
.ipynb .pdf Custom MRKL Agent Contents Custom LLMChain Multiple inputs Custom MRKL Agent# This notebook goes through how to create your own custom MRKL agent. A MRKL 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...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_mrkl_agent.html
f5c9eef120e4-1
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.agents import ZeroShotAgent, Tool, AgentExecutor from langchain import OpenAI, SerpAPIWrapper, LLM...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_mrkl_agent.html
f5c9eef120e4-2
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 lots of "Args" Question: {input} {agent_scratchpad} Note that we are able to feed agents a self-defined prompt template, i.e. not restricted to the p...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_mrkl_agent.html
f5c9eef120e4-3
Multiple inputs# Agents can also work with prompts that require multiple inputs. prefix = """Answer the following questions as best you can. You have access to the following tools:""" suffix = """When answering, you MUST speak in the following language: {language}. Question: {input} {agent_scratchpad}""" prompt = ZeroS...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_mrkl_agent.html
f5c9eef120e4-4
Thought: I now know the final answer. Final Answer: La popolazione del Canada è stata stimata a 39.566.248 il 1° gennaio 2023, dopo un record di crescita demografica di 1.050.110 persone dal 1° gennaio 2022 al 1° gennaio 2023. > Finished chain. 'La popolazione del Canada è stata stimata a 39.566.248 il 1° gennaio 2023,...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_mrkl_agent.html
05fa29a56eee-0
.ipynb .pdf Custom MultiAction Agent Custom MultiAction 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. - The agent class itself: this decides which action to take. In this notebook we walk through how to create ...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_multi_action_agent.html
05fa29a56eee-1
""" if len(intermediate_steps) == 0: return [ AgentAction(tool="Search", tool_input="foo", log=""), AgentAction(tool="RandomWord", tool_input="foo", log=""), ] else: return AgentFinish(return_values={"output": "bar"}, log="") async ...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_multi_action_agent.html
05fa29a56eee-2
foo > Finished chain. 'bar' previous Custom MRKL Agent next Custom Agent with Tool Retrieval By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Apr 25, 2023.
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\custom_multi_action_agent.html
3b50419d0eb8-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...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\chat_conversation_agent.html
3b50419d0eb8-1
agent_chain.run(input="hi, i am bob") > Entering new AgentExecutor chain... WARNING:root:Failed to persist run: HTTPConnectionPool(host='localhost', port=8000): Max retries exceeded with url: /chain-runs (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x13fab40d0>: Failed to establish a new ...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\chat_conversation_agent.html
3b50419d0eb8-2
Thought: WARNING:root:Failed to persist run: HTTPConnectionPool(host='localhost', port=8000): Max retries exceeded with url: /chain-runs (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x13fae8be0>: Failed to establish a new connection: [Errno 61] Connection refused')) { "action": "Final...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\chat_conversation_agent.html
3b50419d0eb8-3
} ``` > Finished chain. "The last letter in your name is 'b', and the winner of the 1978 World Cup was the Argentina national football team." agent_chain.run(input="whats the weather like in pomfret?") > Entering new AgentExecutor chain... { "action": "Current Search", "action_input": "weather in pomfret" } Obs...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\chat_conversation_agent.html
3b50419d0eb8-4
} > Finished chain. 'The weather in Pomfret, CT for the next 10 days is as follows: Sun 16. 64° · 50°. 24% · NE 7 mph ; Mon 17. 58° · 45°. 70% · ESE 8 mph ; Tue 18. 57° · 37°. 8% · WSW 15 mph.' previous Custom Agent with Tool Retrieval next Conversation Agent By Harrison Chase © Copyright 2023, Harrison Chas...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\chat_conversation_agent.html
7a10200590a5-0
.ipynb .pdf Conversation Agent Conversation Agent# This notebook walks through using an agent optimized for conversation. 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 want the agent to be able to chat with the user as well...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\conversational_agent.html
7a10200590a5-1
AI: 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... Thought: Do I need to use a tool? Yes Action: Current Search Action Input: Thai food dinner recipes Observation: 59 easy Thai recipes fo...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\conversational_agent.html
7a10200590a5-2
> Finished chain. 'The last letter in your name is "b" and the winner of the 1978 World Cup was the Argentina national football team.' agent_chain.run(input="whats the current temperature in pomfret?") > Entering new AgentExecutor chain... Thought: Do I need to use a tool? Yes Action: Current Search Action Input: Curre...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\conversational_agent.html
c1548d86aaed-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...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\mrkl.html
c1548d86aaed-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: DiCaprio met actor Camila Morrone in December 2017, when she was 20 and he was 43. They were spott...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\mrkl.html
c1548d86aaed-2
> Entering new AgentExecutor chain... I need to find out the artist's full name and then search the FooBar database for their albums. 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 b...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\mrkl.html
c1548d86aaed-3
Thought: I now know the final answer. Final Answer: The artist who released the album 'The Storm Before the Calm' is Alanis Morissette and the albums of hers in the FooBar database are Jagged Little Pill. > Finished chain. "The artist who released the album 'The Storm Before the Calm' is Alanis Morissette and the album...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\mrkl.html
532a184a8860-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...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\mrkl_chat.html
532a184a8860-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": "Leo DiCaprio girlfriend" } ``` Obse...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\mrkl_chat.html
532a184a8860-2
mrkl.run("What is the full name of the artist who recently released an album called 'The Storm Before the Calm' and are they in the FooBar database? If so, what albums of theirs are in the FooBar database?") > Entering new AgentExecutor chain... Question: What is the full name of the artist who recently released an alb...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\mrkl_chat.html
532a184a8860-3
sample_rows = connection.execute(command) SELECT "Title" FROM "Album" WHERE "ArtistId" IN (SELECT "ArtistId" FROM "Artist" WHERE "Name" = 'Alanis Morissette') LIMIT 5; SQLResult: [('Jagged Little Pill',)] Answer: Alanis Morissette has the album Jagged Little Pill in the database. > Finished chain. Observation: Alanis...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\mrkl_chat.html
da3c9f94f5d8-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 import AgentType from langchain.agents.react.base import DocstoreExplorer docstore=DocstoreExplorer(Wikipedia())...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\react.html
da3c9f94f5d8-1
Action: Search[David Chanoff] Observation: David Chanoff is a noted author of non-fiction work. His work has typically involved collaborations with the principal protagonist of the work concerned. His collaborators have included; Augustus A. White, Joycelyn Elders, Đoàn Văn Toại, William J. Crowe, Ariel Sharon, Kenneth...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\react.html
1dd0160413f8-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 from langchain.agents import AgentType llm = OpenAI(temperature=0) search = SerpAPIWrapper() tools = [ Tool(...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agents\examples\self_ask_with_search.html
c1a7943a7dc3-0
.ipynb .pdf How to combine agents and vectorstores Contents Create the Vectorstore Create the Agent Use the Agent solely as a router Multi-Hop vectorstore reasoning How to combine agents and vectorstores# This notebook covers how to combine agents and vectorstores. The use case for this is that you’ve ingested your d...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agent_executors\examples\agent_vectorstore.html
c1a7943a7dc3-1
texts = text_splitter.split_documents(documents) embeddings = OpenAIEmbeddings() docsearch = Chroma.from_documents(texts, embeddings, collection_name="state-of-union") Running Chroma using direct local API. Using DuckDB in-memory for database. Data will be transient. state_of_union = RetrievalQA.from_chain_type(llm=llm...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agent_executors\examples\agent_vectorstore.html
c1a7943a7dc3-2
), ] # 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=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True) agent.run("What did biden say about ketanji brown jackson is the state of the union address?") > Entering n...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agent_executors\examples\agent_vectorstore.html
c1a7943a7dc3-3
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...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agent_executors\examples\agent_vectorstore.html
c1a7943a7dc3-4
Notice that in the above examples the agent did some extra work after querying the RetrievalQAChain. You can avoid that and just return the result directly. tools = [ Tool( name = "State of Union QA System", func=state_of_union.run, description="useful for when you need to answer questions a...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agent_executors\examples\agent_vectorstore.html
c1a7943a7dc3-5
Action: Ruff QA System 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...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agent_executors\examples\agent_vectorstore.html
c1a7943a7dc3-6
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 default agent type ...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agent_executors\examples\agent_vectorstore.html
c1a7943a7dc3-7
previous Agent Executors next How to use the async API for Agents 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 Apr 25, 2023.
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agent_executors\examples\agent_vectorstore.html
b27349a0cc1d-0
.ipynb .pdf How to use the async API for Agents Contents Serial vs. Concurrent Execution Using Tracing with Asynchronous Agents How to use the async API for Agents# LangChain provides async support for Agents by leveraging the asyncio library. Async methods are currently supported for the following Tools: SerpAPIWrap...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agent_executors\examples\async_agent.html
b27349a0cc1d-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=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True ) agent.run(q) s = time.perf_counter() g...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agent_executors\examples\async_agent.html
b27349a0cc1d-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...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agent_executors\examples\async_agent.html
b27349a0cc1d-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...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agent_executors\examples\async_agent.html
b27349a0cc1d-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...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agent_executors\examples\async_agent.html
b27349a0cc1d-5
> Entering new AgentExecutor chain... > Entering new AgentExecutor chain... I need to find out who Olivia Wilde's boyfriend is and then calculate his age raised to the 0.23 power. 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 ...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agent_executors\examples\async_agent.html
b27349a0cc1d-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...
rtdocs\python.langchain.com\langchain.readthedocs.io\en\latest\modules\agents\agent_executors\examples\async_agent.html