id
stringlengths
14
16
text
stringlengths
36
2.73k
source
stringlengths
49
117
c97d1a88ecee-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...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html
c97d1a88ecee-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...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html
c97d1a88ecee-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://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html
c97d1a88ecee-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://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html
c97d1a88ecee-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 May 28, 2023.
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/agent_vectorstore.html
1f702fe9ec35-0
.ipynb .pdf Handle Parsing Errors Contents Setup Error Default error handling Custom Error Message Custom Error Function Handle Parsing Errors# Occasionally the LLM cannot determine what step to take because it outputs format in incorrect form to be handled by the output parser. In this case, by default the agent err...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/handle_parsing_errors.html
1f702fe9ec35-1
22 response = json.loads(action.strip()) IndexError: list index out of range During handling of the above exception, another exception occurred: OutputParserException Traceback (most recent call last) Cell In[4], line 1 ----> 1 mrkl.run("Who is Leo DiCaprio's girlfriend? No need to add Action") ...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/handle_parsing_errors.html
1f702fe9ec35-2
135 if new_arg_supported 136 else self._call(inputs) 137 ) 138 except (KeyboardInterrupt, Exception) as e: 139 run_manager.on_chain_error(e) File ~/workplace/langchain/langchain/agents/agent.py:947, in AgentExecutor._call(self, inputs, run_manager) 945 # We now enter the agen...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/handle_parsing_errors.html
1f702fe9ec35-3
758 Override this to take control of how the agent makes and acts on choices. 759 """ 760 try: 761 # Call the LLM to see what to do. --> 762 output = self.agent.plan( 763 intermediate_steps, 764 callbacks=run_manager.get_child() if run_manager else None, 765 **inp...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/handle_parsing_errors.html
1f702fe9ec35-4
verbose=True, handle_parsing_errors=True ) mrkl.run("Who is Leo DiCaprio's girlfriend? No need to add Action") > Entering new AgentExecutor chain... Observation: Invalid or incomplete response Thought: Observation: Invalid or incomplete response Thought:Search for Leo DiCaprio's current girlfriend Action: ``` { "...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/handle_parsing_errors.html
1f702fe9ec35-5
"action_input": "Who is Leo DiCaprio's girlfriend?" } ``` Observation: DiCaprio broke up with girlfriend Camila Morrone, 25, in the summer of 2022, after dating for four years. He's since been linked to another famous supermodel – Gigi Hadid. The power couple were first supposedly an item in September after being spott...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/handle_parsing_errors.html
1f702fe9ec35-6
"action_input": "Who is Leo DiCaprio's girlfriend?" } ``` Observation: DiCaprio broke up with girlfriend Camila Morrone, 25, in the summer of 2022, after dating for four years. He's since been linked to another famous supermodel – Gigi Hadid. The power couple were first supposedly an item in September after being spott...
https://python.langchain.com/en/latest/modules/agents/agent_executors/examples/handle_parsing_errors.html
454e621f219a-0
.ipynb .pdf Custom Agent Custom Agent# This notebook goes through how to create your own custom agent. An agent consists of two 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 langc...
https://python.langchain.com/en/latest/modules/agents/agents/custom_agent.html
454e621f219a-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()...
https://python.langchain.com/en/latest/modules/agents/agents/custom_agent.html
62cd40f161a0-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...
https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_chat_agent.html
62cd40f161a0-1
!pip install langchain !pip install google-search-results !pip install openai 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 ty...
https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_chat_agent.html
62cd40f161a0-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 These were previous tasks you completed: Begin! Question: {input} {agent_sc...
https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_chat_agent.html
62cd40f161a0-3
# This includes the `intermediate_steps` variable because that is needed 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 pa...
https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_chat_agent.html
62cd40f161a0-4
llm = ChatOpenAI(openai_api_key=OPENAI_API_KEY, temperature=0) Define the stop sequence# 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 Observati...
https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_chat_agent.html
62cd40f161a0-5
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 the Agent Use the Agent By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 28, 2023.
https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_chat_agent.html
efd8bd7ba50a-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 ...
https://python.langchain.com/en/latest/modules/agents/agents/custom_agent_with_tool_retrieval.html
efd8bd7ba50a-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...
https://python.langchain.com/en/latest/modules/agents/agents/custom_agent_with_tool_retrieval.html
efd8bd7ba50a-2
Tool(name='foo-95', description='a silly function that you can use to get more information about the number 95', return_direct=False, verbose=False, callback_manager=<langchain.callbacks.shared.SharedCallbackManager object at 0x114b28a90>, func=<function fake_func at 0x15e5bd1f0>, coroutine=None), Tool(name='foo-12', ...
https://python.langchain.com/en/latest/modules/agents/agents/custom_agent_with_tool_retrieval.html
efd8bd7ba50a-3
Tool(name='foo-14', description='a silly function that you can use to get more information about the number 14', return_direct=False, verbose=False, callback_manager=<langchain.callbacks.shared.SharedCallbackManager object at 0x114b28a90>, func=<function fake_func at 0x15e5bd1f0>, coroutine=None), Tool(name='foo-11', ...
https://python.langchain.com/en/latest/modules/agents/agents/custom_agent_with_tool_retrieval.html
efd8bd7ba50a-4
from typing import Callable # Set up a prompt template class CustomPromptTemplate(StringPromptTemplate): # The template to use template: str ############## NEW ###################### # The list of tools available tools_getter: Callable def format(self, **kwargs) -> str: # Get the in...
https://python.langchain.com/en/latest/modules/agents/agents/custom_agent_with_tool_retrieval.html
efd8bd7ba50a-5
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...
https://python.langchain.com/en/latest/modules/agents/agents/custom_agent_with_tool_retrieval.html
efd8bd7ba50a-6
output_parser=output_parser, stop=["\nObservation:"], allowed_tools=tool_names ) Use the Agent# Now we can use it! agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True) agent_executor.run("What's the weather in SF?") > Entering new AgentExecutor chain... Thought: I need to...
https://python.langchain.com/en/latest/modules/agents/agents/custom_agent_with_tool_retrieval.html
2f9fa8b9587c-0
.ipynb .pdf Custom MultiAction Agent Custom MultiAction Agent# This notebook goes through how to create your own custom agent. An agent consists of two 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 ...
https://python.langchain.com/en/latest/modules/agents/agents/custom_multi_action_agent.html
2f9fa8b9587c-1
""" if len(intermediate_steps) == 0: return [ AgentAction(tool="Search", tool_input=kwargs["input"], log=""), AgentAction(tool="RandomWord", tool_input=kwargs["input"], log=""), ] else: return AgentFinish(return_values={"output": "bar"}...
https://python.langchain.com/en/latest/modules/agents/agents/custom_multi_action_agent.html
2f9fa8b9587c-2
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 28, 2023.
https://python.langchain.com/en/latest/modules/agents/agents/custom_multi_action_agent.html
b9400845cef9-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...
https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html
b9400845cef9-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 ...
https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html
b9400845cef9-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...
https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html
b9400845cef9-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...
https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html
b9400845cef9-4
# 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:"], allowed_tools=tool_names ) Use the Agent# Now we can use it! a...
https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html
b9400845cef9-5
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 repeat N times) Thought: I now know...
https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html
b9400845cef9-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:...
https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html
3adcc1a519ed-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...
https://python.langchain.com/en/latest/modules/agents/agents/agent_types.html
3adcc1a519ed-1
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on May 28, 2023.
https://python.langchain.com/en/latest/modules/agents/agents/agent_types.html
1b7fae33f2b0-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...
https://python.langchain.com/en/latest/modules/agents/agents/custom_mrkl_agent.html
1b7fae33f2b0-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...
https://python.langchain.com/en/latest/modules/agents/agents/custom_mrkl_agent.html
1b7fae33f2b0-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...
https://python.langchain.com/en/latest/modules/agents/agents/custom_mrkl_agent.html
1b7fae33f2b0-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...
https://python.langchain.com/en/latest/modules/agents/agents/custom_mrkl_agent.html
1b7fae33f2b0-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,...
https://python.langchain.com/en/latest/modules/agents/agents/custom_mrkl_agent.html
ea3f63ef2b12-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...
https://python.langchain.com/en/latest/modules/agents/agents/examples/conversational_agent.html
ea3f63ef2b12-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...
https://python.langchain.com/en/latest/modules/agents/agents/examples/conversational_agent.html
ea3f63ef2b12-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...
https://python.langchain.com/en/latest/modules/agents/agents/examples/conversational_agent.html
a106c4cb8c41-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://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl_chat.html
a106c4cb8c41-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...
https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl_chat.html
a106c4cb8c41-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...
https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl_chat.html
a106c4cb8c41-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...
https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl_chat.html
79619975543b-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://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl.html
79619975543b-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...
https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl.html
79619975543b-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...
https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl.html
79619975543b-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...
https://python.langchain.com/en/latest/modules/agents/agents/examples/mrkl.html
d0ea7d2dad59-0
.ipynb .pdf Structured Tool Chat Agent Contents Initialize Tools Adding in memory Structured Tool Chat Agent# This notebook walks through using a chat agent capable of using multi-input tools. Older agents are configured to specify an action input as a single string, but this agent can use the provided tools’ args_sc...
https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html
d0ea7d2dad59-1
print(response) > Entering new AgentExecutor chain... Action: ``` { "action": "Final Answer", "action_input": "Hello Erica, how can I assist you today?" } ``` > Finished chain. Hello Erica, how can I assist you today? response = await agent_chain.arun(input="Don't need help really just chatting.") print(response) >...
https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html
d0ea7d2dad59-2
We recently open-sourced an auto-evaluator tool for grading LLM question-answer chains. We are now releasing an open source, free to use hosted app and API to expand usability. Below we discuss a few opportunities to further improve May 1, 2023 5 min read Callbacks Improvements TL;DR: We're announcing improvements to o...
https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html
d0ea7d2dad59-3
discussions around a single agent. If multiple Apr 28, 2023 4 min read Gradio & LLM Agents Editor's note: this is a guest blog post from Freddy Boulton, a software engineer at Gradio. We're excited to share this post because it brings a large number of exciting new tools into the ecosystem. Agents are largely defined b...
https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html
d0ea7d2dad59-4
💡 TL;DR: We’ve introduced a new abstraction and a new document Retriever to facilitate the post-processing of retrieved documents. Specifically, the new abstraction makes it easy to take a set of retrieved documents and extract from them Apr 20, 2023 3 min read Autonomous Agents & Agent Simulations Over the past two w...
https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html
d0ea7d2dad59-5
Context Originally we designed LangChain.js to run in Node.js, which is the Apr 11, 2023 3 min read LangChain x Supabase Supabase is holding an AI Hackathon this week. Here at LangChain we are big fans of both Supabase and hackathons, so we thought this would be a perfect time to highlight the multiple ways you can use...
https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html
d0ea7d2dad59-6
The reason we like Supabase so much is that Apr 8, 2023 2 min read Announcing our $10M seed round led by Benchmark It was only six months ago that we released the first version of LangChain, but it seems like several years. When we launched, generative AI was starting to go mainstream: stable diffusion had just been re...
https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html
d0ea7d2dad59-7
This is done with the goals of (1) allowing retrievers constructed elsewhere to be used more easily in LangChain, (2) encouraging more experimentation with alternative Mar 23, 2023 4 min read LangChain + Zapier Natural Language Actions (NLA) We are super excited to team up with Zapier and integrate their new Zapier NLA...
https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html
d0ea7d2dad59-8
Ingham and Jon Luo are two of the community members leading the change on the SQL integrations. We’re really excited to write this blog post with them going over all the tips and tricks they’ve learned doing so. We’re even more excited to announce that we’ Mar 13, 2023 8 min read Origin Web Browser [Editor's Note]: Thi...
https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html
d0ea7d2dad59-9
Authors: Parth Asawa (pgasawa@), Ayushi Batwara (ayushi.batwara@), Jason Mar 8, 2023 4 min read Prompt Selectors One common complaint we've heard is that the default prompt templates do not work equally well for all models. This became especially pronounced this past week when OpenAI released a ChatGPT API. This new AP...
https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html
d0ea7d2dad59-10
What does this mean? It means that all your favorite prompts, chains, and agents are all recreatable in TypeScript natively. Both the Python version and TypeScript version utilize the same serializable format, meaning that artifacts can seamlessly be shared between languages. As an Feb 17, 2023 2 min read Streaming Sup...
https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html
d0ea7d2dad59-11
"url": "https://xkcd.com/" } } ``` Observation: Navigating to https://xkcd.com/ returned status code 200 Thought:I can extract the latest comic title and alt text using CSS selectors. Action: ``` { "action": "get_elements", "action_input": { "selector": "#ctitle, #comic img", "attributes": ["alt", "src"] ...
https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html
d0ea7d2dad59-12
Action: ``` { "action": "Final Answer", "action_input": "Hi Erica! How can I assist you today?" } ``` > Finished chain. Hi Erica! How can I assist you today? response = await agent_chain.arun(input="whats my name?") print(response) > Entering new AgentExecutor chain... Your name is Erica. > Finished chain. Your nam...
https://python.langchain.com/en/latest/modules/agents/agents/examples/structured_chat.html
da59f7c3f1da-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://python.langchain.com/en/latest/modules/agents/agents/examples/chat_conversation_agent.html
da59f7c3f1da-1
> Entering new AgentExecutor chain... { "action": "Final Answer", "action_input": "Hello Bob! How can I assist you today?" } > Finished chain. 'Hello Bob! How can I assist you today?' agent_chain.run(input="what's my name?") > Entering new AgentExecutor chain... { "action": "Final Answer", "action_input...
https://python.langchain.com/en/latest/modules/agents/agents/examples/chat_conversation_agent.html
da59f7c3f1da-2
> Entering new AgentExecutor chain... { "action": "Final Answer", "action_input": "The last letter in your name is 'b'. Argentina won the World Cup in 1978." } > Finished chain. "The last letter in your name is 'b'. Argentina won the World Cup in 1978." agent_chain.run(input="whats the weather like in pomfret?"...
https://python.langchain.com/en/latest/modules/agents/agents/examples/chat_conversation_agent.html
c8317f7889ba-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(...
https://python.langchain.com/en/latest/modules/agents/agents/examples/self_ask_with_search.html
ce4ecc308bb5-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())...
https://python.langchain.com/en/latest/modules/agents/agents/examples/react.html
ce4ecc308bb5-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...
https://python.langchain.com/en/latest/modules/agents/agents/examples/react.html
474b1399adc6-0
.ipynb .pdf Jira Jira# This notebook goes over how to use the Jira tool. The Jira tool allows agents to interact with a given Jira instance, performing actions such as searching for issues and creating issues, the tool wraps the atlassian-python-api library, for more see: https://atlassian-python-api.readthedocs.io/jir...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/jira.html
474b1399adc6-1
Observation: None Thought: I now know the final answer Final Answer: A new issue has been created in project PW with the summary "Make more fried rice" and description "Reminder to make more fried rice". > Finished chain. 'A new issue has been created in project PW with the summary "Make more fried rice" and descriptio...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/jira.html
853049187113-0
.ipynb .pdf Spark SQL Agent Contents Initialization Example: describing a table Example: running queries Spark SQL Agent# This notebook shows how to use agents to interact with a Spark SQL. Similar to SQL Database Agent, it is designed to address general inquiries about Spark SQL and facilitate error recovery. NOTE: ...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html
853049187113-1
+-----------+--------+------+--------------------+------+----+-----+-----+----------------+-------+-----+--------+ | 1| 0| 3|Braund, Mr. Owen ...| male|22.0| 1| 0| A/5 21171| 7.25| null| S| | 2| 1| 1|Cumings, Mrs. Joh...|female|38.0| 1| 0| PC 17599...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html
853049187113-2
| 7| 0| 1|McCarthy, Mr. Tim...| male|54.0| 0| 0| 17463|51.8625| E46| S| | 8| 0| 3|Palsson, Master. ...| male| 2.0| 3| 1| 349909| 21.075| null| S| | 9| 1| 3|Johnson, Mrs. Osc...|female|27.0| 0| 2| 347742...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html
853049187113-3
| 14| 0| 3|Andersson, Mr. An...| male|39.0| 1| 5| 347082| 31.275| null| S| | 15| 0| 3|Vestrom, Miss. Hu...|female|14.0| 0| 0| 350406| 7.8542| null| S| | 16| 1| 2|Hewlett, Mrs. (Ma...|female|55.0| 0| 0| 248706...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html
853049187113-4
only showing top 20 rows # Note, you can also connect to Spark via Spark connect. For example: # db = SparkSQL.from_uri("sc://localhost:15002", schema=schema) spark_sql = SparkSQL(schema=schema) llm = ChatOpenAI(temperature=0) toolkit = SparkSQLToolkit(db=spark_sql, llm=llm) agent_executor = create_spark_sql_agent( ...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html
853049187113-5
3 1 3 Heikkinen, Miss. Laina female 26.0 0 0 STON/O2. 3101282 7.925 None S */ Thought:I now know the schema and sample rows for the titanic table. Final Answer: The titanic table has the following columns: PassengerId (INT), Survived (INT), Pclass (INT), Name (STRING), Sex (STRING), Age (DOUBLE), SibSp (INT), Parch (IN...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html
853049187113-6
> Finished chain. 'The titanic table has the following columns: PassengerId (INT), Survived (INT), Pclass (INT), Name (STRING), Sex (STRING), Age (DOUBLE), SibSp (INT), Parch (INT), Ticket (STRING), Fare (DOUBLE), Cabin (STRING), and Embarked (STRING). Here are some sample rows from the table: \n\n1. PassengerId: 1, Su...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html
853049187113-7
Action: list_tables_sql_db Action Input: Observation: titanic Thought:I should check the schema of the titanic table to see if there is an age column. Action: schema_sql_db Action Input: titanic Observation: CREATE TABLE langchain_example.titanic ( PassengerId INT, Survived INT, Pclass INT, Name STRING, Sex ...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html
853049187113-8
SELECT SQRT(AVG(Age)) as square_root_of_avg_age FROM titanic Thought:The query is correct, so I can execute it to find the square root of the average age. Action: query_sql_db Action Input: SELECT SQRT(AVG(Age)) as square_root_of_avg_age FROM titanic Observation: [('5.449689683556195',)] Thought:I now know the final an...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html
853049187113-9
2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Thayer) female 38.0 1 0 PC 17599 71.2833 C85 C 3 1 3 Heikkinen, Miss. Laina female 26.0 0 0 STON/O2. 3101282 7.925 None S */ Thought:I can use the titanic table to find the oldest survived passenger. I will query the Name and Age columns, filtering by Survived and order...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark_sql.html
341968d71521-0
.ipynb .pdf PowerBI Dataset Agent Contents Some notes Initialization Example: describing a table Example: simple query on a table Example: running queries Example: add your own few-shot prompts PowerBI Dataset Agent# This notebook showcases an agent designed to interact with a Power BI Dataset. The agent is designed ...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/powerbi.html
341968d71521-1
toolkit = PowerBIToolkit( powerbi=PowerBIDataset(dataset_id="<dataset_id>", table_names=['table1', 'table2'], credential=DefaultAzureCredential()), llm=smart_llm ) agent_executor = create_pbi_agent( llm=fast_llm, toolkit=toolkit, verbose=True, ) Example: describing a table# agent_executor.run("Desc...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/powerbi.html
341968d71521-2
examples=few_shots, ) agent_executor = create_pbi_agent( llm=fast_llm, toolkit=toolkit, verbose=True, ) agent_executor.run("What was the maximum of value in revenue in dollars in 2022?") previous PlayWright Browser Toolkit next Python Agent Contents Some notes Initialization Example: describing a table ...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/powerbi.html
e19942e6076d-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://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html
e19942e6076d-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://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html
e19942e6076d-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://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html
e19942e6076d-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://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html
e19942e6076d-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://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html
e19942e6076d-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://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html
e19942e6076d-6
"TrackId" INTEGER NOT NULL, PRIMARY KEY ("PlaylistId", "TrackId"), FOREIGN KEY("TrackId") REFERENCES "Track" ("TrackId"), FOREIGN KEY("PlaylistId") REFERENCES "Playlist" ("PlaylistId") ) SELECT * FROM 'PlaylistTrack' LIMIT 3; PlaylistId TrackId 1 3402 1 3389 1 3390 Thought: I can use a SELECT statement to get the...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html
e19942e6076d-7
Thought: I now know the final answer. Final Answer: The total number of tracks in each playlist are: '90’s Music' (1477), 'Brazilian Music' (39), 'Classical' (75), 'Classical 101 - Deep Cuts' (25), 'Classical 101 - Next Steps' (25), 'Classical 101 - The Basics' (25), 'Grunge' (15), 'Heavy Metal Classic' (26), 'Music' (...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html
e19942e6076d-8
CREATE TABLE "Artist" ( "ArtistId" INTEGER NOT NULL, "Name" NVARCHAR(120), PRIMARY KEY ("ArtistId") ) SELECT * FROM 'Artist' LIMIT 3; ArtistId Name 1 AC/DC 2 Accept 3 Aerosmith CREATE TABLE "Track" ( "TrackId" INTEGER NOT NULL, "Name" NVARCHAR(200) NOT NULL, "AlbumId" INTEGER, "MediaTypeId" INTEGER NOT NULL...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html
e19942e6076d-9
"InvoiceId" INTEGER NOT NULL, "TrackId" INTEGER NOT NULL, "UnitPrice" NUMERIC(10, 2) NOT NULL, "Quantity" INTEGER NOT NULL, PRIMARY KEY ("InvoiceLineId"), FOREIGN KEY("TrackId") REFERENCES "Track" ("TrackId"), FOREIGN KEY("InvoiceId") REFERENCES "Invoice" ("InvoiceId") ) SELECT * FROM 'InvoiceLine' LIMIT 3;...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html
e19942e6076d-10
Thought: I should double check my query before executing it. Action: query_checker_sql_db Action Input: SELECT Artist.Name, SUM(InvoiceLine.Quantity) AS TotalQuantity FROM Artist INNER JOIN Track ON Artist.ArtistId = Track.ArtistId INNER JOIN InvoiceLine ON Track.TrackId = InvoiceLine.TrackId GROUP BY Artist.Name ORDER...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html