{"id":8270,"date":"2023-11-30T06:31:37","date_gmt":"2023-11-30T14:31:37","guid":{"rendered":"https:\/\/live-cometml.pantheonsite.io\/?p=8270"},"modified":"2025-04-24T17:04:02","modified_gmt":"2025-04-24T17:04:02","slug":"implementing-agents-in-langchain","status":"publish","type":"post","link":"https:\/\/www.comet.com\/site\/blog\/implementing-agents-in-langchain\/","title":{"rendered":"Implementing Agents in LangChain"},"content":{"rendered":"\n<section class=\"section section--body\">\n<h2 class=\"section-divider\"><span style=\"color: var(--wpex-heading-color); font-size: var(--wpex-text-2xl); font-weight: var(--wpex-heading-font-weight); font-family: var(--wpex-body-font-family, var(--wpex-font-sans));\">A Guide to Enhancing AI with Strategic Decision-Making and Tool Integration<\/span><\/h2>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<figure class=\"graf graf--figure\">\n<\/figure><\/div><\/div><\/section>\n\n\n\n<figure class=\"wp-block-image aligncenter graf-image\"><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/0*-h2zNfFsN0EHbL8Y\" alt=\"Implementing Agents in LangChain with Comet + CometLLM\"\/><figcaption class=\"wp-element-caption\">Photo by <a href=\"https:\/\/unsplash.com\/@julientromeur?utm_source=medium&amp;utm_medium=referral\">julien Tromeur<\/a> on\u00a0<a href=\"http:\/\/Unsplash.com\">Unsplash<\/a><\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading graf graf--h3\">Agents in LangChain<\/h3>\n\n\n\n<p class=\"graf graf--p\">Agents in LangChain are systems that use a language model to interact with other tools.<\/p>\n\n\n\n<p class=\"graf graf--p\">They can be used for tasks such as grounded question\/answering, interacting with APIs, or taking action. LangChain provides:<\/p>\n\n\n\n<ul class=\"wp-block-list postList\">\n<li>A standard interface for agents.<\/li>\n\n\n\n<li>A selection of agents to choose from.<\/li>\n\n\n\n<li>Examples of end-to-end agents.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading graf graf--h3\">Agents vs.&nbsp;Chains<\/h3>\n\n\n\n<p class=\"graf graf--p\">The core idea of agents is to use an LLM to choose a sequence of actions.<\/p>\n\n\n\n<p class=\"graf graf--p\">In chains, a sequence of actions is hardcoded (in code). In agents, a language model is used as a reasoning engine to determine which actions to take and in which order. An agent uses a language model to interact with other tools or environments.<\/p>\n\n\n\n<p class=\"graf graf--p\">Agents involve a language model:<\/p>\n\n\n\n<ul class=\"wp-block-list postList\">\n<li>Making decisions about which actions to take.<\/li>\n\n\n\n<li>Taking those actions.<\/li>\n\n\n\n<li>Observing the results.<\/li>\n\n\n\n<li>Repeating the process until a desired outcome is achieved.<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote graf graf--blockquote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em class=\"markup--em markup--blockquote-em\">An agent is different from a chain in that a chain is a sequence of calls, whether to a language model or another utility.<\/em><\/p>\n<\/blockquote>\n\n\n\n<p class=\"graf graf--p\">A chain focuses on the <strong class=\"markup--strong markup--p-strong\">flow of information and computation<\/strong>. In contrast, an agent focuses on <strong class=\"markup--strong markup--p-strong\">decision-making and interaction with the environment<\/strong>.<\/p>\n\n\n\n<p class=\"graf graf--p\">Agents can be used for applications such as personal assistants, question answering, chatbots, querying tabular data, interacting with APIs, extraction, summarization, and evaluation.<\/p>\n\n\n\n<p class=\"graf graf--p\">Agents use an LLM as a reasoning engine and connect it to two key components: tools and memory.<\/p>\n\n\n\n<section class=\"section section--body\">\n<div class=\"section-divider\">\n<hr class=\"section-divider\">\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<blockquote class=\"graf graf--pullquote\"><p>Want to learn how to build modern software with LLMs using the newest tools and techniques in the field? <a class=\"markup--anchor markup--pullquote-anchor\" href=\"https:\/\/www.comet.com\/production\/site\/llm-course\/?utm_source=Heartbeat&amp;utm_medium=referral&amp;utm_content=Medium&amp;utm_campaign=Heartbeat_LangChain_Series_HS\" target=\"_blank\" rel=\"noopener ugc nofollow\" data-href=\"https:\/\/www.comet.com\/production\/site\/llm-course\/?utm_source=Heartbeat&amp;utm_medium=referral&amp;utm_content=Medium&amp;utm_campaign=Heartbeat_LangChain_Series_HS\">Check out this free LLMOps course<\/a> from industry expert Elvis Saravia of&nbsp;DAIR.AI!<\/p><\/blockquote>\n<\/div>\n<\/div>\n<\/section>\n\n\n\n<section class=\"section section--body\">\n<div class=\"section-divider\">\n<hr class=\"section-divider\">\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<h3 class=\"graf graf--h3\">What are tools and toolkits?<\/h3>\n<p class=\"graf graf--p\">In LangChain, tools and toolkits provide additional functionality and capabilities to agents.<\/p>\n<p class=\"graf graf--p\">Tools are individual components that perform specific tasks, such as retrieving information from external sources or processing data.<\/p>\n<p class=\"graf graf--p\">Conversely, toolkits are collections of tools designed to work together and provide a more comprehensive set of functionalities.<\/p>\n<h3 class=\"graf graf--h3\">Why do agents even need&nbsp;tools?<\/h3>\n<p class=\"graf graf--p\">Providing an agent with the right tools becomes a powerful system that can execute and implement solutions on your behalf.<\/p>\n<p class=\"graf graf--p\">Combining an agent\u2019s decision-making abilities with the functionality provided by tools allows it to perform a wide range of tasks effectively.<\/p>\n<p class=\"graf graf--p\">Here are a few reasons why an agent needs tools:<\/p>\n<ul class=\"postList\">\n<li class=\"graf graf--li\"><strong class=\"markup--strong markup--li-strong\">Access to external resources:<\/strong> Tools allow an agent to access and retrieve information from external sources, such as databases, APIs, or web scraping. This enables the agent to gather relevant data and use it for decision-making.<\/li>\n<li class=\"graf graf--li\"><strong class=\"markup--strong markup--li-strong\">Data processing and manipulation:<\/strong> Tools provide the necessary functionality for an agent to process and manipulate data. This includes cleaning and transforming data, performing calculations, or applying machine learning algorithms.<\/li>\n<li class=\"graf graf--li\"><strong class=\"markup--strong markup--li-strong\">Integration with other systems:<\/strong> Tools enable agents to integrate with other systems or services. For example, an agent may need to interact with a chatbot platform, a customer relationship management (CRM) system, or a knowledge base. Tools facilitate this integration and allow agents to exchange information with these systems.<\/li>\n<li class=\"graf graf--li\"><strong class=\"markup--strong markup--li-strong\">Customization and extensibility:<\/strong> While LangChain provides built-in tools, it also allows users to define custom tools. This means an agent can be equipped with tools tailored to its unique requirements. Custom tools can be created to address specific tasks or to integrate with proprietary systems.<\/li>\n<\/ul>\n<h3 class=\"graf graf--h3\">Why does an agent need&nbsp;memory?<\/h3>\n<p class=\"graf graf--p\">An agent in LangChain needs memory to store and retrieve information during decision-making.<\/p>\n<p class=\"graf graf--p\">Memory allows an agent to maintain context and remember previous interactions, which is crucial for providing personalized and coherent responses.<\/p>\n<p class=\"graf graf--p\">Here are a few reasons why an agent needs memory:<\/p>\n<ul class=\"postList\">\n<li class=\"graf graf--li\"><strong class=\"markup--strong markup--li-strong\">Contextual understanding:<\/strong> Memory helps an agent understand the context of a conversation or interaction. By storing previous messages or user inputs, the agent can refer back to them and provide more accurate and relevant responses. This allows the agent to maintain a coherent conversation and understand the user\u2019s intent.<\/li>\n<li class=\"graf graf--li\"><strong class=\"markup--strong markup--li-strong\">Long-term knowledge:<\/strong> Memory enables an agent to accumulate knowledge over time. By storing information in memory, the agent can build a knowledge base and use it to answer questions or provide recommendations. This allows the agent to provide more informed and accurate responses based on past interactions.<\/li>\n<li class=\"graf graf--li\"><strong class=\"markup--strong markup--li-strong\">Personalization:<\/strong> Memory allows an agent to personalize its responses based on the user\u2019s preferences or history. By remembering previous interactions, the agent can tailor its responses to the specific needs or interests of the user. This enhances the user experience and makes the agent more effective in achieving its objectives.<\/li>\n<li class=\"graf graf--li\"><strong class=\"markup--strong markup--li-strong\">Continuity:<\/strong> Memory ensures continuity in a conversation or interaction. The agent can pick up where it left off by storing the conversation history and maintaining a consistent dialogue with the user. This creates a more natural and engaging user experience.<\/li>\n<\/ul>\n<h3 class=\"graf graf--h3\">\ud83d\udc69\ud83c\udffe\u200d\ud83d\udcbb Let\u2019s see it in&nbsp;code<\/h3>\n<p class=\"graf graf--p\">Let\u2019s get some preliminaries out of the way<\/p>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"python\"><span class=\"pre--content\">%%capture\n!pip install langchain openai duckduckgo-search youtube_search wikipedia\n\n<span class=\"hljs-keyword\">import<\/span> os\n<span class=\"hljs-keyword\">import<\/span> getpass\n\nos.environ[<span class=\"hljs-string\">\"OPENAI_API_KEY\"<\/span>] = getpass.getpass(<span class=\"hljs-string\">\"Enter Your OpenAI API Key:\"<\/span>)<\/span><\/pre>\n<p class=\"graf graf--p\">And now set up a LLM<\/p>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"python\"><span class=\"pre--content\"><span class=\"hljs-keyword\">from<\/span> langchain.agents <span class=\"hljs-keyword\">import<\/span> load_tools\n<span class=\"hljs-keyword\">from<\/span> langchain.agents <span class=\"hljs-keyword\">import<\/span> initialize_agent\n<span class=\"hljs-keyword\">from<\/span> langchain.llms <span class=\"hljs-keyword\">import<\/span> OpenAI\n\nllm = OpenAI(temperature=<span class=\"hljs-number\">0.1<\/span>)<\/span><\/pre>\n<h3 class=\"graf graf--h3\">Giving the Agent&nbsp;Tools<\/h3>\n<p class=\"graf graf--p\">You can either pass the tools as arguments when initializing the toolkit or individually initialize the desired tools. The tools can be selected from the native tools in LangChain, or you can define custom tools if needed.<\/p>\n<p class=\"graf graf--p\">You can find the available native tools <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/github.com\/langchain-ai\/langchain\/blob\/ccb9e3ee2d4ffde1bb33c6c0df0db87aff3341bf\/libs\/langchain\/langchain\/agents\/load_tools.py#L409\" target=\"_blank\" rel=\"nofollow noopener\" data-href=\"https:\/\/github.com\/langchain-ai\/langchain\/blob\/ccb9e3ee2d4ffde1bb33c6c0df0db87aff3341bf\/libs\/langchain\/langchain\/agents\/load_tools.py#L409\">here<\/a> and look at the dictionary <code class=\"markup--code markup--p-code\">_EXTRA_OPTIONAL_TOOLS<\/code> for the key of the tool.<\/p>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"python\"><span class=\"pre--content\">tools = load_tools([<span class=\"hljs-string\">\"ddg-search\"<\/span>, <span class=\"hljs-string\">\"llm-math\"<\/span>, <span class=\"hljs-string\">\"wikipedia\"<\/span>], llm=llm)<\/span><\/pre>\n<p class=\"graf graf--p\">You can inspect the tool name and description:<\/p>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"python\"><span class=\"pre--content\">tools[<span class=\"hljs-number\">0<\/span>].name, tools[<span class=\"hljs-number\">0<\/span>].description<\/span><\/pre>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"plaintext\"><span class=\"pre--content\">\n('duckduckgo_search',\n 'A wrapper around DuckDuckGo Search. Useful for when you need to answer questions about current events. Input should be a search query.')<\/span><\/pre>\n<h3 class=\"graf graf--h3\">Initialize the&nbsp;agent<\/h3>\n<p class=\"graf graf--p\">There are two ways you can instantiate the agent: <code class=\"markup--code markup--p-code\">AgentExecutor<\/code> or <code class=\"markup--code markup--p-code\">initialize_agent<\/code>.<\/p>\n<h3 class=\"graf graf--h3\">AgentExecutor<\/h3>\n<p class=\"graf graf--p\">The <code class=\"markup--code markup--p-code\">AgentExecutor<\/code> class is responsible for executing the agent&#8217;s actions and managing the agent&#8217;s memory.<\/p>\n<p class=\"graf graf--p\">It takes an agent, a set of tools, and an optional memory object as input.<\/p>\n<p class=\"graf graf--p\">The <code class=\"markup--code markup--p-code\">AgentExecutor<\/code> provides a more flexible and customizable way to run the agent, as you can specify the tools and memory to be used.<\/p>\n<h4 class=\"graf graf--h4\">When to use <code class=\"markup--code markup--h4-code\">AgentExecutor<\/code>:<\/h4>\n<ul class=\"postList\">\n<li class=\"graf graf--li\">When you want more control over executing the agent\u2019s actions and memory management.<\/li>\n<li class=\"graf graf--li\">When you want to specify the tools and memory to be used by the agent.<\/li>\n<\/ul>\n<h3 class=\"graf graf--h3\">Initialize Agent<\/h3>\n<p class=\"graf graf--p\">The <code class=\"markup--code markup--p-code\">initialize_agent<\/code> function is a convenience function provided by LangChain that simplifies creating an agent.<\/p>\n<p class=\"graf graf--p\">It takes the agent class, the language model, and an optional list of tools as input.<\/p>\n<p class=\"graf graf--p\">It automatically initializes the agent with the specified language model and tools.<\/p>\n<h4 class=\"graf graf--h4\">When to use <code class=\"markup--code markup--h4-code\">initialize_agent<\/code>:<\/h4>\n<ul class=\"postList\">\n<li class=\"graf graf--li\">When you want a simplified way to create an agent without specifying the memory.<\/li>\n<li class=\"graf graf--li\">When you want to create an agent with default settings, quickly.<\/li>\n<\/ul>\n<p class=\"graf graf--p\">If you need more customization and control over the agent\u2019s execution, you should use <code class=\"markup--code markup--p-code\">AgentExecutor<\/code>.<\/p>\n<p class=\"graf graf--p\">If you prefer a more straightforward and quicker way to create an agent, you can use <code class=\"markup--code markup--p-code\">initialize_agent<\/code>.<\/p>\n<p class=\"graf graf--p\">We\u2019re going the simple and quick route here.<\/p>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"python\"><span class=\"pre--content\">agent = initialize_agent(tools,\n                         llm,\n                         agent=<span class=\"hljs-string\">\"zero-shot-react-description\"<\/span>,\n                         verbose=<span class=\"hljs-literal\">True<\/span>)<\/span><\/pre>\n<p class=\"graf graf--p\">You can inspect the prompt for the agent:<\/p>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"python\"><span class=\"pre--content\"><span class=\"hljs-built_in\">print<\/span>(agent.agent.llm_chain.prompt.template)<\/span><\/pre>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"plaintext\"><span class=\"pre--content\">Answer the following questions as best you can. You have access to the following tools:\n\nduckduckgo_search: A wrapper around DuckDuckGo Search. Useful for when you need to answer questions about current events. Input should be a search query.\nCalculator: Useful for when you need to answer questions about math.\nWikipedia: A wrapper around Wikipedia. Useful for when you need to answer general questions about people, places, companies, facts, historical events, or other subjects. Input should be a search query.\n\nUse the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of [duckduckgo_search, Calculator, Wikipedia]\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought\/Action\/Action Input\/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question\n\nBegin!\n\nQuestion: {input}\nThought:{agent_scratchpad}<\/span><\/pre>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"1\" data-code-block-lang=\"python\"><span class=\"pre--content\">query = <span class=\"hljs-string\">\"\"\"\nWho is the current Chief AI Scientist at Meta AI? When was he born?\nWhat is his current age? What is the average life expectancy of people where he was born?\n\"\"\"<\/span>\n\nagent.run(query)<\/span><\/pre>\n<pre class=\"graf graf--pre graf--preV2\" spellcheck=\"false\" data-code-block-mode=\"2\" data-code-block-lang=\"plaintext\"><span class=\"pre--content\">&gt; Entering new AgentExecutor chain...\n I need to find out who the Chief AI Scientist is, when he was born, and what the average life expectancy is in his country.\n\nAction: duckduckgo_search\nAction Input: \"Chief AI Scientist Meta AI\"\nObservation: At the same panel, Yann LeCun, chief AI scientist at Facebook parent Meta, was asked about the current limitations of AI. He focused on generative AI trained on large language models,... The strength of the deep learning era of artificial intelligence has lead to something of a renaissance in corporate R&amp;D in information technology, according to Yann LeCun, chief AI... Meta's chief A.I. scientist calls A.I. doomers 'preposterous' and predicts LLMs are just a passing fad BY Jeremy Kahn June 14, 2023, 12:17 PM PDT Meta Chief A.I. Scientist Yann LeCun... Prof LeCun now works as the chief AI scientist at Meta, the parent company of Facebook, Instagram and WhatsApp. He disagrees with his fellow godfathers that AI is a risk to the human race. One of the 'Godfathers of AI' and Chief AI Scientist at Meta AI (FAIR), Yann LeCun joined us for a special live talk and fireside chat with our Executive Director, Usama Fayyad at...\nThought: Yann LeCun is the Chief AI Scientist at Meta AI.\n\nAction: Wikipedia\nAction Input: \"Yann LeCun\"\nObservation: Page: Yann LeCun\nSummary: Yann Andr\u00e9 LeCun ( l\u0259-KUN, French: [l\u0259k\u0153\u0303]; originally spelled Le Cun; born 8 July 1960) is a  Turing Award winning French computer scientist working primarily in the fields of machine learning, computer vision, mobile robotics and computational neuroscience. He is the Silver Professor of the Courant Institute of Mathematical Sciences at New York University and Vice-President, Chief AI Scientist at Meta.He is well known for his work on optical character recognition and computer vision using convolutional neural networks (CNN), and is a founding father of convolutional nets. He is also one of the main creators of the DjVu image compression technology (together with L\u00e9on Bottou and Patrick Haffner). He co-developed the Lush programming language with L\u00e9on Bottou.\nLeCun received the 2018 Turing Award (often referred to as the \"Nobel Prize of Computing\"), together with Yoshua Bengio and Geoffrey Hinton, for their work on deep learning.\nThe three are sometimes referred to as the \"Godfathers of AI\" and \"Godfathers of Deep Learning\".\n\nPage: LeNet\nSummary: LeNet is a convolutional neural network structure proposed by LeCun et al. in 1998,. In general, LeNet refers to LeNet-5 and is a simple convolutional neural network. Convolutional neural networks are a kind of feed-forward neural network whose artificial neurons can respond to a part of the surrounding cells in the coverage range and perform well in large-scale image processing.\n\n\n\nPage: Geoffrey Hinton\nSummary: Geoffrey Everest Hinton  (born 6 December 1947) is a British-Canadian cognitive psychologist and computer scientist, most noted for his work on artificial neural networks. From 2013 to 2023, he divided his time working for Google (Google Brain) and the University of Toronto, before publicly announcing his departure from Google in May 2023 citing concerns about the risks of artificial intelligence (AI) technology. In 2017, he co-founded and became the chief scientific advisor of the Vector Institute in Toronto.With David Rumelhart and Ronald J. Williams, Hinton was co-author of a highly cited paper published in 1986 that popularised the backpropagation algorithm for training multi-layer neural networks, although they were not the first to propose the approach. Hinton is viewed as a leading figure in the deep learning community. The dramatic image-recognition milestone of the AlexNet designed in collaboration with his students Alex Krizhevsky and Ilya Sutskever for the ImageNet challenge 2012 was a breakthrough in the field of computer vision.Hinton received the 2018 Turing Award (often referred to as the \"Nobel Prize of Computing\"), together with Yoshua Bengio and Yann LeCun, for their work on deep learning. They are sometimes referred to as the \"Godfathers of Deep Learning\", and have continued to give public talks together.In May 2023, Hinton announced his resignation from Google to be able to \"freely speak out about the risks of A.I.\" He has voiced concerns about deliberate misuse by malicious actors, technological unemployment, and existential risk from artificial general intelligence.\n\n\nThought: Yann LeCun was born on July 8, 1960 and is currently 63 years old.\n\nAction: duckduckgo_search\nAction Input: \"Average life expectancy in France\"\nObservation: Chart and table of France life expectancy from 1950 to 2023. United Nations projections are also included through the year 2100. The current life expectancy for France in 2023 is 83.13 years, a 0.16% increase from 2022. The life expectancy for France in 2022 was 83.00 years, a 0.16% increase from 2021. The life expectancy for France in 2021 was ... Comparison of average female and male life expectancy as defined by WHO for 2019. Open the original chart in a separate tab and hover over a bubble to highlight it. The squares of bubbles are proportional to country population according to estimation of the UN for 2019. ... France: 82.7: 79.7: 85.5: 5.8: Life expectancy at birth, total (years) - France | Data In 2021, the total life expectancy at birth in France remained nearly unchanged at around 82.32 years. These figures refer to the expected lifespan of the average newborn in a given country... Demographics Distribution of the population in France in 2023, by age group\nThought: The average life expectancy in France is 82.7 years.\n\nFinal Answer: Yann LeCun is the current Chief AI Scientist at Meta AI. He was born on July 8, 1960 and is currently 63 years old. The average life expectancy in France, where he was born, is 82.7 years.\n\n&gt; Finished chain.\nYann LeCun is the current Chief AI Scientist at Meta AI. He was born on July 8, 1960 and is currently 63 years old. The average life expectancy in France, where he was born, is 82.7 years.<\/span><\/pre>\n<h3 class=\"graf graf--h3\">Conclusion<\/h3>\n<p class=\"graf graf--p\">As the digital and AI landscapes evolve, the role of agents within LangChain takes on new significance.<\/p>\n<p class=\"graf graf--p\">Agents, powered by language models act as dynamic systems interfacing with various tools, performing tasks ranging from grounded question answering to API interactions. This blog post has delved into the architecture of these agents, contrasting them with chains and highlighting their decision-making prowess. Equipped with tools and memory, agents within LangChain offer a sophisticated way to handle complex tasks, pushing the boundaries of what\u2019s possible with AI.<\/p>\n<p class=\"graf graf--p\">They stand as a testament to the future of automated systems, promising smarter, more intuitive interactions within digital environments.<\/p>\n<\/div>\n<\/div>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>A Guide to Enhancing AI with Strategic Decision-Making and Tool Integration Agents in LangChain Agents in LangChain are systems that use a language model to interact with other tools. They can be used for tasks such as grounded question\/answering, interacting with APIs, or taking action. LangChain provides: Agents vs.&nbsp;Chains The core idea of agents is [&hellip;]<\/p>\n","protected":false},"author":68,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"customer_name":"","customer_description":"","customer_industry":"","customer_technologies":"","customer_logo":"","footnotes":""},"categories":[65,7],"tags":[70,71,52,31,34],"coauthors":[166],"class_list":["post-8270","post","type-post","status-publish","format-standard","hentry","category-llmops","category-tutorials","tag-langchain","tag-language-models","tag-llm","tag-llmops","tag-prompt-engineering"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Implementing Agents in LangChain - Comet<\/title>\n<meta name=\"description\" content=\"LangChain Agents are systems that use an LM to interact with other tools for tasks such as grounded questions-answering or API interaction\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.comet.com\/site\/blog\/implementing-agents-in-langchain\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Implementing Agents in LangChain\" \/>\n<meta property=\"og:description\" content=\"LangChain Agents are systems that use an LM to interact with other tools for tasks such as grounded questions-answering or API interaction\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.comet.com\/site\/blog\/implementing-agents-in-langchain\/\" \/>\n<meta property=\"og:site_name\" content=\"Comet\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cometdotml\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-30T14:31:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-24T17:04:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/0*-h2zNfFsN0EHbL8Y\" \/>\n<meta name=\"author\" content=\"Harpreet Sahota\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Cometml\" \/>\n<meta name=\"twitter:site\" content=\"@Cometml\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Harpreet Sahota\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Implementing Agents in LangChain - Comet","description":"LangChain Agents are systems that use an LM to interact with other tools for tasks such as grounded questions-answering or API interaction","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.comet.com\/site\/blog\/implementing-agents-in-langchain\/","og_locale":"en_US","og_type":"article","og_title":"Implementing Agents in LangChain","og_description":"LangChain Agents are systems that use an LM to interact with other tools for tasks such as grounded questions-answering or API interaction","og_url":"https:\/\/www.comet.com\/site\/blog\/implementing-agents-in-langchain\/","og_site_name":"Comet","article_publisher":"https:\/\/www.facebook.com\/cometdotml","article_published_time":"2023-11-30T14:31:37+00:00","article_modified_time":"2025-04-24T17:04:02+00:00","og_image":[{"url":"https:\/\/cdn-images-1.medium.com\/max\/1600\/0*-h2zNfFsN0EHbL8Y","type":"","width":"","height":""}],"author":"Harpreet Sahota","twitter_card":"summary_large_image","twitter_creator":"@Cometml","twitter_site":"@Cometml","twitter_misc":{"Written by":"Harpreet Sahota","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.comet.com\/site\/blog\/implementing-agents-in-langchain\/#article","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/blog\/implementing-agents-in-langchain\/"},"author":{"name":"Harpreet Sahota","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/46036ab474aa916e2873daece26a28d6"},"headline":"Implementing Agents in LangChain","datePublished":"2023-11-30T14:31:37+00:00","dateModified":"2025-04-24T17:04:02+00:00","mainEntityOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/implementing-agents-in-langchain\/"},"wordCount":1213,"publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/implementing-agents-in-langchain\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn-images-1.medium.com\/max\/1600\/0*-h2zNfFsN0EHbL8Y","keywords":["LangChain","Language Models","LLM","LLMOps","Prompt Engineering"],"articleSection":["LLMOps","Tutorials"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.comet.com\/site\/blog\/implementing-agents-in-langchain\/","url":"https:\/\/www.comet.com\/site\/blog\/implementing-agents-in-langchain\/","name":"Implementing Agents in LangChain - Comet","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/implementing-agents-in-langchain\/#primaryimage"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/implementing-agents-in-langchain\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn-images-1.medium.com\/max\/1600\/0*-h2zNfFsN0EHbL8Y","datePublished":"2023-11-30T14:31:37+00:00","dateModified":"2025-04-24T17:04:02+00:00","description":"LangChain Agents are systems that use an LM to interact with other tools for tasks such as grounded questions-answering or API interaction","breadcrumb":{"@id":"https:\/\/www.comet.com\/site\/blog\/implementing-agents-in-langchain\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.comet.com\/site\/blog\/implementing-agents-in-langchain\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/blog\/implementing-agents-in-langchain\/#primaryimage","url":"https:\/\/cdn-images-1.medium.com\/max\/1600\/0*-h2zNfFsN0EHbL8Y","contentUrl":"https:\/\/cdn-images-1.medium.com\/max\/1600\/0*-h2zNfFsN0EHbL8Y"},{"@type":"BreadcrumbList","@id":"https:\/\/www.comet.com\/site\/blog\/implementing-agents-in-langchain\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.comet.com\/site\/"},{"@type":"ListItem","position":2,"name":"Implementing Agents in LangChain"}]},{"@type":"WebSite","@id":"https:\/\/www.comet.com\/site\/#website","url":"https:\/\/www.comet.com\/site\/","name":"Comet","description":"Build Better Models Faster","publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.comet.com\/site\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.comet.com\/site\/#organization","name":"Comet ML, Inc.","alternateName":"Comet","url":"https:\/\/www.comet.com\/site\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/","url":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","contentUrl":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","width":310,"height":310,"caption":"Comet ML, Inc."},"image":{"@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/cometdotml","https:\/\/x.com\/Cometml","https:\/\/www.youtube.com\/channel\/UCmN63HKvfXSCS-UwVwmK8Hw"]},{"@type":"Person","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/46036ab474aa916e2873daece26a28d6","name":"Harpreet Sahota","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/image\/2d21512be19ba7e19a71a803309e2a88","url":"https:\/\/secure.gravatar.com\/avatar\/a6ca5a533fc9f143a0a7428037ff652aa0633d66bf27e76ae89b955ae72a0f2d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a6ca5a533fc9f143a0a7428037ff652aa0633d66bf27e76ae89b955ae72a0f2d?s=96&d=mm&r=g","caption":"Harpreet Sahota"},"url":"https:\/\/www.comet.com\/site\/blog\/author\/theartistsofdatasciencegmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/8270","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/comments?post=8270"}],"version-history":[{"count":1,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/8270\/revisions"}],"predecessor-version":[{"id":15430,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/8270\/revisions\/15430"}],"wp:attachment":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/media?parent=8270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/categories?post=8270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/tags?post=8270"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/coauthors?post=8270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}