跪拜 Guibai
← Back to the summary

A Tencent Interviewer's Agent Architecture Grilling, Answered from a Real CLI Implementation

Hello everyone, I'm Second Brother.

If you're someone who believes in hard work, believes in the process, believes in taking it one step at a time, and believes you can get a piece of the pie in the AI era, then I hope you'll read this next hardcore interview experience carefully.

(The full text is quite intense, I guarantee you'll learn a lot. Fasten your seatbelts, we're off~)

content

01. The Connection and Difference Between LLM and Agent

Old Wang's first question was a conceptual one. "Explain the connection and difference between LLM and Agent."

"Let's start with the connection. Every decision an Agent makes is made by the LLM."

"Whether to call a tool, which one to call, how to fill in the parameters, whether the task is complete—the model is in charge of all these decisions. The Agent framework itself doesn't make judgments."

"The difference lies in the boundaries of responsibility. An LLM is a stateless text generation service. One call takes in a piece of context and outputs a piece of text. Once the call ends, it remembers nothing and cannot change the external world."

"An Agent is an execution system built around an LLM, supplementing three things the model lacks:"

"To sum it up in one sentence: the LLM is responsible for thinking, and the Agent is responsible for actually doing it after thinking."

Old Wang followed up. "So, does a web-based chat assistant count as an Agent?"

"It depends on whether it has a ReAct loop. Pure Q&A is a single call—text in, text out—so it doesn't count. Once it starts searching the web on its own, running code, and using intermediate results to push forward, it's already a lightweight Agent."

"The criterion isn't the product form, but whether there's a closed loop of 'decision, action, observation, decision again.' As for how ReAct specifically works, that's perfect for the next question."

02. What Parts Make Up a ReAct Agent?

Old Wang nodded. "You know about ReAct Agents? What parts are they made of?"

"ReAct is the loop of Reasoning + Acting. Taking my own PaiCLI-Python as an example, it breaks down into five parts, each mapping to a specific module:"

How It Completes a Problem Given by a User

Old Wang followed up. "So, when a user gives it a problem, what's the whole process?"

"First, two preparation steps: inject the matched Skill candidate list into the context, and check whether the total message count needs compression."

"Then, enter the loop. Send the message history and tool list to the model. The model returns a stream, either giving a direct text answer or initiating a tool call."

"If it's the latter, the executor runs the tool, appends the result as a tool message back into the history, and calls the model again. The model sees the tool result and continues deciding—either calling another tool or giving the final answer."

"There are two exit conditions. The model no longer requests a tool, ending normally; or it reaches the 20-round limit, forcing a wrap-up."

"There are also two implementation details. One is that read-only tools can run up to 4 concurrently, while write operations are strictly serial to prevent mutual overwriting. The other is that in a streaming scenario, tool call parameters arrive in fragments. You have to concatenate the parameter fragments by sequence number into a complete JSON before handing it to the executor. If you concatenate too early, you get a half-finished JSON and the parsing fails immediately."

03. Designing an Agent Framework: What Modules Would You Divide It Into?

Old Wang leaned back in his chair. "If you were to design an Agent framework from scratch, what modules would you divide it into?"

"Six core layers:"

"The security layer is easy to miss, so I'll mention it separately. An Agent really does execute commands. The blacklist contains dangerous ones like sudo and rm -rf, which are intercepted directly."

"File writing and command execution are either marked with a danger level or require mandatory human confirmation. All execution records go into an audit log. The more capable a system is, the more you need to think first about how to restrain it."

How Modules Interact

"Assembly happens at startup. The entry layer merges built-in tools and MCP tools into a single tool registry and hands it to the Agent."

"Runtime flow: The Agent holds the message history. Each round, it hands the history to the model layer. The call request returned by the model is handed to the tool layer for execution. The result is fed back into the history, and the cycle repeats."

"The key design decision is that all modules output only one thing to the outside: uniformly formatted streaming events. Text increments, thought increments, tool calls, usage statistics—all are events. The entry layer only handles rendering and doesn't get involved in logic."

"The benefit is that each layer can be replaced independently. Change the model, only the model layer is affected. Add a tool, only the registry changes. Change the interface, only the entry layer changes."

04. The Connection and Difference Between MCP and Tool

Old Wang jotted a note in his book. "Talk about the connection and difference between MCP and tool."

"The difference lies in ownership. A tool is an in-app function. I write it myself, register it myself, and it follows the code. Other applications can't use it."

"MCP decouples tools from the application, turning them into independent service processes. Any MCP-supporting client can connect and use them. It solves the combinatorial explosion problem of M applications connecting to N tools."

"The connection is that they lead to the same destination. Once an MCP tool is connected, it gets wrapped into the same form as a built-in tool, registered in the same tool registry, and ultimately fed to the model in the Function Calling format."

"The model doesn't know, and doesn't need to know, whether a tool is a local function or a remote service."

"In my implementation, I did three things:"

"Configuration is also merged in layers. A global config in the user directory, a local config in the project directory. For services with the same name, the latter overrides the former. Paths support environment variable expansion."

"If a server can't connect, it's isolated individually and the error is logged, without affecting the normal registration of other tools."

"There's another easily overlooked point. Besides tools, MCP also has resources and prompt templates. I mapped these into virtual tools as well. Listing resources, reading resources, and calling regular tools all go through the same path. The model side doesn't need to learn new actions."

05. How Short-Term and Long-Term Memory Are Implemented

Old Wang flipped a page of the resume. "For the intelligent Q&A in your project, how are short-term and long-term memory implemented?"

"Short-term memory is the message history within a session—a list with an upper limit of 100 entries, working in conjunction with context compression."

"The trigger line for compression is 80% of the available input budget. Once exceeded, it compresses down to 55%. The most recent 6 messages are kept as-is, and earlier turns undergo extractive summarization. The split boundary falls on user messages, ensuring tool calls and results appear in pairs."

"Long-term memory uses SQLite stored in the user directory, effective across sessions, with scope isolated by project path. There are a few design details I can expand on:"

"There's one more boundary to guard. Summaries generated by compression only serve the current session. They are second-hand information generated by the model and are never promoted to long-term memory."

"Long-term memory only accepts facts the user explicitly requests to save. Once this line is loosened, the memory store will quickly be polluted by the model's own paraphrasing."

The Industry's Mainstream Three-Layer Memory System

Old Wang then followed up. "How is the industry's mainstream three-layer memory system divided? What's stored in each layer?"

"The mainstream division cuts three layers by scope:"

Layer What's Stored In PaiCLI-Python
Session Layer Messages of the current conversation In-memory message list, 100-entry limit
Project Layer Repo conventions, build commands PAI.md at project root, tracked by Git
Global Layer Cross-project personal preferences Memory store and global config in user directory

"File memory also has a local override layer, PAI.local.md, which stores machine-specific config and isn't checked into version control. Loading also has a budget: single files are truncated at 6000 characters, and the combined total is 16000 characters, preventing memory from eating up the context window."

I suggest saving this table. It can basically be applied to any memory-related question.

06. Do You Know About Skill's Progressive Loading Mechanism?

Old Wang threw out the next question. "Do you know about Skill's progressive disclosure mechanism?"

"I do. The core is eight words: index resident, body on-demand. Specifically, it's two stages."

"First stage: Every time the user inputs, only the names and descriptions of the top 5 matching Skills are injected into the context. A single description is truncated to 300 characters, and the entire index doesn't exceed 4000 characters. At this point, the model knows which skills are available, but not a single character of the body text has entered."

"Second stage: The model determines the current task matches a Skill and actively calls the load tool. Only then is the body of SKILL.md read, with an upper limit of 5000 characters. Moreover, the body isn't immediately stuffed into the current turn; it's placed in a buffer and injected with the tool results in the next turn. The buffer only keeps the most recent 3 entries to prevent accumulation."

"The Skill directory itself is also divided into three layers: built-in, user-level, and project-level. When names collide, the project-level overrides the user-level, consistent with the layering logic of memory files."

"The benefit of this mechanism can be quantified. For 20 Skills, fully loading them at a 5000-character limit per piece would be 100,000 characters. The resident cost of progressive disclosure is only a 4000-character index—a 25x difference."

Old Wang followed up. "How are candidates matched?"

"Weighted scoring. If the user explicitly names a Skill, it gets the highest score directly. Otherwise, scoring is based on the hit location: name hits have the highest weight, tags next, descriptions lowest. Chinese also uses bigram and trigram tokenization to improve recall."

"To put it bluntly, it's a miniature search engine. The retrieval objects just changed from web pages to skills."

07. How to Guarantee Output Quality When Using AI

Old Wang asked the last formal question. "When using AI, how should you guarantee the quality of the output content?"

"I'll answer in three layers, starting with what I've implemented."

Old Wang followed up. "Those are all engineering measures. What about at the prompt level?"

"Three practices. Write acceptance criteria directly into the prompt so the model knows what 'qualified' means. For complex tasks, require the model to first restate its understanding before acting, exposing deviations early. For important outputs, have the model self-check against the criteria one round before delivering."

"I'll also be honest: I haven't implemented a universal hook mechanism or structured output validation yet, and the main loop doesn't have automatic retries. The biggest taboo in an interview for this question is claiming you've done something you haven't. The first rule of quality assurance is to ensure what you say is true."

Old Wang smiled and closed his notebook.

How to Write PaiCLI on a Resume?

Project Name: PaiCLI-Python

Project Description: A Python Agent CLI tool benchmarking against Claude Code, supporting three modes: ReAct, plan execution, and multi-agent.

Tech Stack: Python, asyncio, httpx, MCP, SQLite

Core Responsibilities:

Counter-Question

08. Based on My Interview Performance, How Should I Study Backend and Agent?

At the end of the interview, it was my turn to ask a counter-question. "Based on my performance just now, can you give me some study advice for backend and Agent?"

Old Wang thought for a moment, and the advice he gave was packed with information. It was so thoughtful, man, I almost wanted to bow to him. His original words, broken down, form a complete self-check checklist:

Every item on this list can be reviewed against the source code of a real project.

ending

In the past, backend interviews were about concurrency and middleware. Now, they're about understanding models, tool calling, memory, and context.

We have the chance to stand at the forefront of AI development, turning 'Agent' from a glossary term into a project on our resumes that can withstand tough questioning. Although there are many challenges, it's also full of infinite possibilities.

Keep it up, brothers and sisters.

See you next time.