langchain-ai / langchainjs
LangChain.js v1 is strongest when the agent loop stays observable and constrained
LangChain.js v1 centers its main package on agents, model and tool abstractions, structured output, messages, and middleware, with agents running on LangGraph. That shared machinery can shorten integration work, but it does not remove the hard product work of permissions, context selection, evaluation, cost controls, and truthful failure handling.
WHAT TO KNOW FIRST
- LangChain v1's createAgent is built on LangGraph and uses middleware as the main extension point for prompts, models, tools, guardrails, and lifecycle behavior.
- Provider abstraction reduces integration repetition but cannot make model capabilities, tool schemas, streaming events, or billing identical.
- Tools are application authority: input validation, authorization, idempotency, timeouts, approval, and audit records must be enforced outside model instructions.
01Read the repository through the v1 package boundary
The LangChain.js repository contains a TypeScript framework and packages for building model-powered applications. In the current v1 line, the main langchain package was streamlined around agent building blocks. The official release guide says legacy chains, retrievers, indexing, and older community exports moved to @langchain/classic. Current examples should therefore begin with the v1 documentation rather than copying an older chain import from a blog post.
The package split is more than housekeeping. It tells teams which abstraction the maintainers consider the current center: createAgent, messages, models, tools, structured output, and middleware, built over LangGraph execution. Existing applications can continue with classic functionality while migrating deliberately. New code should add the narrowest packages it needs and record why. Installing every integration preemptively expands updates, bundle surface, and credential handling without improving the first use case.
02createAgent provides a loop, not a finished worker
The standard createAgent function connects a model, tools, and a system prompt. The model receives messages, may request one or more tool calls, observes their results, and continues until it returns without another call. LangChain handles the repeated message and execution plumbing. Because the agent is built on LangGraph, it can also participate in streaming, persistence, interruption, and larger stateful workflows when configured with the required components.
A running loop does not define a product objective or reliable stopping policy. The application still needs task scope, maximum model and tool calls, timeouts, cancellation, cost budgets, and a terminal status that distinguishes success from a fluent explanation. A model may call the wrong tool, repeat a failed operation, or stop before the external result is complete. The surrounding system must decide what evidence counts as completion and retain enough trace data to audit that decision.
03Provider abstraction has a useful limit
LangChain offers a standard model interface and separate integration packages for providers. This can make messages, streaming, retries, and model selection more consistent across an application. It is useful when a team compares providers, routes workloads, or wants tool definitions shared by several models. The abstraction is not proof that models are interchangeable. Context limits, tool-call formats, structured output support, content blocks, safety behavior, latency, and billing can differ materially.
Keep provider and model identifiers in trace records and evaluation results. Test each supported combination rather than assuming a fallback preserves quality. Provider-specific capabilities should be exposed deliberately instead of hidden behind a lowest-common-denominator interface that nobody understands. Model routing is also a business decision: a cheaper fallback that returns plausible but unusable output is not resilience. The application needs explicit error classes for unavailable, rate-limited, refused, malformed, and unsupported responses.
04Tools are typed authority boundaries
A LangChain tool has a name, description, input schema, and implementation. Zod schemas can validate arguments before code executes, while the description helps the model decide when to call the tool. The implementation may search a catalog, read an account, change a record, send a message, or trigger infrastructure. That makes tool design closer to an API endpoint than a helper function. Names and schemas should be narrow, unambiguous, and versioned with the domain they expose.
Authorization cannot live in the tool description or system prompt. Check the authenticated user, tenant, resource, and requested action inside the application boundary. Write operations need idempotency keys, timeouts, retries appropriate to the external service, and audit records. Return compact structured results and stable error codes rather than dumping entire databases or stack traces back into model context. High-impact tools should require human approval or a separately verified workflow state before execution.
- Separate read and write capabilities instead of hiding both behind one broad tool.
- Treat tool output as untrusted content that may contain instructions, secrets, or malformed data.
- Record requested arguments, authorization result, external receipt, and final state with sensitive fields redacted.
05Middleware is the v1 control surface
LangChain v1 makes middleware the main way to intercept the agent lifecycle. Official middleware can summarize long conversations, require human approval, redact personally identifiable information, limit model calls, retry failures, or change tool availability. Custom hooks can run before or after the agent, around model calls, and around tool calls. Middleware travels inside the LangGraph created by createAgent, including when that agent is embedded in a larger graph.
Order and failure behavior matter. A redaction layer must run before the model receives sensitive text, an approval gate must wrap the actual write call, and logging should not reintroduce values another layer removed. Summarization can save context but may discard facts the next decision needs. Test middleware as a composition, not only as isolated functions. Give each layer a bounded responsibility and avoid building a second invisible workflow whose control flow is harder to inspect than an explicit graph.
06Structured output establishes a useful contract
Structured output lets an agent return data validated against a schema rather than leaving every caller to parse prose. Current documentation supports provider-native structured output where available and tool-based strategies elsewhere. The result is exposed separately from ordinary messages, allowing the application to render, store, or route a typed object. This is useful for classification, extraction, plans, and downstream API calls.
A valid shape is not a correct fact. A model can place the wrong customer, amount, or source in perfectly valid JSON. Add field constraints, provenance, and domain checks after schema validation. High-impact decisions may need deterministic lookup or human review. Version schemas and keep raw provider or trace references according to the privacy policy so regressions can be investigated. If validation fails, return an explicit failure rather than silently coercing a plausible object into the workflow.
07Memory, context, and retrieval are separate choices
Short-term conversation state can be persisted through LangGraph checkpointers, while long-term memory and retrieval require additional stores or application design. More context is not automatically better. Old messages consume tokens, retrieved documents can be stale or malicious, and user data must remain within tenant and retention boundaries. Summarization preserves selected meaning but changes the evidence available to later steps.
Define which source owns each fact, how it is retrieved, when it expires, and whether the model may act on it. Retrieved content should be treated as data, not privileged instructions, because documents and web pages can contain prompt injection. Cite or attach source identifiers when answers depend on knowledge, and use deterministic application reads for permissions or account state. Memory should improve continuity without becoming an unreviewed database of everything a user ever said.
08Evaluation and operations decide whether the framework helps
A production agent needs an evaluation set drawn from real tasks, including ordinary success, ambiguous requests, missing data, tool failure, injection attempts, permission boundaries, and cost outliers. Record final correctness, tool sequence, latency, token use, retries, and external receipts. A trace is useful for diagnosis, while a repeatable evaluator shows whether a prompt, model, package, or middleware change improved the system. Provider calls should be stubbed for deterministic unit tests and exercised directly in a smaller integration suite.
LangChain.js is MIT licensed and has an active release stream, so related packages should be pinned and upgraded together with migration notes in hand. Use it when its agent loop, integrations, and middleware remove repeated infrastructure you would otherwise maintain. For Fine Structure, that is relevant where agents coordinate real business work, but the product must still own approvals, permissions, receipts, and customer-facing truth. A direct provider SDK is clearer when one request is all the feature needs.
A SENSIBLE FIRST HOUR
Start small enough to learn the repo
- Install current langchain, @langchain/core, Zod, and one official provider package, then pin all related package versions together.
- Define one read-only tool with a narrow Zod schema, a timeout, a stable error result, and fixture-backed tests independent of the model.
- Create an agent with an explicit model and system prompt, invoke three representative tasks, and record messages, tool calls, latency, token use, and final outcomes.
- Add structured output or middleware only for a measured need, then run an evaluation set with failure, injection, permission, and cost cases before connecting write-capable tools.
SOURCE LEDGER
What this review is built on
We use the project repository and first-party documentation. Access, licenses and project direction can change, so recheck the linked source before making a production decision.