chains · prompts · agents
Prompts
The foundation of LLM interaction. Prompts are templates, instructions, and examples that guide the model’s output. LangChain elevates prompts using PromptTemplates with dynamic variables, few-shot examples, and output parsers.
prompt = PromptTemplate.from_template(
“Explain {concept} like I’m 10 years old.”
)
→ formatted: “Explain LangChain like I’m 10 years old.”
Chains
Sequences of calls — combine prompts, LLMs, and utilities into reproducible pipelines. Chains enable multi-step workflows: retrieve data, transform, call LLM, parse output. LCEL (LangChain Expression Language) makes chains declarative and lightning fast.
chain = prompt | llm | output_parser
response = chain.invoke({“concept”: “chain”})
# output: “A chain links multiple AI actions together…”
Agents
Autonomous decision-makers. Agents use an LLM to decide which actions to take, which tools to invoke (search, calculator, APIs), and in what order. Unlike fixed chains, agents adapt dynamically based on intermediate results — true reasoning engines.
agent = create_react_agent(llm, tools, prompt)
agent.invoke({“input”: “What’s 24*7 and weather in Tokyo?”})
→ uses calculator + web search tools iteratively.
⚡ How they work together: The LangChain synergy
While each concept is powerful individually, their true potential emerges in combination. Prompts define how we talk to AI, chains create reliable workflows, and agents bring autonomous intelligence. LangChain unifies them into a coherent ecosystem.
🔍 Key differences
- Prompts → input design / control
- Chains → fixed sequence / reliability
- Agents → dynamic decisions / flexibility
🧠 Real-world flow example
➤ Agent decides to search the web → calls a Chain that formats search queries (Prompt) → gets results → agent reasons: needs summarization → triggers another Chain (summarize with prompt) → final answer.
Unified syntax to compose chains and agents: prompt | llm | output_parser. Stream, batch, async out-of-the-box.
Agent prompts include system messages, tool descriptions, and few-shot examples — enabling complex reasoning like ReAct, Plan-and-Execute.
Agents use custom tools (APIs, DB, code exec). Chains can be wrapped as tools, and prompts evolve with partial variables, few-shot selectors.
“LangChain transforms LLMs from stateless predictors into composable, context-aware systems — through prompts, chains, and agents.”

