Building AI Agents: Core Capabilities and Engineering Practices Beyond Frameworks

    Agent development is often framed as a question of which frameworks to learn, but production reliability depends more on task planning, tool governance, memory design, retrieval quality, observability, and evaluation. This article explains the capabilities developers should master, how deterministic workflows and limited autonomy can coexist, how to make tool execution trustworthy, how to manage short- and long-term memory, and how to optimize RAG end to end. It also provides a framework-selection checklist and a practical path from prototype to production, emphasizing that frameworks can be replaced while engineering discipline transfers.

    1. The Core Question: No Mandatory Framework, but Mandatory Capabilities

    “Which frameworks must I learn to build agents?” is a common question, but it tends to draw attention to API usage rather than the system itself.

    An agent can be understood as a program that runs around a goal: it receives a task, makes decisions with context, calls tools within its permissions, continues based on execution results, and ultimately returns an answer or completes an action. The model provides understanding and decision-making. The software system constrains execution, persists state, handles exceptions, and records evidence.

    The real requirement is therefore not mastery of every interface in a particular framework, but mastery of the following capabilities:

    • How tasks are decomposed and how execution paths are constrained;
    • How tools are declared, validated, authorized, and invoked;
    • How conversation state and long-term information are stored and used;
    • How external knowledge is retrieved, filtered, and cited;
    • How execution is observed, evaluated, recovered, and audited.

    The value of a framework is that it organizes these recurring engineering problems into reusable abstractions. For an application with only a few tools and no complex state, writing control logic directly may be more straightforward. For systems with branching execution, human approval, cross-session state, and strict audit requirements, mature framework abstractions are often more valuable.

    The criterion should not be “whether to use a framework,” but “whether business constraints can be met at a reasonable cost.”

    2. Task Planning: Build Controllable Flows First, Then Add Autonomy

    2.1 Distinguish workflows from dynamic planning

    In a workflow, execution steps are mainly defined in advance by developers. For example, knowledge Q&A can follow the sequence “understand the question—retrieve materials—generate an answer—check citations.”

    Dynamic planning allows the model to decide the next step based on the current task and feedback. When analyzing an anomaly, for example, the model might query metrics first, then inspect logs, and then decide whether to continue collecting information based on the results.

    The two are not mutually exclusive. A common production pattern is to use a deterministic workflow to define the overall boundary while allowing limited model decisions at specific nodes. This hybrid design preserves adaptability while making testing and risk control easier.

    2.2 Planning capability does not mean unlimited reasoning

    Complex tasks may require more reasoning, but it does not follow that every request should go through multiple planning rounds. Additional reasoning and repeated calls usually increase latency and cost, and their benefits need to be verified through task evaluation.

    A more practical strategy is to layer tasks:

    • For tasks with clear information and low risk, execute a fixed process directly;
    • For tasks with limited ambiguity, clarify first or perform one round of bounded planning;
    • For tasks involving multiple tools, use iterative execution with stopping conditions;
    • For tasks involving funds, permissions, or data deletion, add human confirmation.

    Users need correct results and necessary explanations, not the full internal reasoning trace. The system should record auditable decision summaries, invocation parameters, and execution results rather than relying on exposing internal reasoning to prove reliability.

    2.3 What planning frameworks should provide

    Rather than asking whether a framework can automatically decompose tasks, it is more useful to ask:

    • Does it support conditional branches and state transitions?
    • Can it set budgets for execution steps, time, and cost?
    • Does it support cancellation, pausing, and human takeover?
    • Can it distinguish business failures, tool failures, and abnormal model outputs?
    • Can it save checkpoints and resume execution?

    Checkpoint recovery does not mean tools can be invoked repeatedly without condition. For operations with external side effects, the recovery process must confirm whether the previous operation has already completed; otherwise, it may write or submit twice.

    3. Tool Calling: From “Call Succeeded” to “Execution Is Trustworthy”

    Tool calling is the key link between an agent and external systems, and it is also where risk most easily enters the business system.

    3.1 Establish explicit tool contracts

    Every tool should have clear input, output, and error definitions. Input validation cannot rely only on the model following prompts; it should also be enforced by code.

    For example, a query tool should at least define the query scope, time conditions, and return limits. A write tool should also define the target object, operation permissions, and duplicate-submission handling.

    A tool call request generated by the model is only a candidate instruction. Before actual execution, the system still needs to perform parameter validation, permission checks, and business rule checks.

    3.2 Govern read and write operations separately

    Read tools and write tools carry different risks. Querying information usually does not change business state, while sending notifications, adjusting configurations, or deleting records produces external effects.

    A tiered strategy can therefore be used:

    • Read-only operations execute automatically within the authorized scope;
    • Ordinary write operations execute after business rule checks;
    • High-risk operations require explicit confirmation;
    • Irreversible operations require additional approval and audit requirements.

    Tool credentials should be managed by the server and should not be exposed directly to the model. Authorization scope should also be based on the current user and current task, rather than defaulting to allowing invocation simply because a tool exists.

    3.3 Retries must account for side effects

    A network timeout does not necessarily mean the operation failed. The request may already have been processed by the external system, with only the response delayed.

    Read operations can therefore be retried under limits. Write operations need idempotency identifiers, status queries, or business deduplication mechanisms to avoid duplicate execution. Whether an operation is retryable should be determined by the tool contract, not by arbitrary model judgment.

    4. Memory Management: The Hard Part Is Selection and Isolation, Not Storage

    4.1 Short-term memory maintains consistency for the current task

    Short-term memory typically includes recent conversation, current task state, tool results, and necessary summaries. The simplest implementation is to store a message list, but as context grows, passing everything to the model increases cost, slows responses, and buries key information.

    Reasonable context management should select information by purpose:

    • Keep the current task goal and explicit constraints;
    • Keep unresolved questions;
    • Keep key facts and their sources;
    • Compress completed intermediate steps;
    • Remove duplicate content and irrelevant retrieval results.

    Note that a summary is not a lossless substitute for the original record. For precise information such as amounts, dates, and object identifiers, structured state should be preferred over relying only on natural-language summaries.

    4.2 Long-term memory reuses information across sessions

    Long-term memory can include preferences explicitly stated by users, long-term task background, and confirmed facts, but not all historical conversations should automatically be treated as trusted memory.

    A safer design is to layer information:

    • Explicit preferences: language, format, or response length specified by the user;
    • Confirmed facts: information with reliable sources that may be used long term;
    • Temporary context: valid only for the current task or a limited period;
    • Speculative information: unconfirmed and not suitable for direct写入 stable profiles.

    Long-term memory should also record source, update time, applicable scope, and expiration conditions. When new information conflicts with old information, it should be updated, downgraded, or confirmed with the user, rather than concatenating both into context.

    4.3 Isolation and deletion matter more than “remembering more”

    Information across users, tenants, and business spaces must be strictly isolated. Even within the same user, information from different tasks may not be appropriate to reference across contexts.

    For example, preferences from private conversations can be used to adjust expression style, but they should not unconditionally enter enterprise business tasks. Long-term memory should support viewing, modification, deletion, and disabling, and should apply stricter retention policies to sensitive information.

    The goal of a memory system is not maximum storage, but using the right information at the right time.

    5. Retrieval-Augmented Generation: Easy to Connect, but Quality Requires End-to-End Optimization

    Retrieval-augmented generation provides the model with external materials that are relevant to the current question and traceable. It can improve knowledge coverage and factual grounding, but it does not automatically guarantee answer accuracy.

    5.1 Document processing determines knowledge usability

    Text splitting should account for document structure rather than mechanically truncating by fixed length.

    Documentation is suitable for splitting by sections and semantic paragraphs; tables need to preserve relationships between fields and rows; operational procedures need to preserve step order; policy documents need to preserve effective dates, applicable scope, and version information.

    Each knowledge chunk should preferably carry metadata such as source, title, update time, and access permissions. This information serves retrieval as well as answer citation and auditing.

    5.2 Retrieval methods should fit query characteristics

    Semantic retrieval is suitable for finding content expressed differently but with similar meaning; keyword retrieval is suitable for exact names, numbers, and specialized terms; relational retrieval is suitable for structured filtering; graph-structured retrieval is suitable for questions with explicit entity relationships.

    These methods can be combined, but more complex combinations are not necessarily better. Representative questions should be used to determine whether an additional retrieval path truly improves results.

    At the same time, distinguish retrieval algorithms, retrieval libraries, and database services: they solve different problems and should not be treated as the same component merely because all participate in similarity queries.

    5.3 Whether to retrieve requires task routing

    Questions involving internal policies, real-time data, or precise sources should usually prioritize retrieval. Tasks such as pure text rewriting or simple format conversion may not need access to a knowledge base.

    When task types are unclear, routing can combine rules and model judgment. Rules handle explicit boundaries, while the model handles language ambiguity, but routing effectiveness still needs to be verified through testing.

    5.4 Generated answers must be constrained by evidence

    Before retrieval results enter context, they should undergo relevance filtering, deduplication, and permission checks. Instructive text in documents should be treated as content to be analyzed, not as system execution instructions, to reduce prompt injection risk.

    If materials are insufficient, conflicting, or outdated, the system should state the limitations and request additional information when necessary, rather than filling in nonexistent facts to complete an answer.

    Retrieval quality and answer quality should also be evaluated separately: first determine whether the right materials were found, then determine whether they were accurately understood and used.

    6. Visualization and Runtime Governance: Observability and Improvement Are What Matter

    A visual interface can lower the barrier to process configuration, but it is not the core competitive advantage by itself. For production systems, it is more valuable to connect execution traces, data management, and quality improvement.

    6.1 Make complex execution locatable

    A single request may involve model calls, knowledge retrieval, multiple tool operations, and human approval. If the system retains only the final answer, it is difficult to determine where a failure occurred.

    Runtime records should cover:

    • Which process and configuration version were used;
    • Which node consumed most of the time;
    • Whether tools failed or were called repeatedly;
    • Which materials were retrieved;
    • Which step triggered a safety block;
    • Whether the final result passed business checks.

    Logs should avoid storing unnecessary sensitive information and should control access by role. Observability does not mean all raw data should be retained indefinitely.

    6.2 Base optimization on repeatable evaluation

    Real systems need to manage test samples, inspect failure cases, compare versions, and turn human feedback into improvement input.

    Evaluation metrics should correspond to business goals, including task completion rate, answer correctness, citation validity, tool-call compliance, response latency, and invocation cost. For high-risk tasks, incorrect operations and permission violations should also be measured.

    Only by establishing an evaluation loop can a team determine whether a prompt change, knowledge update, or process adjustment is truly effective, rather than drawing conclusions from a small number of demos.

    7. How to Choose a Framework: By Complexity and Constraints, Not Popularity

    Common framework capabilities can be divided into four categories:

    Capability category Main problem addressed Better-fit scenarios
    Invocation and workflow encapsulation Unify model, prompt, and tool calling Rapid prototyping, simple task chains
    State orchestration Branching, looping, pausing, resuming Long processes, human approval, complex execution
    Knowledge processing Document parsing, retrieval, and citation Enterprise knowledge Q&A, document analysis
    Runtime governance Tracing, evaluation, configuration, and permissions Team collaboration, production operations

    When selecting a framework, focus on validating the following questions:

    1. Is the core logic easy to understand and test?
      If a simple process must go through many implicit transformations to run, debugging cost may exceed the benefits of encapsulation.

    2. Can the model, storage, and retrieval implementations be replaced?
      Business logic should depend on stable internal interfaces as much as possible, rather than spreading framework-specific calls throughout the code.

    3. Are abnormal behaviors controllable?
      Test timeouts, cancellation, tool errors, state recovery, and duplicate execution in practice, not just by reading feature lists.

    4. Does it meet deployment and data governance requirements?
      Permission isolation, log redaction, data retention, and configuration management should be part of the selection criteria.

    5. Is the adoption cost worthwhile?
      Learning, upgrading, maintenance, and migration are all costs. The repetitive work reduced by a framework should be enough to cover these investments.

    Step 1: Choose a task with clear boundaries. Define inputs, outputs, invocable tools, and actions that must not be executed, and complete a minimal closed loop first.

    Step 2: Separate model calls, tool execution, retrieval, and state storage. Even if no framework is used yet, avoid piling all logic into a single function.

    Step 3: Build a small but representative test set. Cover normal questions, ambiguous questions, no-answer questions, unauthorized requests, and tool failure scenarios, and fix the evaluation method.

    Step 4: Introduce frameworks based on actual problems. Add orchestration capabilities when complex state transitions appear; improve the retrieval pipeline when knowledge quality issues arise; build long-term memory when cross-session requirements emerge.

    Step 5: Complete production safeguards. This includes permission checks, timeout limits, retry strategies, idempotency controls, log redaction, version management, human takeover, and exception alerts.

    Step 6: Continuously optimize based on failure samples. Distinguish model understanding errors, missing knowledge, tool exceptions, and process design defects, and adjust based on the cause rather than uniformly increasing prompt length or call count.

    Conclusion

    There is no universal “must-learn framework list” for building agents. What is worth mastering long term is this: use deterministic processes to constrain uncertain decisions, use explicit contracts to govern tool execution, use scope and provenance to manage memory, use evidence to constrain answers, and improve continuously through observability and evaluation.

    Frameworks can be replaced, but engineering capabilities transfer. Understand these capabilities first, then choose an implementation that reduces real complexity. That is how a demo agent can gradually become a reliable, maintainable business system.