[KongchangAI]
· 4 min read· 2,200 words

The 12 Core Principles of AI Agents Explained Clearly: From Messages to Multi-Agent Systems

The 12 Core Principles of AI Agents Explained Clearly: From Messages to Multi-Agent Systems

Breaking down the 12 underlying principles of AI Agents, showing that Agents are essentially code assemblies of simple technical details.

The article systematically explains the 12 core principles behind AI Agents in an accessible way, noting that the underlying logic hasn't fundamentally changed over the past year. It starts from the interaction starting point: the large model's only channel is the Message array, and it's completely stateless with no memory—every request must repackage history. Then it introduces prompt engineering methods for controlling AI behavior—System Prompt sets roles, Chain of Thought improves reasoning accuracy, Few-shot locks output format, pre-fill cuts opening pleasantries, and stop sequences prevent the model from imagining results on its own. It then explains that tool calling is just a developer-wrapped protocol and that RAG is essentially an open-book exam, not knowledge injection. Finally, it covers how the ReAct loop achieves autonomous decision-making, why hallucination can only be suppressed but not eliminated, and the collaborative division of labor in multi-Agent orchestration. The conclusion: Agents are not profound technology but systems engineering where simple logic is stitched together with code.

The concept of AI Agents is being hyped everywhere, but many people get lost in the technical jargon. In reality, the underlying logic of Agents hasn't fundamentally changed over the past year or so. Those seemingly complex frameworks, when taken apart, are nothing more than combinations of a few basic principles. Based on a systematic breakdown by a Bilibili creator, this article strings together these 12 core principles in an accessible way to help you truly understand how AI does work for us.

1. The Starting Point of Interaction: Message Data Structure and Stateless Nature

1. Message: AI's Only Communication Channel

Chatting with AI feels like a back-and-forth conversation, but large models have no such thing as a "conversation channel" at the底层 (underlying level). All interaction goes through a single channel: the Message array. Each request doesn't just send the current sentence—it packages the entire history into a list (array) and sends it over. What the large model does is similar to reading comprehension—after reading the whole set of messages, it infers what would be most appropriate to write next.

At the底层, this array is encapsulated in JSON format, clearly marking which sentence was said by the user (role: user) and which was the AI's reply (role: assistant). If you send an empty array, the model won't generate a single word. This is precisely the most fundamental starting point of every Agent.

2. Statelessness: AI Has No Memory at All

A mind-blowing truth: large models have absolutely no memory. Every request starts completely fresh, which is technically called "stateless." One second you ask it to write an email, the next second you say "that's too long, shorten it"—in its eyes, you're a complete stranger.

So how does it know what to shorten? The system does some behind-the-scenes work: it takes the previous question, the AI's reply, plus the new instruction "shorten it," repackages everything into a brand-new payload, and sends it to the model all at once. The capacity for holding this history is the context window. If the window is too small, it forgets after a couple of exchanges; if you stuff everything in, it's expensive and the model easily gets "dazzled." How to balance this is a fundamental skill in Agent development.

2. Controlling AI Behavior: System Prompt and Prompt Engineering

3. System Prompt: Putting a Persona Mask on AI

How do you make AI play a specific role? Through the system prompt. It's written at the very top of the Message array with the highest authority, like a supreme code of conduct, making the model think through this mask when processing all subsequent conversations.

The contrast is intuitive: ask directly "explain what an API is," and the model gives a textbook definition—dry and boring. But if you prepend a system prompt to the request—"You are a kindergarten teacher speaking to a five-year-old. Please explain complex concepts with vivid analogies"—the same question instantly transforms into "Imagine an API is like a little bear waiter in a restaurant." Whether building a customer service Agent or a writing assistant, this is the first step to locking in the AI's behavioral style.

The system prompt is written here

4. Chain of Thought (CoT): Teaching AI to Draft

Large models have no calculator at the底层. Solving math problems is essentially using probability to "guess" the next digit—asking directly for a six-digit times seven-digit multiplication is almost guaranteed to be wrong. But amazingly, adding "please calculate step by step" can boost accuracy to over 90%.

The principle: the model infers subsequent content from prior conversation history. When it lists intermediate reasoning steps one by one (breaking down numbers, multiplying individual digits), these correct intermediate steps become the context for predicting the final answer—it's giving itself clues. Just like a person doing complex arithmetic: trying to do it in your head easily leads to errors, but using scratch paper to lay out the steps usually gets the right result. This is the Chain of Thought (CoT).

5. Few-shot Prompting: Locking Output Format with Examples

A common crash scenario when building Agents: you require an sentiment classification system to output only three words—"positive/negative/neutral" (zero-shot prompting)—but the model returns a huge explanation instead, which is a bug in code. Reasoning with it doesn't help; the most effective approach is to directly give two or three concrete examples:

Input: The weather is so nice today, I feel great → Output: Positive Input: Whatever, anything works for me → Output: Neutral Input: This movie is terrible → Output: (blank)

The model gets it instantly and perfectly mimics the format, outputting only "Negative." One real example is worth ten lines of abstract requirements—this is few-shot prompting.

Just give it two or three concrete examples

6. Pre-fill: Cutting Off the Opening Pleasantries

Even with few-shot, some models are still too polite—they open with "Sure, here's the JSON data you requested," and program parsing throws an error immediately. The pre-fill approach is clever: write the opening for the model before it starts speaking. Want it to return JSON? Pre-fill a left curly brace at the start of the AI's response. The brace is already there, so the model can't start with "Sure"—it can only follow the semantics and write key-value pairs, finally closing with a right curly brace. The output is clean and entirely parseable JSON. This technique is indispensable for building stable Agents.

7. Stop Sequences: Shut Up When It's Time to Shut Up

AI has an extremely powerful imagination. Ask it to check Beijing weather, and after outputting "Action: GetWeather," if you don't call stop, it will pretend to be the weather tool itself and casually write "Observation: Beijing is sunny, 30°C today"—before the code even has a chance to go online, it has already fantasized the result. This is a catastrophic bug in Agent systems.

The solution is to set a stop sequence, such as the word "Observation": when it writes this word, it must stop immediately—not a single character more. Control returns to the code, which takes the command to the real API, retrieves the data, then splices the real result into the conversation history and feeds it back to the model. This give-and-take handoff of control relies entirely on the stop sequence hitting the brakes.

3. Tool Calling and External Knowledge: The Boundaries of Agent Capabilities

8. Tool Calling: AI Doesn't Actually Use Any Tools

You often hear that AI can browse the internet, query databases, and call tools. The truth is: at the底层, AI can neither access the internet nor operate any software. All it can do is spit out strings based on probability. So-called tool calling is a protocol layer that developers wrap around the outside.

The complete flow: the model outputs a JSON-formatted call instruction, and then its task is done. The Agent framework intercepts and parses this JSON, discovers it wants Beijing weather, and calls the real third-party API on its behalf in the background. After getting the real data (30°C sunny), it splices it back to the model, which can then continue composing its reply to you. The essence of tool calling is having the model output standardized call instructions, while code handles execution and result injection.

AI can access the internet

9. RAG: Giving AI an Open-Book Exam

How do you make the model know company private data (employee handbook, reimbursement process, product docs)? Retraining is too expensive. The mainstream solution is RAG (Retrieval-Augmented Generation), but it doesn't pour the materials into the model's brain—it's essentially giving AI an open-book exam.

When an employee asks "What's the company reimbursement limit?", the system doesn't send the question directly to the model. The program first searches a vector database, using keyword or semantic matching to find the relevant clause fragment (regular employees: 1,000 yuan per month). Then it splices this reference material with the question into a brand-new long prompt: "Please answer strictly based on the following reference materials..." Seeing an open-book exam, the model confidently answers "According to company policy, it's 1,000 yuan." It didn't memorize the private data—it just read and copied from the exam paper handed to it.

For example, that string of weather query data I mentioned

4. Autonomous Operation: The ReAct Loop and Multi-Agent Orchestration

10. ReAct: The Loop of Thought, Action, and Observation

How do you chain actions together so AI can plan autonomously? At the code level, it's just a classic external loop where the model repeats three actions according to a template—the ReAct pattern:

  • Thought: Reason about what to do next based on the current problem.
  • Action: After deciding, output a tool-call JSON and hand it to code for real execution.
  • Observation: The code splices the execution result back to the model, which uses it to begin the next round of thinking.

If the task isn't complete, the while loop keeps spinning until the model determines during the thought phase that it's done and exits. So-called Agent autonomous decision-making is essentially just a code structure looping around a "Thought-Action-Observation" template, spinning continuously.

11. Hallucination: Cannot Be Eliminated, Only Suppressed

The biggest headache during loop spinning is hallucination. Ask "Did Lu Xun and Zhou Shuren ever fight?" and the model might earnestly fabricate "They once fought in Shanghai." Because large models are fundamentally autoregressive generation mechanisms—there's no concept of "I know/I don't know" in their heads. They always guess the most likely next word based on preceding text. Forced into word-chain continuation, they naturally produce fluent but incorrect content.

Hallucination is a底层 mechanism that cannot be 100% eliminated, but it can be suppressed: use RAG to retrieve real materials, and strictly constrain in the system prompt "You must answer based on the given facts; if you can't find a basis, say you don't know." At high-risk decision points, human verification must be added—you cannot fully delegate.

12. Multi-Agent Orchestration: The Division of Labor Between Foreman and Workers

After tuning individual Agents, the final step is making them work together. Multi-Agent orchestration is much like workplace division of labor: set up a "foreman" Agent to receive complex tasks (like planning a Beijing trip). It doesn't do the concrete work itself but decomposes and dispatches—flight queries go to a flight Agent calling the airline API, room bookings go to a hotel Agent checking prices, itinerary writing goes to a planning Agent combining the schedule. Sub-Agents report back when done, the foreman aggregates, and finally presents the complete itinerary to the user. This collaboration lets each Agent focus on a vertical domain, greatly improving the stability and efficiency of complex business systems.

Final Thoughts

From the most basic Message data structure and context memory, to prompt engineering (System Prompt, CoT, Few-shot, Pre-fill, stop sequences), to tool-calling protocols, RAG, the ReAct loop, and multi-agent collaboration—so-called AI Agents are not some profound technology. They are essentially systems engineering where simple technical details are stitched together externally with program code. Understanding this underlying logic will give you more confidence, whether you're writing prompts to tune AI yourself or architecting projects.

Background Supplement

Each message in the Message array distinguishes its speaker through the role field. The three most common roles are: system (system prompt, setting AI's behavioral guidelines), user (user input), and assistant (AI's historical replies). In tool-calling scenarios, a tool role also appears, carrying results returned by external tools. Different vendors' APIs differ slightly in field naming (e.g., OpenAI uses content, Anthropic supports content blocks), but the core structure is the same: an ordered list with a role label for each message. Understanding this is crucial—what we call "multi-turn conversation" is, from the model's perspective, just a longer list. There is no session object or connection state. Developers must maintain this list themselves—adding, removing, and truncating—which is precisely the first thing Agent frameworks need to solve.

Chain of Thought has two engineering extensions worth knowing. First, "zero-shot CoT": without any examples, just one sentence "Let's think step by step" can significantly improve reasoning performance, showing that step-by-step reasoning ability is partially internalized in large models. Second, "Self-Consistency": sampling multiple different reasoning paths for the same question, then voting for the majority answer—trading sampling cost for accuracy. Additionally, CoT output consumes context window; longer reasoning steps mean more token consumption. In Agents, the thinking process is usually placed inside specific tags (like <thought>) to distinguish it from actual action instructions during parsing.

The "vector database" in RAG deserves elaboration. Text is first converted into high-dimensional vectors by an embedding model—semantically similar texts are closer in vector space. During retrieval, the user's question is also converted into a vector, and approximate nearest neighbor search (e.g., cosine similarity) retrieves the most similar fragments. Real systems often use hybrid retrieval: keyword search (BM25) ensures proper nouns are matched, while vector search ensures semantic recall, with results from both fused and ranked. Retrieved fragments also need reranking and truncation because the context window is limited—stuffing in too much irrelevant material dilutes key information and induces the model to get "dazzled." Chunking strategy (chunk size and overlap) also directly affects recall quality and is one of the main levers for RAG tuning.

#AI Agent#Message data structure#System Prompt#Chain of Thought#Few-shot#RAG#ReAct loop#multi-Agent orchestration
Share:

Related articles