I am a beginner in large language models, gradually learning and understanding them. But in the process, I've encountered quite a few confusions. Here I adopt the Feynman learning method, hoping to explain some basic concepts, development history, technical solutions, and engineering practices of LLMs in plain language, to consolidate knowledge and fill in gaps. The following is a comprehensive overview.
When a user inputs: [I drank a cup of ___ before going out this morning], the model, based on the language patterns learned during training, calculates the “reasonable probability of what comes next” for thousands of fragments in its vocabulary. The highest probability candidates include “soy milk” and “cow milk” – expressions that align with common sense. If it selects the token corresponding to “soy,” the model then starts thinking again about what should follow [I drank a cup of soy], and the next output becomes [I drank a cup of soy milk], repeating this process until termination.
When a user inputs something like [I drank before going out this morning], during actual generation the model doesn't literally pick from tens of thousands of words. On one hand, low-probability words are often nonsensical and would make the content logically messy; on the other hand, considering the full vocabulary increases computational cost. So the model first uses rules to cut out extremely low-probability options, narrowing the candidate pool. This step is called candidate pool filtering, and the two most common rules are Top-K and Top-P algorithms.
After filtering to a reasonable candidate pool, the model randomly samples within this range according to probability to select the final next word. Temperature is used to adjust the randomness of this sampling:
That's how LLMs work. Through the simple mechanism of predicting the next word, the entire edifice is built.
Key technical details:
Single-turn interaction is the most fundamental way LLMs operate, and it's the foundation for all subsequent complex interaction capabilities.
Many people think of LLMs as “Q&A” conversation machines, but from a logical standpoint, they only do one thing from start to finish: given some starting text, continue writing forward. All user input – questions, instructions, background information – is collectively called a prompt, essentially handing the model half a manuscript to complete. The complete result generated word by word based on this content is called the completion. The Q&A, copywriting, and code generation we see daily are essentially different forms of “continuation.”
This single-turn mode is inherently stateless; each interaction is completely independent. The model only processes the current input and won't actively remember information from the previous round of conversation. It's like handing it a fresh piece of scratch paper each time – it writes, clears it, and absolutely won't remember what was on the previous sheet.
Don't directly conflate this with mature complex products like [Doubao, CodeX, Claude Code]. At its core, the basic operation mode is stateless single-turn interaction. It's only through various engineering methods that people get the illusion of a stateful, multi-turn conversational Q&A system. Remember: LLMs are fundamentally not Q&A systems – they're one-shot continuation systems.
This also brings the most direct limitation: inability to handle multi-turn context. If you split the conversation into two rounds – first telling the model your name and age, then separately asking “How old am I?” – the model simply can't answer. Continuous conversation easily leads to “amnesia” and logical disconnection [we'll discuss solutions later]. In the single-turn interaction stage, the primary means of improving output quality is writing detailed prompts – refining the wording, structure, and instruction format to guide the model toward more accurate, better-aligned results.
Key technical details:
Since LLMs are “memoryless” continuation machines, how do we get that smooth back-and-forth, even heart-to-heart chatting feeling in [Doubao]?
Actually, this is entirely an engineering “trick.” LLMs themselves don't remember things [Note: there are some solutions, which we'll discuss at an appropriate time later], but the engineers behind chat products are clever: when you're on the third round of conversation with the model, the software secretly copies everything you've said in the first two rounds, along with the model's responses, pastes them like a sticky note in front of your new question, then packages it all into a long text and stuffs it into the model. Technically, this bundled “history ledger” is called context.
So, the LLM can answer your follow-up questions not because it “remembers,” but because each time you press send, you're handing over the entire history along with the new question, letting it do a larger-scale “single-turn continuation.” This engineering approach of trading space for time perfectly fakes human “memory,” but at a steep cost – every additional sentence you say causes the text volume for transmission and recalculation to avalanche upward. Not only does it get more expensive the more you chat, but it quickly hits the physical ceiling of the LLM's vision.
Now, you sharp-minded folks surely see several serious problems:
Key technical details:
A Doubao that can only chat has significant limitations. We can't keep copy-pasting code text into [Doubao] and then copy-pasting the results back into our editor. That's way too tedious!! Is there a way to let the LLM directly modify files itself? But here at least a few problems exist:
Function Calling emerged, but always remember: LLMs will only ever do one thing – “continue writing text.” They absolutely have no ability to open a web page or execute a single line of code on their own.
So-called function execution is essentially a “secret handshake” between the LLM and backend engineering code. The LLM is responsible for making decisions (calling out the secret code), while the backend program handles the physical work (executing code based on the secret code).
get_weather that can query city weather. If you want to use it, you must output a JSON-formatted result like: {\"name\": \"get_weather\", \"arguments\": {\"city\": \"Hangzhou\"}}.”{\"name\": \"get_weather\", \"arguments\": {\"city\": \"Hangzhou\"}}You smartly realize there might be several problems here:
We'll discuss strategies for solving these problems later.
Key timeline and technologies:
LLMs only ever do one thing – “continue writing text” – and they do it based on probability. This leads them to frequently make things up in domains they don't understand. Moreover, because of the context mechanism, once they start going wrong, subsequent content builds on previous content, leading to increasingly absurd errors. This is hallucination!!
Typical hallucinations:
One reason for hallucinations is insufficient training data in the relevant domain, so when continuing text, there's no significantly high probability for selecting the next appropriate word. But it seems hard to solve:
This makes LLMs difficult to use in certain scenarios:
Key technologies:
An LLM is a “continuation machine” without memory, faking memory entirely by pasting history records into context.
Suppose you're building a historical archive decryption assistant. You have various electronic historical materials, and you want the LLM to answer questions about historical materials accurately and comprehensively, detailing various aspects of a small battle.
The LLM's context can't fit all historical materials. Even if you could barely stuff in a copy of “WWII Declassified Archives,” to answer a user's 100-character question, you'd need to concatenate a million-character context to send to the LLM for inference and next-word prediction – cost-prohibitive.
Enter RAG (Retrieval-Augmented Generation). In a nutshell: it solves problems like an open-book exam, rather than memorizing the entire textbook.
When someone asks: “On the eve of the Normandy landings in 1944, how did the Allies use false intelligence to deceive the Germans?” Here's how the RAG system “cheats” behind the scenes:
The LLM doesn't need to memorize the entire archive. It just needs to take the open-book exam with the “precise cheat sheets” stuffed into its context each time.
To solve these open-book exam failures, the industry has evolved more complex patch technologies.
Key technical details:
LLMs have long been criticized as “fast talkers lacking deep thinking.” In previous chapters, we saw that LLM content generation is like a reflex – seeing the previous Token, it spits out the next Token based on probability, without pause, all in one go.
This “intuitive” continuation works great for writing essays and churning out papers, but frequently fails when facing complex math problems, logical reasoning, or writing large-scale engineering code. When humans tackle advanced math, they still need scratch paper to scribble and calculate for a while. Yet LLMs are expected to spit out the final answer within milliseconds – this clearly violates the objective laws of complex tasks.
To teach LLMs to “think before they act” like humans, engineering and algorithmic techniques for letting LLMs “draft” behind the scenes have evolved.
When a user inputs a tricky problem: “Xiaoming has 3 apples. Xiaohong has twice as many apples as Xiaoming. Xiaoming eats 1 apple. Xiaohong gives Xiaoming 4 apples. Who has more apples now? How many more?”
A traditional “intuitive” LLM might, due to similar number combinations in its training data, blurt out a wrong conclusion – because LLMs are continuation machines!!
But in the new reasoning era (represented by Reasoning models), before presenting the final answer to the user, the LLM conducts a lengthy self-continuation on its “mental scratch paper” behind the scenes:
Model's internal chain of thought:
1. First clarify initial state: Xiaoming = 3, Xiaohong = 3 * 2 = 6.2. Process the first change: Xiaoming eats 1, Xiaoming = 3 - 1 = 2.3. Process the second change: Xiaohong gives Xiaoming 4. Wait, Xiaohong gives away 4, so Xiaohong decreases! Xiaohong = 6 - 4 = 2; Xiaoming receives 4, Xiaoming = 2 + 4 = 6.4. Re-compare results: Now Xiaoming has 6, Xiaohong has 2. Xiaoming has more.5. Calculate the difference: 6 - 2 = 4. Check passed, ready to output.
Finally, the user sees the concise and elegant final answer on screen: “Xiaoming has more apples now, 4 more than Xiaohong.”
The LLM hasn't changed its “text continuation” essence – it's just turned part of its continuation into “inner thoughts” visible only to itself (Thought). By stretching the generation time and trading more Tokens for logical accuracy, this technique of making the model write out its thinking process step by step is called Chain of Thought (CoT).
You smartly realize: if the LLM makes a mistake in the second step of “drafting,” won't it go completely off the rails afterward?
In the latest post-training techniques, LLMs have been trained with a “self-correction” ability. When they discover logical contradictions in their chain of thought (for example, realizing the calculated total number of apples doesn't add up), they actively hit the mental brakes: “No, I forgot to subtract the apples Xiaohong gave away from Xiaohong's total. Let me recalculate.”
This mechanism of continuously evaluating the current path during generation, and backtracking to retry when something's wrong, is like pruning and searching on a thought tree. The model no longer goes down one path to the bitter end but iterates repeatedly on virtual scratch paper until it finds the reasoning path with the highest probability and most self-consistent logic.
Key technical details:
Because we keep saying LLMs are “continuation machines,” they sound weak. You ask a question, it responds with a secret code, the backend finishes the work, and it's done. This “whip once, turn once” mode obviously isn't smart enough.
But if you've actually used Claude Code, OpenAI Codex, or Cursor, you must be amazed: how can they sit there for hours continuously modifying code, compiling, debugging, and re-modifying until bugs are completely fixed, just like a real programmer?
They haven't replaced the underlying LLM, nor have they applied any magic. This ability to sustain endurance and autonomously solve complex engineering problems is the crystallization of Agent technology.
If we compare an LLM to a “wise person” who has retired from the world but knows all martial arts secrets under heaven. It understands all programming languages, knows all algorithms, but has a fatal weakness – it has no physical body and suffers from intermittent amnesia. It can't touch a computer, and as soon as it speaks next (one interaction ends), it completely forgets what was just discussed.
To make this “wise person” write code for us continuously for hours, engineering must build it an exoskeleton armor consisting of four core components:
npm run dev or pytest.Tools like Claude Code can work continuously for hours because the core mechanism is trapping the LLM in a carefully designed “Think → Act → Observe → Think again” infinite loop (technically called the ReAct pattern).
Let's break it down in plain language. When you type claude-code fix the login bug in the terminal, here's what's actually happening behind the scenes in this crazy “involution loop” over the next few hours:
list_dir tool, I should call it.”{\"tool\": \"list_dir\", \"path\": \"./src\"}.ls ./src on the computer, and forcefully pastes the result into the LLM's context: “Reporting to the sage, the directory contains auth.py and main.py.”auth.py. I need to use read_file to see the content.”{\"tool\": \"read_file\", \"path\": \"./src/auth.py\"}.run_command(cmd=\"pytest\") to run tests. The terminal returns a massive red Error: NullPointerException.user_session. No worries, I'll use the modify_file tool to fix it.”
This is the truth behind its ability to code continuously for hours: It doesn't write code correctly all at once. Like a human programmer, it writes a few lines, runs it, encounters errors, curses, looks at the error message, changes a few more lines, and re-runs. As long as you don't hit Ctrl + C to forcefully terminate, the LLM will tirelessly keep self-correcting in this infinite loop driven by the code shell.
You cleverly recall what we discussed in Chapter 3 – the “avalanche-like explosion” of context and costs.
Letting Claude Code run for hours means this “Think-Act-Observe” loop cycles hundreds or thousands of times. Every error message, every piece of code read, keeps getting pasted into the LLM's “history ledger (Context).”
To solve this, top-tier code Agents like Claude Code invest heavily in “context management.” They meticulously manage this ledger. We'll discuss details later.
Key technical details:
We've been saying that LLMs are essentially “one-shot text continuation systems.” But in practical applications, they seem very obedient – they don't really resist or curse at people. According to previous theories about Top-K, Top-P, temperature control, etc., this doesn't seem to explain why LLMs appear to be tamed, becoming docile workhorses, working 996 – why???
Behind this lies the most crucial “taming” of LLMs. The raw model freshly crawled from massive internet text is actually a “wild and untamable” puzzle – it knows a lot but doesn't obey at all. The corpus from forums like Tieba and Reddit is full of sarcasm, mockery, and aggressive language. Without control, an LLM might, through its probability-based Top mechanism, start spewing garbage.
To transform a machine that only blindly continues text into the empathetic, format-rigorous AI assistant we see in [Doubao], the LLM must go through three stages of evolution. We can vividly use the metaphor of “training a wild monkey that has read all the Buddhist scriptures in the library into a living Buddha sitting in the main hall who answers all questions”:
[Input: Tell me what giant pandas eat?] -> [Output: Giant pandas mainly eat bamboo.]. These standard cheat sheets are fed to the model for retraining.If you often use Grok or Gemini, you'll notice that multiple options often pop up simultaneously, asking you to choose which is better – this is also a form of RLHF.
Earlier we mentioned that LLM knowledge is often stuck at the year it was trained (e.g., 2024), and it can't “learn online.” You smartly think: since fine-tuning (SFT) can feed it new data, why not just stuff new private standard manuals or 2026 news directly into fine-tuning and let it learn again – wouldn't that solve hallucination and timeliness issues?
This is very intuitive from an engineering standpoint, but in practice, it's a huge disaster.
An LLM's knowledge is stored in the form of digital weights, distributed uniformly and vaguely across billions or tens of billions of parameters, like salt dissolved in water. This brings two fatal technical limitations:
Industry consensus:
- Use Fine-tuning to change the model's behavior, tone, obedience, or teach it specific output formats. - Use RAG (Retrieval-Augmented Generation, i.e., open-book exam) to provide the model with the latest, most accurate hard facts and private data that cannot tolerate any lossy compression.
Treating fine-tuning as a hard drive to store new knowledge is like expecting a college student to memorize a medical dictionary and then immediately perform surgery – both inefficient and dangerous. This is also why, in current engineering practice, RAG and Agent have become mainstream for deployment, while fine-tuning has stepped back, specifically used for “alignment” and “pruning” of the model's various capabilities.
Key technical details:
We've been repeatedly emphasizing: LLMs are “text continuation” machines. All their superpowers are built on giving them a piece of text and having them spit out the next word based on probability.
But when you open the latest [Doubao] and casually take a photo of a dense code screen or a complex circuit board logic diagram, throw it at the model and ask: “Which line of code in here is wrong?” – it can instantly pinpoint among a sea of pixels and point out the error in text.
Don't LLMs only recognize text? How can they recognize images, even audio and video?
Behind this, the LLM hasn't changed its brain. Rather, engineers have installed a “translator” in front of the LLM.
Since LLMs only eat Tokens, we force images to also masquerade as Tokens.
When you upload a screenshot of code in the chat and ask “how to fix it,” the entire backend process is a “sleight of hand”:
[System Prompt] + [Image Tile Token 1] + [Image Tile Token 2] +...+ [Image Tile Token 100] + [User Question: What's in this image?]To the LLM, it doesn't see any colorful picture. In its “eyes,” those 100 image tiles are 100 “special words it has never seen before.” But because during massive pre-training, it has countless times seen the pattern that “[special characters with dark circles] often appear next to the word [giant panda].”
So it fires up its only trick – text continuation – and naturally spits out: “The image shows a giant panda eating bamboo.”
You immediately think: Since LLMs can “see” images by adding a “visual translator,” conversely, can we make them directly control a real-world robot or robotic arm through “text continuation”?
The answer is: absolutely yes, and this is exactly the field of Embodied AI.
Traditional robot control requires complex mathematical formulas to calculate joint angles, torque, and Cartesian coordinates for robotic arms. But what if we treat the robotic arm's actions as a kind of “language”?
In cutting-edge embodied AI engineering practice, engineers have done something very radical: they've encoded various robot actions – like “gripper open,” “gripper close,” “move left 5 cm” – into special codes in the vocabulary (usually called Action Tokens).
When you input to an LLM connected to a robotic arm: [Help me pick up the red block on the table.]
<ROBOT_MOVE_X_0.05> <ROBOT_MOVE_Y_-0.02> <ROBOT_GRIPPER_CLOSE>.This transforms the originally tedious mechanical control problem into a pure, cross-modal “advanced text continuation” game.
But there's no free lunch. This approach of forcefully turning everything into Tokens and stuffing them into the LLM brings extremely heavy engineering costs:
- in the image, but because that small tile is too inconspicuous, it gets ignored by the LLM during inference after translation, leading to calculation results that are off by a mile.To solve these visual and physical control failures, the industry is currently moving comprehensively from early “assembled multimodal (independent training then forced concatenation)” toward “native multimodal (from day one of pre-training, let the model simultaneously eat text, images, and action data).”
Key technical details:
In previous chapters, we've learned how to make LLMs work like workhorses performing various simple tasks.
But if you're asked to write an enterprise-level system, you'll find that just writing “glue code” to stick these parts together can exhaust you. That's when the LLM engineering world evolved specialized “assembly pipeline frameworks.”
The earliest behemoth to appear was LangChain. Its core idea was to encapsulate common patterns in LLM application development into standard “Lego bricks.” It wrapped APIs from different vendors into unified shells and turned RAG steps into an automated conveyor belt. In the early days, it did allow beginners to assemble a chatbot in just a few lines of code.
But when people brought LangChain into serious production environments, the nightmare began:
Then PydanticAI emerged. It borrowed design philosophies from modern backend development (like FastAPI) and proposed two weapons against the uncontrollability of LLMs:
An LLM is a stateless text continuation machine. We discussed earlier that multi-turn dialogue relies on the backend frantically stacking “history ledgers.” But if a user chats with AI for three days straight, or logs in again next month, this ledger will not only burst the LLM's context but also drive compute costs to bankruptcy.
To give Agents long-term memory similar to humans, engineering has installed a layered “permanent backpack”:
More advanced memory is the entity relationship graph. As AI communicates with you, it secretly draws a network about you in its backpack: [User] -- likes --> [Black Coffee], [User] -- profession --> [Software Development].
This memory is no longer fragmented text snippets but structured state, making the LLM feel like an old friend every time it interacts with you.
We've given LLMs “hands and feet” (Tool Call), letting them check weather and modify files. But imagine, in a large enterprise, there are thousands of internal microservice APIs (check finances, approve leave requests, search employees, modify permissions…).
If we cram all the “instruction manuals” for these thousands of tools into the LLM before every conversation, two things happen: First, the context explodes immediately, getting more expensive the more you chat. Second, the LLM, facing thousands of choices, becomes deeply confused and starts randomly calling tools.
Thus, the Dynamic Skills system emerged. It turns tool usage into a “two-stage retrieval”:
When we've used PydanticAI to set the standards, Memory to give it memory, and Skills to give it unlimited capabilities, this Agent (single workhorse) becomes theoretically omnipotent.
Now we have an extremely ambitious idea: Can I create an omniscient and omnipotent “Super Single Agent”? I'll stuff all the company's rules and regulations, customer service scripts, Python programming standards, and financial reimbursement processes into its prompt, letting it handle all the company's dirty work single-handedly.
In engineering practice, if you actually do this, the LLM will slap you awake with reality. As you cram more and more prompts and hundreds of tools into this single Agent, it quickly falls into “deep confusion” – not only does response speed slow down, but it also frequently suffers from identity “schizophrenia.”
To solve this “mediocrity caused by omnicompetence,” there are two complete decouplings in the LLM world. One happens inside the LLM (the physical structure evolution of the model), and the other happens in our business code (the sociological separation at the application layer). These are often confused, but for beginners, distinguishing them is crucial.
First, we must peel back the physical shell of LLMs and see how their underlying hardware and compute power are squeezed out. In today's market, the underlying structure of LLMs mainly falls into two camps.
Early classic models (like early Llama series, or various small standalone models with tens of billions of parameters) are almost all “dense models.”
To break through the physical limits of dense models, today's hottest top-tier LLMs (like the famous DeepSeek-V4 or GPT-5 series) have almost all switched to MoE architecture.
After hearing about the hardware situation, you might think: “Since MoE models like DeepSeek are already this smart and cheap, if I write all my company's business logic into the prompt and let it handle everything alone, it should work, right?”
Sorry, it still fails. Because the underlying MoE can only solve “whether text continuation is fast and compute-efficient,” it cannot solve the logical chaos that occurs when humans write complex business systems.
Suppose you want to build a “fully automated R&D expense reimbursement audit assistant.” If you make it a single Agent, you'd have to write tens of thousands of characters in its System Prompt:
"You need to be both a warm and friendly customer service representative guiding users to upload invoices, AND a strict rigorous code auditor checking users' code for security vulnerabilities, AND a stingy accountant checking the company's MySQL database to see if department budgets are exceeded..."
When the LLM sees this massive chunk of prompt, its attention mechanism gets completely confused. When the user inputs: “Help me check if the code for this login interface is done, and also reimburse the 5000 yuan overspent last week due to fixing this bug.” This single Agent immediately falls into identity schizophrenia: it might evaluate your code in the extremely stingy tone of an accountant saying it's not cost-effective, or while checking the database, it casually treats a minus sign in the code as the reimbursement amount. This is “dementia caused by omnicompetence.”
When human society faces complex tasks, it never relies on a lone hero but on departmental collaboration. When LLMs are deployed in business, they must also move toward Multi-Agent systems. The core is: completely dismantle a complex all-powerful Agent into a “virtual office” composed of multiple specialized AIs.
Let's use the failure case above to see how a modern multi-agent system (e.g., built on LangGraph or PydanticAI Graph) flows smoothly behind the scenes:
read local code file. It focuses 100% attention on the code and quickly produces a rigorous security audit report.read-only connection to company financial database. It quickly queries last week's R&D department financial flow and produces the exact overspend amount.In this application-layer decoupling process, the LLM doesn't need to play both judge and god of wealth in the same context. Each sub-Agent's Prompt is extremely clean, carrying only two or three tool skills. Tool call accuracy directly skyrockets from 40% for the single Agent to over 95%.