LangChain / Semantic Kernel
Frameworks for composing LLM apps β chains and LCEL, prompt templates, memory, plugins/tools, and the move toward stateful agent graphs (LangGraph).
Orchestration frameworks like LangChain and Semantic Kernel provide reusable building blocks β prompt templates, models, output parsers, memory, retrievers, and tools β so you compose LLM applications instead of hand-wiring API calls. LangChain pipes components with LCEL into uniform Runnables; Semantic Kernel registers plugins on a Kernel with automatic function calling. Both increasingly favor stateful agent graphs (LangGraph) for complex, multi-step workflows.
Building an LLM app from raw API calls means hand-wiring prompts, history, retrieval, tool calls, parsing, retries, and streaming yourself. Orchestration frameworks (LangChain, LlamaIndex, Semantic Kernel) provide reusable, composable building blocks so you assemble apps from parts instead of plumbing β with consistent patterns for models, memory, and tools.
The core pieces are prompt templates, models, output parsers, memory, retrievers, and tools. LangChain composes them with LCEL β literally piping components together (prompt | model | parser) into a single Runnable that supports invoke, stream, batch, and async uniformly. Swap any component without rewriting the flow.
Memory persists conversation state across turns so the app 'remembers' context. Tools/functions let the model take actions; Semantic Kernel registers them as plugins ([KernelFunction]) and uses automatic function calling (FunctionChoiceBehavior.Auto) to invoke them, while LangChain wires tool-calling agents. This is how chains graduate into agents.
Simple linear chains aren't enough for stateful, branching, multi-step agent workflows, so the ecosystem moved toward graph runtimes β LangGraph for LangChain, and agent frameworks in Semantic Kernel β that model an app as nodes and edges with explicit state, loops, and human-in-the-loop checkpoints. These give the control and observability production agents need.
Key Concepts
Libraries (LangChain, Semantic Kernel, LlamaIndex) that compose LLM apps from reusable building blocks.
Composing components into a pipeline; LangChain pipes them (prompt | model | parser) into one Runnable.
A reusable, parameterized prompt with roles and placeholders (system/human, {input}, chat_history).
Persisted conversation state injected into the prompt so the app remembers prior turns.
Functions the model can call; Semantic Kernel marks them [KernelFunction] and auto-invokes them.
A stateful node/edge runtime for branching, looping, multi-step agent workflows with checkpoints.
1# --- LangChain (Python) β compose with LCEL: prompt | model | parser ---2from langchain_core.prompts import ChatPromptTemplate3from langchain_core.output_parsers import StrOutputParser4from langchain_openai import ChatOpenAI56prompt = ChatPromptTemplate.from_messages([7 ("system", "You translate English to French."),8 ("human", "{text}"),9])10chain = prompt | ChatOpenAI(model="gpt-4o") | StrOutputParser() # one Runnable11chain.invoke({"text": "good morning"}) # also .stream() / .batch() / async1213# Tool-using agent (LangGraph powers stateful agents under the hood):14from langchain.agents import create_tool_calling_agent, AgentExecutor15agent = create_tool_calling_agent(llm, [search_tool], agent_prompt)16AgentExecutor(agent=agent, tools=[search_tool]).invoke({"input": "..."})1718// --- Semantic Kernel (C#/.NET) β Kernel + plugins + auto function calling ---19var kernel = Kernel.CreateBuilder()20 .AddOpenAIChatCompletion("gpt-4o", apiKey)21 .Build();22kernel.Plugins.AddFromObject(new WeatherPlugin()); // [KernelFunction]-tagged methods2324OpenAIPromptExecutionSettings settings = new()25 { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() }; // auto-invoke tools26var answer = await kernel.InvokePromptAsync(27 "What should I wear in Paris today?", new(settings));
Orchestration frameworks are how most production LLM apps are built β they standardize prompts, memory, retrieval, tools, and streaming, and power the agent runtimes (LangGraph, SK agents) behind modern AI products. Knowing their building blocks, the LCEL/plugin model, and when abstraction helps vs hurts is core to practical AI engineering and a common interview topic.
Common Pitfalls
1Swapping Models and Adding RAG Without a Rewrite
A team prototyped a chatbot with direct OpenAI API calls. Now they need to add conversation memory, retrieval over docs, and the ability to switch model providers β and the hand-rolled code is tangled and hard to extend.
Bespoke API plumbing couples the app to one provider and one flow. Adding memory, retrieval, and parsing means rewriting glue code, and changing models touches everything β slow and error-prone.
Adopt an orchestration framework: express the flow as composed components (prompt template β retriever β model β output parser) with a memory module. Swapping providers is a one-line model change, adding RAG is inserting a retriever, and streaming/batching come for free from the framework's runnable interface.
Takeaway: Orchestration frameworks turn LLM apps into composable pipelines, so memory, retrieval, parsing, and model choice become swappable parts β far more maintainable than hand-wired API calls.
2When the Framework Becomes the Problem
A team wrapped everything in deep framework abstractions. Debugging a wrong answer meant digging through layers of chains and callbacks, and a simple custom step fought the framework's conventions.
Over-relying on heavy abstractions hid what was actually sent to the model, made control flow opaque, and added indirection that outweighed the benefit for a relatively simple app β a common critique of early LangChain usage.
Use the framework deliberately: lean on it for genuinely reusable pieces (prompt templates, retrievers, memory, agent loops), keep the prompts and control flow inspectable, and drop to plain API calls or a graph runtime (LangGraph) where explicit state and debuggability matter more than abstraction.
Takeaway: Frameworks help when they remove real plumbing, not when they hide what's happening. Keep prompts and flow observable, and choose the level of abstraction that fits the app's complexity.
Join the discussion
Comments
Loading comments...
Cookie preferences
We use essential cookies for sign-in and preferences. With your permission, we also use basic analytics to improve lessons.