Skip to content
AI/ML

Generative AI with LangChain: What I'd Ship Before Agents

Generative AI with LangChain connects models, retrieval and tools; here's how I'd choose the smallest useful workflow and test it before production.

Topic
AI/ML
Reading time
6 min
Length
1,387 words
Published
Nov 4, 2026
01:42 pm IST
In this article
  1. Where Transformers, Hugging Face and LangChain fit
  2. What LangChain v1 changes for application code
  3. Building a small LangChain workflow before adding agents
  4. Making LangChain RAG answer from the right documents
  5. What LangChain structured output and agents do not solve
  6. Choosing Hugging Face without assuming local means finished

Generative AI with LangChain brings model calls, document retrieval, structured responses and tools into one application workflow. The concrete API change covered in the source guide is LangChain v1's use of create_agent as the standard agent entry point, with older APIs moved into langchain-classic. My interest is less in building an agent immediately and more in deciding which of those building blocks a production feature actually needs.

I work on AI-assisted editorial workflows, so I read this through a fairly specific lens: can I give an editor useful output, identify where it came from, and keep control over what happens next? I'd start with a constrained chain or retrieval workflow. I'd add an agent only when choosing between tools is genuinely part of the job.

The source guide covers Transformers, Hugging Face and LangChain together. Here is how I'd turn that material into implementation decisions rather than a shopping list of AI components.

Where Transformers, Hugging Face and LangChain fit

I separate these into three layers. The Transformer is the model architecture. Hugging Face supplies a model hub and the transformers library for loading and running models. LangChain supplies application building blocks around models, including messages, prompts, tools and retrieval workflows. I wouldn't treat any one of them as a replacement for the others.

For a text-generation model, the source describes tokenization, embeddings, attention, feed-forward processing and next-token prediction. Attention lets a token gather information from other tokens. For decoder-only chat models, causal masking restricts that attention to earlier tokens. That distinction matters when reading a simplified explanation that says every word can look at every other word.

I don't need to implement attention to ship an editorial assistant. I do need the right mental model: generated text is not a database lookup. Lowering temperature changes how adventurous token selection is; I would not treat it as a factuality guarantee. For a factual answer, I'd inspect the evidence supplied to the model and the answer it produced.

The source also separates encoder models, useful for tasks such as embeddings and classification, from decoder models used for generation. I'd preserve that distinction in my design. Choosing a chat model would not automatically settle my choice of embedding model.

What LangChain v1 changes for application code

The guide says LangChain and LangGraph reached version 1.0 on October 22, 2025. It identifies create_agent, middleware for controlling the agent loop, and the separate langchain-classic package as relevant changes. For Python, it lists a minimum requirement of Python 3.10.

I'd use those details mainly as a warning against mixing tutorial generations. Before copying an example, I'd check its imports and package assumptions. An older chain example and a current agent example may be teaching different interfaces, even when both are described simply as “LangChain.”

I also wouldn't confuse a standard model interface with interchangeable behavior. The source shows provider switching through init_chat_model. I'd still rerun my evaluation cases after switching providers. Keeping the calling code similar is useful; deciding whether the new answers are acceptable remains my responsibility.

Building a small LangChain workflow before adding agents

I'd implement the first feature as a narrow, inspectable path. In a newsroom CMS, I'd rather test a draft-summary operation with an explicit review step than begin with an assistant allowed to choose actions across the publishing workflow.

  1. Define the output contract. I'd write down whether the feature returns prose, extracted fields or an answer with supporting passages. I'd also define what the interface shows when the model cannot produce a usable result.
  2. Test the plumbing independently. I'd use a fake model to check prompt variables and output handling before spending time judging generated answers.
  3. Introduce a real model deliberately. I'd keep API keys in environment variables, as the source recommends, and evaluate representative inputs rather than just the example prompt.
  4. Add retrieval only for a data dependency. If the answer depends on our documents, I'd test retrieval separately from generation.
  5. Add tools only for explicit actions. I'd keep permissions and approval decisions in application code, not infer authorization from the model's request.

The following example adapts the source's offline LCEL pattern to an editorial prompt. It needs langchain-core, but no API key or model download. The reply is deliberately fixed. I'd use this to check composition, not to claim that summarization quality has been tested.

from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_core.language_models.fake_chat_models import GenericFakeChatModel
from langchain_core.messages import AIMessage

model = GenericFakeChatModel(
    messages=iter([
        AIMessage(content="The draft describes a revised editorial review process.")
    ])
)

prompt = ChatPromptTemplate.from_messages([
    ("system", "Summarize the supplied draft in one sentence. Do not add facts."),
    ("human", "Draft: {draft}"),
])

chain = prompt | model | StrOutputParser()

result = chain.invoke({
    "draft": "The editorial team is revising its review process."
})
print(result)

The pipe connects the prompt, model and string parser. The source reports testing its offline examples with LangChain 1.4.8 and langchain-core 1.7.4; I haven't independently run this adaptation. Before using it in a project, I'd verify it against that project's installed dependencies.

Making LangChain RAG answer from the right documents

The source describes retrieval-augmented generation as two stages: indexing documents, then retrieving relevant chunks for each question and putting them into the generation prompt. Its examples include document loading, splitting, embeddings and vector storage. I'd use that separation to structure my tests, too.

First, I'd inspect the retrieved passages without asking the model to answer. For each representative question, I'd check whether the needed information appeared at all. If retrieval missed it, I'd investigate the documents and chunk boundaries before rewriting the answer prompt.

Second, I'd test missing and conflicting evidence. My acceptance cases would include a question that the collection cannot answer and two documents that disagree. I'd want the application to make uncertainty visible rather than encourage a polished guess.

For intelligent search over newsroom material, I'd also check document eligibility before generation. My design would keep draft visibility and editorial access rules outside the model's judgment. I'd ask reviewers to inspect both the answer and the passages supplied to it, because those are different parts of the workflow.

The source suggests chunks of 500 to 1,000 characters as an example. I'd treat that as a starting experiment, not a production default. My choice would depend on whether each retrieved chunk preserved enough context to support the intended answer.

What LangChain structured output and agents do not solve

I like structured output for application boundaries. The guide uses a Pydantic schema and with_structured_output to request typed fields, and reports an offline parser test rejecting an invalid value. That's a useful distinction from hoping free-form text happens to resemble JSON.

I would still separate shape validation from factual validation. A field can have the expected type while containing an answer I would reject. For extraction, I'd compare fields against the supplied document and define what should happen when a value is missing, rather than encouraging the model to fill every field.

Tools deserve the same caution. In the source's model, the LLM requests a tool call; the program or agent loop executes the function and returns its result. I'd make that boundary visible in the design. A requested action would still pass through my authorization, argument checks and, where appropriate, human approval.

For a workflow whose steps are already known, I'd skip the agent loop initially. For a single model call, I'd also consider whether a direct provider integration is clearer. My reason to choose LangChain would be useful composition or shared interfaces, not the assumption that every AI feature needs a framework.

Choosing Hugging Face without assuming local means finished

The source shows Hugging Face pipelines for classification and generation, including a small open chat model. It also describes the quality trade-off against frontier API models. I'd evaluate the exact task before deciding that local execution is the right compromise.

For sensitive material, I'd inspect the complete data path before making a privacy claim. I'd also follow the source's warning about downloaded model code: avoid trust_remote_code=True unless the repository has been checked, and prefer the safetensors format.

My next step would be a small evaluation set: supported answers, unsupported questions, malformed output and tool requests that should be denied. I'd build the shortest workflow that passes those checks. Only then would I decide whether giving the model more freedom is worth the extra behavior I'd have to review.

Deepak Kumar

Written by

Deepak Kumar

Sr Software Engineer at India Today Group | Aaj Tak · MERN Stack · Generative AI

I build RAG systems in production, on MongoDB Atlas Vector Search over a working editorial archive. I write here about what those systems actually do once real traffic hits them. Hiring an LLM engineer in India? Here is how I work.

More on ByteMuni

ByteMuni is a developer publication: tutorials and source-checked tech news, published daily.

Read more on ByteMuni →
Message me