LangChain Agents
What it is
LangChain Agents is the agent layer of LangChain, a framework for building applications with language models. In LangChain’s own definition, an agent is a model calling tools in a loop until a given task is complete. A harness is everything around that loop: the prompt, the tools, and any middleware that shapes the model’s behaviour.
The current entry point is create_agent in Python, and createAgent in JavaScript. You give it a model, a list of tools, and a system prompt, and it builds an agent that can reason, call a tool, read the result, and decide what to do next. It runs until the model gives a final answer or a stop condition is reached, such as an iteration limit.
LangChain itself is a broader framework with integrations for models, tools, vector stores and memory. LangGraph, a separate library from the same team, is the lower-level runtime underneath: create_agent builds a LangGraph graph that you can customise with middleware. If you want a ready-made, batteries-included agent, LangChain’s docs point to Deep Agents. If you want the standard tool loop that you configure yourself, use create_agent. If you need explicit control over state and steps, use LangGraph directly.
Who made it
LangChain is made by LangChain, Inc., the company founded by Harrison Chase. The project is open source on GitHub, and its documentation is at docs.langchain.com.
- Official docs: https://docs.langchain.com/oss/javascript/langchain/agents
- GitHub: https://github.com/langchain-ai/langchain
What it does
LangChain agents can search the web, query a database, read files, call APIs, run code, and write structured output. Because tools are ordinary functions — in Python, any Python callable, a LangChain tool, or a tool dictionary — you can wrap almost any capability as a tool and hand it to the agent.
Agents support structured output, so you can ask for a validated schema instead of free text, and streaming, so you can show tokens and tool events as they happen. Every agent keeps its conversation history in an AgentState object, and you can resume a conversation by passing the same thread ID.
How it works
You create an agent with a model, tools, and a system prompt. At run time, the agent sends the conversation and the tool descriptions to the model. The model either replies directly or returns a tool call. LangChain runs the tool, adds the result to the history, and calls the model again. That loop continues until the model produces a final answer.
Middleware hooks run before and after the model call and around each tool call, which is how you add guardrails without rewriting the loop. You can also pass per-run context, such as a user ID or API keys, so tools can act for the right person. State is append-only: new messages are added, never replaced, which keeps the history auditable.
LangChain agents work with many model providers, and the model can be chosen once at creation or selected dynamically at run time, which helps with cost and routing. Tools can also be chosen dynamically, so an agent only sees the tools it is allowed to use in that moment.
How to start
- Install LangChain for your language. In Python, the docs use the
langchainpackage; in JavaScript, installlangchainfrom npm. Check the official docs for the current install command for your version. - Set an API key for your model provider as an environment variable, for example
OPENAI_API_KEYfor OpenAI. - Define at least one tool. In Python, decorate a function with
@tooland give it a clear name, description, and typed arguments. The description is what the model reads to decide when to use it. - Create the agent with
create_agent, passing the model, the tools, and a short system prompt that says what the agent should do and what it should not do. - Invoke it with a message and a thread ID, for example
agent.invoke({"messages": [{"role": "user", "content": "What is the weather in London?"}]}, config={"configurable": {"thread_id": "1"}}). The exact call shape differs between Python and JavaScript — follow the docs page for your language. - Test with a small, safe task, read the tool calls in the trace, and only then add tools that change data.
For a guided start, read the Agents page in the official docs, then the Tools page, then the middleware page for guardrails.
Who it is for
LangChain Agents is for developers who are comfortable writing Python or JavaScript and want a standard, well-documented agent loop they can extend. It suits teams building research assistants, support agents, data agents, and internal tools, and developers who already use LangChain integrations and want their agent to use the same models, tools and tracing. It is not a no-code builder: you write code, but you do not have to write the loop, state handling, or streaming yourself.
Watch out for
LangChain has changed its agent API over time. Older tutorials use AgentExecutor and initialize_agent; those have moved to langchain-classic in recent versions, and the current entry point is create_agent. Follow the current docs at docs.langchain.com and check the version you installed before copying code from a blog post.