id
stringlengths
14
16
text
stringlengths
36
2.73k
source
stringlengths
49
117
cee1613b3a81-9
give up on milestones: A CNN Hero\\u2019s message for Autism Awareness Month"}, {"innerText": "CNN Hero of the Year Nelly Cheboi returned to Kenya with plans to lift more students out of poverty"}]'
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html
cee1613b3a81-10
# If the agent wants to remember the current webpage, it can use the `current_webpage` tool await tools_by_name['current_webpage'].arun({}) 'https://web.archive.org/web/20230428133211/https://cnn.com/world' Use within an Agent# Several of the browser tools are StructuredTool’s, meaning they expect multiple arguments. T...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html
cee1613b3a81-11
``` { "action": "get_elements", "action_input": { "selector": "h1, h2, h3, h4, h5, h6" } } ``` Observation: [] Thought: Thought: I need to navigate to langchain.com to see the headers Action: ``` { "action": "navigate_browser", "action_input": "https://langchain.com/" } ``` Observation: Navigating to http...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/playwright.html
4d6e5f5c853c-0
.ipynb .pdf Azure Cognitive Services Toolkit Contents Create the Toolkit Use within an Agent Azure Cognitive Services Toolkit# This toolkit is used to interact with the Azure Cognitive Services API to achieve some multimodal capabilities. Currently There are four tools bundled in this toolkit: AzureCogsImageAnalysisT...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/azure_cognitive_services.html
4d6e5f5c853c-1
[tool.name for tool in toolkit.get_tools()] ['Azure Cognitive Services Image Analysis', 'Azure Cognitive Services Form Recognizer', 'Azure Cognitive Services Speech2Text', 'Azure Cognitive Services Text2Speech'] Use within an Agent# from langchain import OpenAI from langchain.agents import initialize_agent, AgentTyp...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/azure_cognitive_services.html
4d6e5f5c853c-2
audio_file = agent.run("Tell me a joke and read it out for me.") > Entering new AgentExecutor chain... Action: ``` { "action": "Azure Cognitive Services Text2Speech", "action_input": "Why did the chicken cross the playground? To get to the other slide!" } ``` Observation: /tmp/tmpa3uu_j6b.wav Thought: I have the au...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/azure_cognitive_services.html
9ee98ef46ebb-0
.ipynb .pdf Spark Dataframe Agent Contents Spark Connect Example Spark Dataframe Agent# This notebook shows how to use agents to interact with a Spark dataframe and Spark Connect. It is mostly optimized for question answering. NOTE: this agent calls the Python agent under the hood, which executes LLM generated Python...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark.html
9ee98ef46ebb-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.html
9ee98ef46ebb-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.html
9ee98ef46ebb-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.html
9ee98ef46ebb-4
only showing top 20 rows agent = create_spark_dataframe_agent(llm=OpenAI(temperature=0), df=df, verbose=True) agent.run("how many rows are there?") > Entering new AgentExecutor chain... Thought: I need to find out how many rows are in the dataframe Action: python_repl_ast Action Input: df.count() Observation: 891 Thoug...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark.html
9ee98ef46ebb-5
Thought: I now have the math library imported, I can get the square root Action: python_repl_ast Action Input: math.sqrt(29.69911764705882) Observation: 5.449689683556195 Thought: I now know the final answer Final Answer: 5.449689683556195 > Finished chain. '5.449689683556195' spark.stop() Spark Connect Example# # in a...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark.html
9ee98ef46ebb-6
df.show() +-----------+--------+------+--------------------+------+----+-----+-----+----------------+-------+-----+--------+ |PassengerId|Survived|Pclass| Name| Sex| Age|SibSp|Parch| Ticket| Fare|Cabin|Embarked| +-----------+--------+------+--------------------+------+----+-----+-----+------...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark.html
9ee98ef46ebb-7
| 6| 0| 3| Moran, Mr. James| male|null| 0| 0| 330877| 8.4583| null| Q| | 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...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark.html
9ee98ef46ebb-8
| 13| 0| 3|Saundercock, Mr. ...| male|20.0| 0| 0| A/5. 2151| 8.05| null| S| | 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...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark.html
9ee98ef46ebb-9
| 20| 1| 3|Masselmani, Mrs. ...|female|null| 0| 0| 2649| 7.225| null| C| +-----------+--------+------+--------------------+------+----+-----+-----+----------------+-------+-----+--------+ only showing top 20 rows from langchain.agents import create_spark_dataframe_agent from la...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/spark.html
7e669928cc6d-0
.ipynb .pdf Pandas Dataframe Agent Contents Multi DataFrame Example 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 ...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/pandas.html
7e669928cc6d-1
Action: python_repl_ast Action Input: df['Age'].mean() Observation: 29.69911764705882 Thought: I now need to calculate the square root of the average age Action: python_repl_ast Action Input: math.sqrt(df['Age'].mean()) Observation: NameError("name 'math' is not defined") Thought: I need to import the math library Acti...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/pandas.html
7e669928cc6d-2
'177 rows in the age column are different.' previous Natural Language APIs next PlayWright Browser Toolkit Contents Multi DataFrame Example By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 11, 2023.
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/pandas.html
41dfb6101bff-0
.ipynb .pdf OpenAPI agents Contents 1st example: hierarchical planning agent To start, let’s collect some OpenAPI specs. How big is this spec? Let’s see some examples! Try another API. 2nd example: “json explorer” agent OpenAPI agents# We can construct agents to consume arbitrary APIs, here APIs conformant to the Ope...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-1
!mv openapi.yaml spotify_openapi.yaml --2023-03-31 15:45:56-- https://raw.githubusercontent.com/openai/openai-openapi/master/openapi.yaml Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133, 185.199.109.133, 185.199.111.133, ... Connecting to raw.githubusercontent.com (raw.githubusercont...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-2
--2023-03-31 15:45:57-- https://raw.githubusercontent.com/APIs-guru/openapi-directory/main/APIs/spotify.com/1.0.0/openapi.yaml Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133, 185.199.109.133, 185.199.111.133, ... Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|18...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-3
You’ll have to set up an application in the Spotify developer console, documented here, to get credentials: CLIENT_ID, CLIENT_SECRET, and REDIRECT_URI. To get an access tokens (and keep them fresh), you can implement the oauth flows, or you can use spotipy. If you’ve set your Spotify creedentials as environment variabl...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-4
from langchain.agents.agent_toolkits.openapi import planner llm = OpenAI(model_name="gpt-4", temperature=0.0) /Users/jeremywelborn/src/langchain/langchain/llms/openai.py:169: UserWarning: You are trying to use a chat model. This way of initializing it is no longer supported. Instead, please use: `from langchain.chat_mo...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-5
Action: api_controller Action Input: 1. GET /search to search for the album "Kind of Blue" 2. GET /albums/{id}/tracks to get the tracks from the "Kind of Blue" album 3. GET /me to get the current user's information 4. POST /users/{user_id}/playlists to create a new playlist named "Machine Blues" for the current user 5....
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-6
Observation: 7lzoEi44WOISnFYlrAIqyX Thought:Action: requests_post Action Input: {"url": "https://api.spotify.com/v1/playlists/7lzoEi44WOISnFYlrAIqyX/tracks", "data": {"uris": ["spotify:track:7q3kkfAVpmcZ8g6JUThi3o"]}, "output_instructions": "Confirm that the track was added to the playlist"} Observation: The track was ...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-7
Observation: 1. GET /me to get the current user's information 2. GET /recommendations/available-genre-seeds to retrieve a list of available genres 3. GET /recommendations with the seed_genre parameter set to "blues" to get a blues song recommendation for the user Thought:I have the plan, now I need to execute the API c...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-8
Observation: acoustic, afrobeat, alt-rock, alternative, ambient, anime, black-metal, bluegrass, blues, bossanova, brazil, breakbeat, british, cantopop, chicago-house, children, chill, classical, club, comedy, country, dance, dancehall, death-metal, deep-house, detroit-techno, disco, disney, drum-and-bass, dub, dubstep,...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-9
Observation: [ { id: '03lXHmokj9qsXspNsPoirR', name: 'Get Away Jordan' } ] Thought:I am finished executing the plan. Final Answer: The recommended blues song for user Jeremy Welborn (ID: 22rhrz4m4kvpxlsb5hezokzwi) is "Get Away Jordan" with the track ID: 03lXHmokj9qsXspNsPoirR. > Finished chain. Observation:...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-10
openai_agent.run(user_query) > Entering new AgentExecutor chain... Action: api_planner Action Input: I need to find the right API calls to generate a short piece of advice Observation: 1. GET /engines to retrieve the list of available engines 2. POST /completions with the selected engine and a prompt for generating a s...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-11
Thought:I will use the "davinci" engine to generate a short piece of advice. Action: requests_post Action Input: {"url": "https://api.openai.com/v1/completions", "data": {"engine": "davinci", "prompt": "Give me a short piece of advice on how to be more productive."}, "output_instructions": "Extract the text from the fi...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-12
> Entering new AgentExecutor chain... Action: requests_get Action Input: {"url": "https://api.openai.com/v1/models", "output_instructions": "Extract the ids of the available models"} Observation: babbage, davinci, text-davinci-edit-001, babbage-code-search-code, text-similarity-babbage-001, code-davinci-edit-001, text-...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-13
3. POST /completions with the chosen model and a prompt related to improving communication skills to generate a short piece of advice Thought:I have an updated plan, now I need to execute the API calls. Action: api_controller Action Input: 1. GET /models to retrieve the list of available models 2. Choose a suitable mod...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-14
> Finished chain. 'A short piece of advice for improving communication skills is to make sure to listen.' Takes awhile to get there! 2nd example: “json explorer” agent# Here’s an agent that’s not particularly practical, but neat! The agent has access to 2 toolkits. One comprises tools to interact with json: one tool to...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-15
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: ValueError('Value at path `data["servers"...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-16
Action: json_spec_list_keys Action Input: data["paths"] Observation: ['/engines', '/engines/{engine_id}', '/completions', '/chat/completions', '/edits', '/images/generations', '/images/edits', '/images/variations', '/embeddings', '/audio/transcriptions', '/audio/translations', '/engines/{engine_id}/search', '/files', '...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-17
Action: json_spec_list_keys Action Input: data["paths"] Observation: ['/engines', '/engines/{engine_id}', '/completions', '/chat/completions', '/edits', '/images/generations', '/images/edits', '/images/variations', '/embeddings', '/audio/transcriptions', '/audio/translations', '/engines/{engine_id}/search', '/files', '...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-18
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://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-19
> 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://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
41dfb6101bff-20
> Finished chain. 'The response of the POST request is {"id":"cmpl-70Ivzip3dazrIXU8DSVJGzFJj2rdv","object":"text_completion","created":1680307139,"model":"davinci","choices":[{"text":" with mummy not there”\\n\\nYou dig deep and come up with,","index":0,"logprobs":null,"finish_reason":"length"}],"usage":{"prompt_tokens...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/openapi.html
1fafec2316ad-0
.ipynb .pdf Python Agent Contents 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 from langchain.p...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/python.html
1fafec2316ad-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://python.langchain.com/en/latest/modules/agents/toolkits/examples/python.html
1fafec2316ad-2
Epoch 1000: loss = 0.0000 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 PowerBI Dataset Agent next Spark Dataframe Agent Contents Fibonacci Example Training neural net By Harrison Chase © Copyright 2023,...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/python.html
85adb5abc728-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://python.langchain.com/en/latest/modules/agents/toolkits/examples/json.html
85adb5abc728-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://python.langchain.com/en/latest/modules/agents/toolkits/examples/json.html
85adb5abc728-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://python.langchain.com/en/latest/modules/agents/toolkits/examples/json.html
85adb5abc728-3
Initialization Example: getting the required POST parameters for a request By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 11, 2023.
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/json.html
52e39b92e4b5-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
52e39b92e4b5-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
52e39b92e4b5-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
52e39b92e4b5-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
52e39b92e4b5-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
52e39b92e4b5-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
52e39b92e4b5-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
52e39b92e4b5-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
52e39b92e4b5-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
52e39b92e4b5-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
52e39b92e4b5-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
81a42dfcbb8a-0
.ipynb .pdf Gmail Toolkit Contents Create the Toolkit Customizing Authentication Use within an Agent Gmail Toolkit# This notebook walks through connecting a LangChain email to the Gmail API. To use this toolkit, you will need to set up your credentials explained in the Gmail API docs. Once you’ve downloaded the crede...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/gmail.html
81a42dfcbb8a-1
tools = toolkit.get_tools() tools [GmailCreateDraft(name='create_gmail_draft', description='Use this tool to create a draft email with the provided message fields.', args_schema=<class 'langchain.tools.gmail.create_draft.CreateDraftSchema'>, return_direct=False, verbose=False, callbacks=None, callback_manager=None, api...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/gmail.html
81a42dfcbb8a-2
GmailGetThread(name='get_gmail_thread', description=('Use this tool to search for email messages. The input must be a valid Gmail query. The output is a JSON list of messages.',), args_schema=<class 'langchain.tools.gmail.get_thread.GetThreadSchema'>, return_direct=False, verbose=False, callbacks=None, callback_manager...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/gmail.html
81a42dfcbb8a-3
WARNING:root:Failed to persist run: {"detail":"Not Found"} "The latest email in your drafts is from hopefulparrot@gmail.com with the subject 'Collaboration Opportunity'. The body of the email reads: 'Dear [Friend], I hope this letter finds you well. I am writing to you in the hopes of rekindling our friendship and to d...
https://python.langchain.com/en/latest/modules/agents/toolkits/examples/gmail.html
cbf6e12db958-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
cbf6e12db958-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
cbf6e12db958-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
cbf6e12db958-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
cbf6e12db958-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
cbf6e12db958-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
cbf6e12db958-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
d121c62867ad-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
d121c62867ad-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
d121c62867ad-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
d121c62867ad-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
d121c62867ad-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:"],...
https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html
d121c62867ad-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...
https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_agent.html
d121c62867ad-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
f8c08c904070-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
f8c08c904070-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
f8c08c904070-2
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 11, 2023.
https://python.langchain.com/en/latest/modules/agents/agents/custom_multi_action_agent.html
7cec7c28886f-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
7cec7c28886f-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
cc467006cfce-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
cc467006cfce-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
cc467006cfce-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
cc467006cfce-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
cc467006cfce-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
a6aca249f7a0-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
a6aca249f7a0-1
By Harrison Chase © Copyright 2023, Harrison Chase. Last updated on Jun 11, 2023.
https://python.langchain.com/en/latest/modules/agents/agents/agent_types.html
23fec2ec11f7-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
23fec2ec11f7-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
23fec2ec11f7-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
23fec2ec11f7-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
23fec2ec11f7-4
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 Observation (otherwise, the LLM may hallucinate an observation for you)....
https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_chat_agent.html
23fec2ec11f7-5
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 Jun 11, 2023.
https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_chat_agent.html
72fc97ca13f1-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
72fc97ca13f1-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
72fc97ca13f1-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
501c426628e3-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
501c426628e3-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
501c426628e3-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