Core Capabilities Required to Build an AI Agent Framework
This article explains why an agent framework is an assembly tool rather than the source of agent capabilities, and breaks down the four core modules you need to master: planning, memory, RAG, and tool use. It covers control-flow orchestration with budget constraints, short-term context management versus long-term preference storage, chunking, retrieval decisions and reranking, tool contract design and safety boundaries, and how to evaluate frameworks by replaceability.
Introduction: A Framework Is an Assembly Tool, Not a Source of Capability
When many teams kick off an agent project, their first instinct is to find an “all-in-one framework,” as if picking the right one guarantees half the success. In engineering practice, however, a framework solves the problem of assembly efficiency, while the ceiling on an agent’s capability is set by four underlying modules: planning, memory, retrieval-augmented generation (RAG), and tool use. How deeply you understand these four blocks is what you actually have to master.
A rough rule of thumb: if you cannot reproduce a capability with a few dozen lines of general-purpose code, you do not really understand it yet — the framework’s abstraction is simply shielding you. Let’s break each block down.
1. Planning: Orchestration Is Fundamentally Control Flow
The goal of planning is to get the model to decompose “solving the problem” into ordered steps. Common forms in the industry include workflow orchestration, chain-of-thought, and lightweight thinking modes. They are all doing the same thing: generating intermediate states before generating the final answer.
Three common misconceptions need clearing up:
- Planning does not require a specific framework. The core of workflow orchestration is a directed graph (nodes are model calls or functions, edges are data flow), which you can implement with plain function calls and conditional branches in any general-purpose language. So-called declarative orchestration expressions are just a more concise way to write that graph; what they save is a few dozen lines of glue code, not a new capability.
- Full chain-of-thought is poor value in production. It requires the model to emit lengthy intermediate reasoning, which creates two direct costs: higher token consumption, and longer time-to-first-token and total latency. In real applications the user’s waiting window is usually only a few seconds, and long-chain reasoning often exceeds that tolerance.
- Complex schemes that need multi-round iterative planning mostly stay at the paper level. Such schemes assume the task can be retried repeatedly, whereas online systems need deterministic latency and a predictable number of calls.
What engineering practice favors is a combination of “lightweight thinking plus explicit flow”: write the stable, unchanging steps as deterministic code, and hand only the uncertain decision points to the model. Example:
def handle(query, ctx):intent = classify(query) # the model only classifies, short outputif intent == "simple":return answer(query) # answer directly, zero extra overheadplan = planner(query, budget=2) # cap at two steps, avoid infinite iterationresult = execute(plan, ctx)return verify(result) if need_check else result
The key design point is the budget constraint: set hard limits on the number of planning steps, the number of calls, and total latency, and fall back to a degraded path when a limit is exceeded. This improves production stability more than chasing “smarter planning.”
2. Memory: Short-Term and Long-Term Are Two Different Orders of Difficulty
Memory is often discussed as one thing, but it must be split into two layers whose implementation difficulty and business value differ enormously.
Short-Term Memory: Context Governance for Multi-Turn Conversations
The principle is simple: maintain a full copy of the conversation, then trim out the key fragments according to a policy and send them to the model together with the current question. The core need here is not “remembering” but saving tokens, saving latency, and improving accuracy. Common strategies can be combined:
- Sliding window: keep only the most recent N turns;
- Summary compression: generate a structured summary of earlier dialogue (user goal, confirmed constraints, pending items);
- Relevance filtering: drop retrieval results and intermediate artifacts unrelated to the current question;
- Structured carriers: extract facts scattered across the conversation into key-value structures to avoid passing them repeatedly.
This logic can be built with general programming skills plus a single model call; there is no technical barrier. What really needs polishing is the evaluation of trimming policies: prepare a batch of multi-turn conversation samples offline, compare task success rate and average token count under different policies, and let data decide the thresholds.
Long-Term Memory: Cross-Session Preferences and Profiles
This is where differentiation lies. The goal is to remember a user’s language style, preferred response length, long-term goals, and historical constraints across sessions. The difficulty concentrates in three places:
- When to write: what information is worth remembering long-term? You need to distinguish “one-off facts” from “stable preferences,” otherwise the memory store gets flooded with noise.
- Conflict resolution: when a new preference contradicts an old one, you need priority and time-decay mechanisms to decide what overrides what.
- Error isolation: this is the most easily overlooked point and the one that hurts experience the most — pulling information from session A into session B by mistake will visibly derail the answer. Even leading general-purpose assistants in the industry often show this kind of cross-contamination.
A workable engineering approach is to give memory a “scope” and a “confidence”:
memory_item = {scope: "user" | "session" | "project", # scope determines visibilityconfidence: 0.0 ~ 1.0, # low confidence is not injected directlyupdated_at: timestamp, # supports time decaysource: "explicit" | "inferred" # explicit statements beat inferences}
Filter strictly by scope at injection time, put only high-confidence explicit preferences into the prompt, and treat inferred information as candidates only. These constraints noticeably reduce cross-session contamination, and they are the dividing line for whether personalization can ship.
3. Retrieval-Augmented Generation: Three Problems, None Framework-Specific
RAG has been over-mystified. Broken apart, it is only three engineering problems:
- Chunking and index construction: split along semantic boundaries while preserving structural information such as titles, hierarchy, and tables; for corpora dense in entities with clear relationships, you can extract a knowledge graph to support multi-hop question answering. Chunk granularity must align with question granularity — chunks that are too large introduce noise, chunks that are too small lose context, and an overlap window is usually the compromise.
- Retrieval decisions: not every question needs a database lookup. Use a lightweight classifier or a small model to judge “does this need retrieval”; answering simple questions directly lowers both latency and cost. For ambiguous cases, set a fallback policy — better to search once more than to answer out of thin air.
- Storage and approximate retrieval: a vector store handles semantic similarity search, a graph store handles relationship traversal, and the two can coexist. Approximate nearest neighbor (ANN) search is a general-purpose algorithm category with essentially the same mainstream implementation approach, so selection should focus on data scale, recall requirements, incremental update capability, and operational cost rather than the name of a particular implementation.
Tuning happens on the business side, not the tooling side: query rewriting (normalizing colloquial questions into retrieval-friendly phrasing), multi-way recall fusion, reranking, and credibility checks based on citation provenance. Example:
def retrieve(query, top_k=20, final_k=5):if not need_search(query): # decision layer: decide whether to search firstreturn []docs = vector_index.search(rewrite(query), top_k) # recalldocs += graph_index.expand(docs) # relationship expansionreturn rerank(query, docs)[:final_k] # rerank and truncate
Evaluation must also be systematic: monitor recall hit rate, post-rerank relevance, and the factual consistency of the final answer separately. Judging only whether an answer “sounds right” is meaningless.
4. Tool Use: The Agent’s Only Interface to the Outside World
Tool use determines whether an agent can “do things” or can only “talk.” The key points are contract design and safety boundaries:
- The description is the interface: the tool’s name, parameter descriptions, and return structure are the model’s only manual; vague descriptions directly cause the wrong tool to be selected;
- Idempotency and rollback: write operations need idempotency keys so that retries after failure do not produce duplicate side effects;
- Least privilege: grant credentials per session, and add a human confirmation step for sensitive operations;
- Observability: log the inputs, duration, and return code of every call, and pair that with logging services and monitoring alerts to locate problems.
5. Selection Advice: Rank by Replaceability
To judge whether a framework is worth adopting, check three things: modules are replaceable, state is exportable, and failures can degrade gracefully. If a framework locks session state, retrieval indexes, and prompt templates inside private structures, migration cost will spiral out of control as the business grows.
When deploying in the cloud, general-purpose capability categories are usually enough: a container platform to host agent services, a message queue to decouple asynchronous tasks, object storage for raw corpora, and logging and monitoring systems for observability. General cloud product categories from providers such as Baidu AI Cloud can serve as the foundation for this kind of architecture, but the specific selection should still come back to your own data scale and compliance requirements.
Conclusion
What you must master is never a particular framework, but four things: writing the flow as controllable code, trimming context to just enough, making retrieval decisions and reranking solid, and designing tool contracts clearly. Once you have these four blocks down, a framework is just a shell you can swap at any time; the other way around, no matter how fluent you are with a framework, you are only fine-tuning on top of someone else’s abstraction.
