!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}return t}()||function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}(),document.documentElement.setAttribute("data-announcement-bar-initially-dismissed",function(){try{return"true"===localStorage.getItem("docusaurus.announcement.dismiss")}catch(t){}return!1}())

[Skip to main content](#__docusaurus_skipToContent_fallback)

LangChain v0.2 is coming soon! Preview the new docs [here](/v0.2/docs/introduction/).

[

![🦜️🔗 Langchain](/v0.1/img/brand/wordmark.png)![🦜️🔗 Langchain](/v0.1/img/brand/wordmark-dark.png)

](/v0.1/)[Docs](/v0.1/docs/get_started/introduction/)[Use cases](/v0.1/docs/use_cases/)[Integrations](/v0.1/docs/integrations/platforms/)[API Reference](https://api.js.langchain.com)

[More](#)

*   [People](/v0.1/docs/people/)
*   [Community](/v0.1/docs/community/)
*   [Tutorials](/v0.1/docs/additional_resources/tutorials/)
*   [Contributing](/v0.1/docs/contributing/)

[v0.1](#)

*   [v0.2](https://js.langchain.com/v0.2/docs/introduction)
*   [v0.1](/v0.1/docs/get_started/introduction/)

[🦜🔗](#)

*   [LangSmith](https://smith.langchain.com)
*   [LangSmith Docs](https://docs.smith.langchain.com)
*   [LangChain Hub](https://smith.langchain.com/hub)
*   [LangServe](https://github.com/langchain-ai/langserve)
*   [Python Docs](https://python.langchain.com/)

[Chat](https://chatjs.langchain.com)[](https://github.com/langchain-ai/langchainjs)

Search

*   [Get started](/v0.1/docs/get_started/)
    
    *   [Introduction](/v0.1/docs/get_started/introduction/)
    *   [Installation](/v0.1/docs/get_started/installation/)
    *   [Quickstart](/v0.1/docs/get_started/quickstart/)
*   [LangChain Expression Language](/v0.1/docs/expression_language/)
    
    *   [Get started](/v0.1/docs/expression_language/get_started/)
    *   [Why use LCEL?](/v0.1/docs/expression_language/why/)
    *   [Interface](/v0.1/docs/expression_language/interface/)
    *   [Streaming](/v0.1/docs/expression_language/streaming/)
    *   [How to](/v0.1/docs/expression_language/how_to/routing/)
        
    *   [Cookbook](/v0.1/docs/expression_language/cookbook/)
        
    *   [LangChain Expression Language (LCEL)](/v0.1/docs/expression_language/)
*   [Modules](/v0.1/docs/modules/)
    
    *   [Model I/O](/v0.1/docs/modules/model_io/)
        
    *   [Retrieval](/v0.1/docs/modules/data_connection/)
        
    *   [Chains](/v0.1/docs/modules/chains/)
    *   [Agents](/v0.1/docs/modules/agents/)
        
        *   [Quick start](/v0.1/docs/modules/agents/quick_start/)
        *   [Concepts](/v0.1/docs/modules/agents/concepts/)
        *   [Agent Types](/v0.1/docs/modules/agents/agent_types/)
            
        *   [How-to](/v0.1/docs/modules/agents/how_to/custom_agent/)
            
        *   [Agents](/v0.1/docs/modules/agents/)
        *   [Tools](/v0.1/docs/modules/agents/tools/)
            
    *   [More](/v0.1/docs/modules/memory/)
        
*   [Security](/v0.1/docs/security/)
*   [Guides](/v0.1/docs/guides/)
    
*   [Ecosystem](/v0.1/docs/ecosystem/)
    
*   [LangGraph](/v0.1/docs/langgraph/)
*   * * *
    

*   [](/v0.1/)
*   [Modules](/v0.1/docs/modules/)
*   [Agents](/v0.1/docs/modules/agents/)
*   Concepts

On this page

Concepts
========

The core idea of agents is to use a language model to choose a sequence of actions to take. 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.

There are several key components here:

Schema[​](#schema "Direct link to Schema")
------------------------------------------

LangChain has several abstractions to make working with agents easy.

### AgentAction[​](#agentaction "Direct link to AgentAction")

This represents the action an agent should take. It has a `tool` property (which is the name of the tool that should be invoked) and a `toolInput` property (the input to that tool)

### AgentFinish[​](#agentfinish "Direct link to AgentFinish")

This represents the final result from an agent, when it is ready to return to the user. It contains a `returnValues` key-value mapping, which contains the final agent output. Usually, this contains an `output` key containing a string that is the agent's response.

### Intermediate Steps[​](#intermediate-steps "Direct link to Intermediate Steps")

These represent previous agent actions and corresponding outputs from this CURRENT agent run. These are important to pass to future iteration so the agent knows what work it has already done.

Agent[​](#agent "Direct link to Agent")
---------------------------------------

This is the chain responsible for deciding what step to take next. This is usually powered by a language model, a prompt, and an output parser.

Different agents have different prompting styles for reasoning, different ways of encoding inputs, and different ways of parsing the output. For a full list of built-in agents see [agent types](/v0.1/docs/modules/agents/agent_types/). You can also **build custom agents**, should you need further control.

### Agent Inputs[​](#agent-inputs "Direct link to Agent Inputs")

The inputs to an agent are an object. There is only one required key: `steps`, which corresponds to `Intermediate Steps` as described above.

Generally, the PromptTemplate takes care of transforming these pairs into a format that can best be passed into the LLM.

### Agent Outputs[​](#agent-outputs "Direct link to Agent Outputs")

The output is the next action(s) to take or the final response to send to the user (`AgentAction`s or `AgentFinish`). Concretely, this can be typed as `AgentAction | AgentAction[] | AgentFinish`.

The output parser is responsible for taking the raw LLM output and transforming it into one of these three types.

AgentExecutor[​](#agentexecutor "Direct link to AgentExecutor")
---------------------------------------------------------------

The agent executor is the runtime for an agent. This is what actually calls the agent, executes the actions it chooses, passes the action outputs back to the agent, and repeats. In pseudocode, this looks roughly like:

    let nextAction = agent.getAction(...);while (!isAgentFinish(nextAction)) {  const observation = run(nextAction);  nextAction = agent.getAction(..., nextAction, observation);}return nextAction;

While this may seem simple, there are several complexities this runtime handles for you, including:

1.  Handling cases where the agent selects a non-existent tool
2.  Handling cases where the tool errors
3.  Handling cases where the agent produces output that cannot be parsed into a tool invocation
4.  Logging and observability at all levels (agent decisions, tool calls) to stdout and/or to [LangSmith](https://smith.langchain.com).

Tools[​](#tools "Direct link to Tools")
---------------------------------------

Tools are functions that an agent can invoke. The `Tool` abstraction consists of two components:

1.  The input schema for the tool. This tells the LLM what parameters are needed to call the tool. Without this, it will not know what the correct inputs are. These parameters should be sensibly named and described.
2.  The function to run. This is generally just a JavaScript function that is invoked.

### Considerations[​](#considerations "Direct link to Considerations")

There are two important design considerations around tools:

1.  Giving the agent access to the right tools
2.  Describing the tools in a way that is most helpful to the agent

Without thinking through both, you won't be able to build a working agent. If you don't give the agent access to a correct set of tools, it will never be able to accomplish the objectives you give it. If you don't describe the tools well, the agent won't know how to use them properly.

LangChain provides a wide set of built-in tools, but also makes it easy to define your own (including custom descriptions). For a full list of built-in tools, see the [tools integrations section](/v0.1/docs/integrations/tools/)

Toolkits[​](#toolkits "Direct link to Toolkits")
------------------------------------------------

For many common tasks, an agent will need a set of related tools. For this LangChain provides the concept of toolkits - groups of around 3-5 tools needed to accomplish specific objectives. For example, the GitHub toolkit has a tool for searching through GitHub issues, a tool for reading a file, a tool for commenting, etc.

LangChain provides a wide set of toolkits to get started. For a full list of built-in toolkits, see the [toolkits integrations section](/v0.1/docs/integrations/toolkits/)

* * *

#### Help us out by providing feedback on this documentation page:

[

Previous

Quick start

](/v0.1/docs/modules/agents/quick_start/)[

Next

Agent Types

](/v0.1/docs/modules/agents/agent_types/)

*   [Schema](#schema)
    *   [AgentAction](#agentaction)
    *   [AgentFinish](#agentfinish)
    *   [Intermediate Steps](#intermediate-steps)
*   [Agent](#agent)
    *   [Agent Inputs](#agent-inputs)
    *   [Agent Outputs](#agent-outputs)
*   [AgentExecutor](#agentexecutor)
*   [Tools](#tools)
    *   [Considerations](#considerations)
*   [Toolkits](#toolkits)

Community

*   [Discord](https://discord.gg/cU2adEyC7w)
*   [Twitter](https://twitter.com/LangChainAI)

GitHub

*   [Python](https://github.com/langchain-ai/langchain)
*   [JS/TS](https://github.com/langchain-ai/langchainjs)

More

*   [Homepage](https://langchain.com)
*   [Blog](https://blog.langchain.dev)

Copyright © 2024 LangChain, Inc.