Library vs framework
Also: 函式庫 · library · framework · 框架 · 套件庫 · 第三方庫
A library is something you call; a framework is something that calls you.
When you will meet it
While choosing AI tools you keep meeting the argument between 'use a framework like LangChain' and 'call the API directly'. Without the distinction you cannot judge how much control a tool actually leaves you — and control is the dividing line between being able to trace a failure and not.
An analogy
A library is a hardware store: you buy a screwdriver and decide when and where to use it. A framework is an assembly line: it owns the process and you only place parts where it tells you. The line is faster, but when it jams you have very little room to reach in.
Minimal example
函式庫(你主導):
import requests
r = requests.post(url, json=payload) # 你決定什麼時候發、發什麼
text = r.json()["choices"][0]["message"]["content"]
# 之後每一步也都是你寫的
框架(它主導):
agent = create_react_agent(llm, tools, prompt)
agent.invoke({"messages": [...]}) # 之後的迴圈由框架跑
# 它自己決定何時呼叫模型、何時呼叫工具、何時停The test is 'who owns the loop'. If your own code holds a while loop that calls the model, you are using libraries. If you call invoke once and something keeps spinning inside, you are in a framework. LangChain and LlamaIndex are the latter; client packages like requests or openai are the former.
What people get wrong
- Assuming a framework is 'more advanced' and therefore right for beginners. The opposite: a framework hides detail, so when it fails you cannot even see which layer broke. Get the same thing working once with libraries and you will know exactly what the framework was doing for you.
- Using 'framework' and an agent's 'harness' as the same word. A framework (like LangChain) is a parts box for building a harness; the harness is the running thing you built, which assembles context and executes tools.
Related terms
Next
- Complete LangChain Tutorial 2026: Building Enterprise-Grade LLM Applications from Scratch53 min
- LangChain vs LlamaIndex: A Selection Guide and Hands-On Primer9 min