Learning Agents in Practice: Architecture Breakdown and Multi-Role Customization

    This guide explains how learning agents differ from ordinary chat assistants and how to build one that actually improves over time. It walks through a unified execution kernel shared across entry points, a layered memory model, a skill-learning loop with offline validation and rollback, multi-role customization with real isolation, a step-by-step path from a minimal closed loop to continuous operation, and the security and evaluation practices that turn a runnable demo into dependable infrastructure. The focus is on verifiable engineering: evidence, boundaries, and recovery for every capability you add.

    1. From Chat Assistants to Learning Agents

    An ordinary chat assistant generates responses mainly from the current input. Even when it can call tools, if it does not retain useful experience after a task finishes, it may re-explore the same workflow the next time a similar problem appears.

    Learning agents try to solve this repeated-effort problem: while completing a task, they preserve the necessary context, organize validated methods into reusable skills, and use later evaluation to decide which experience to keep, revise, or retire.

    The word “learning” needs to be understood precisely. It usually happens first in the system’s external state—memory stores, skill libraries, and task policies—rather than modifying the underlying model’s parameters on every conversation. Conflating the two leads to overestimating the system’s capabilities and misjudging deployment costs.

    A complete learning agent can be abstracted as:

    Reasoning model + tool execution environment + persistent memory + skill management + evaluation mechanism + permission boundaries

    Here, the model understands the task and proposes the next action; tools interact with the external environment; memory stores cross-task information; skills record reusable workflows; the evaluation mechanism checks whether changes are effective; and permission boundaries decide what the system is allowed to do.

    These capabilities do not automatically form a reliable system. The real engineering difficulty is making them work together in a controlled way, rather than simply stacking features.

    2. A Unified Execution Kernel: One Behavior Across Entry Points

    2.1 Why a Unified Kernel Is Needed

    An agent may receive requests through a terminal, a messaging entry point, scheduled jobs, or a development environment. If each entry point maintains its own task logic, the system easily becomes inconsistent: the same role can access a piece of memory in the terminal but cannot read it from the messaging entry point; one entry point performs a permission check while another bypasses it.

    A more reasonable design lets each entry point handle only protocol adaptation, converting identity, role, session, and task information into a unified request, then handing it to the same execution kernel.

    A typical flow looks like this:

    1. Task entry point
    2. → Identity verification and role selection
    3. → Load role configuration and relevant memory
    4. → Build task context
    5. → Reasoning and tool-call loop
    6. → Validate results and return
    7. → Record trace and generate learning candidates

    A unified kernel does not mean all tasks must run serially. It emphasizes consistent business rules; different tasks can still run concurrently in separate worker processes.

    2.2 How the Execution Loop Works

    A common agent execution pattern iterates repeatedly between “reason—act—observe.” The model decides whether a tool is needed for the current task; if so, the system executes the tool and returns the result to the model; if the information is sufficient, it generates the final answer.

    A simplified illustration (names are for explanation only and do not represent ready-made interfaces):

    1. Initialize task context
    2. Repeat until a step or time limit is reached:
    3. Generate the next decision
    4. If the decision is to finish the task:
    5. Check result completeness
    6. Return the final result
    7. If the decision is to request a tool:
    8. Validate permissions, parameters, and risk level
    9. Execute the tool with a timeout
    10. Add the tool result to the context
    11. Limit exceeded:
    12. Return current progress, reasons for incompletion, and recovery suggestions

    Reliability usually comes from the constraints around the loop, not the loop itself. At minimum, set a task time limit, a tool-call limit, a resource budget, and repeated-failure detection.

    For example, after a file read fails, the system should not retry indefinitely; when the same error appears multiple times, it should switch strategies or ask the user for more information.

    2.3 The Boundary Between Synchronous Execution and Concurrent Scheduling

    Within a single task, synchronously waiting for tool results keeps causality clear: get the data first, then make judgments based on it.

    At the system level, however, long-running tasks should not block all user requests. A task queue and worker processes can separate receiving requests, executing tasks, and sending notifications. For tasks that modify the same directory or shared state, add mutual-exclusion control to avoid concurrent writes overwriting each other.

    3. Layered Memory: Retain What Is Useful, Not the Entire History

    Persistent memory does not mean stuffing the whole conversation back into the context. As tasks accumulate, this approach raises costs, adds retrieval noise, and creates privacy risks.

    A more practical method divides memory by lifecycle, purpose, and trustworthiness.

    3.1 Current Task Context

    This layer holds the goal being executed, constraints, tool outputs, and interim conclusions, mainly for continuous reasoning within the current task.

    It usually has a short lifecycle. After the task ends, a summary can be generated, but the entire content should not be turned into long-term memory by default. In particular, temporary access credentials, one-time links, and sensitive file fragments should be kept out of persistent storage.

    When context needs to be compressed, prioritize keeping the goal, unresolved questions, verified facts, important file locations, and the most recent failure reason—rather than only a surface-level conversation summary.

    3.2 Long-Term Facts and User Preferences

    This layer stores relatively stable information, such as a user’s preferred output language, report structure, project constraints, and authorization scope.

    Long-term memory should carry a source, an update time, and a scope of applicability. Preferences inferred by the model should be marked as unconfirmed rather than treated as facts.

    For example, a user asking for short answers twice in a row is not enough to prove they prefer brevity in all scenarios. A more reasonable record is “recently tends toward concise explanations in technical Q&A,” and the user should be able to view, correct, and delete it.

    If historical memory conflicts with a current explicit instruction, the current instruction and the effective permission policy take precedence.

    3.3 Task Experience Memory

    Experience memory records “what happened”: which problem was handled, what method was used, what the result was, and what evidence supports the conclusion.

    It is well suited to helping an agent retrieve similar cases, but it cannot replace checking the current environment. A solution that worked before may fail because of changes in dependency versions, directory structure, or business rules.

    So after retrieving an old case, first verify its applicable conditions, then decide whether to reuse it.

    3.4 Procedural Memory and Skills

    A skill records “how to accomplish a class of tasks.” It is more abstract than a single task record and should have clear inputs, steps, outputs, and validation criteria.

    For example, a useful skill is not “the last change succeeded,” but rather:

    When an API responds abnormally, first confirm the reproduction conditions, then check the request and response structure, locate the error-handling path, run the relevant tests after making the change, and state the remaining risks.

    The value of a skill lies in reusing a validated workflow, not in making the system mechanically repeat past operations.

    3.5 Memory Retrieval and Updates

    When retrieving memory, consider task relevance, trustworthiness, timeliness, and permission scope together. Not all relevant information may be read by the current role, and the newest record is not necessarily the most reliable.

    Writing to memory also needs governance. A recommended order:

    1. Decide whether the information is worth keeping long-term;
    2. Check whether it contains sensitive content;
    3. Confirm the source and scope of applicability;
    4. Run a conflict check against existing records;
    5. Save the necessary version or update record.

    Only this way can the memory store avoid gradually becoming an unverified collection of information.

    4. The Skill-Learning Loop: Validate Experience Before It Reaches Production

    4.1 Extracting Candidate Skills from Task Traces

    Skill generation can be assisted by the model, but a successful task does not mean the entire execution trace is worth solidifying.

    The system should distinguish which steps actually made a difference and which were incidental attempts. For example, if a failure was ultimately resolved by fixing a configuration, the earlier unrelated retries should not be written into the standard procedure.

    A candidate skill should contain at least:

    • The skill’s goal and applicable scenarios;
    • Preconditions and required permissions;
    • Inputs, operation steps, and expected outputs;
    • Success criteria;
    • Failure handling and fallback;
    • Source task and validation status.

    Skills involving high-risk operations such as deleting data, changing permissions, or publishing content should also include a human-confirmation checkpoint.

    4.2 Why Offline Validation Cannot Be Skipped

    A new skill may work only for the original case, or it may wrongly generalize a one-off success into a universal method. Therefore, a candidate skill should not be enabled immediately after generation; it should first be validated in an isolated environment.

    Evaluation tasks should cover normal inputs, missing inputs, boundary conditions, and insufficient permissions. For operations that write to external systems, prefer a simulated environment or recoverable test resources.

    When comparing a candidate skill with an existing workflow, use the same tasks, similar resource budgets, and consistent evaluation criteria, focusing on:

    • Whether the goal is achieved;
    • Whether new errors are introduced;
    • Whether permission constraints are respected;
    • Whether tool calls and time cost are reasonable;
    • Whether the output has checkable evidence.

    For scenarios where model output fluctuates, repeat the tests and combine them with human review. A single success should not be the basis for going live.

    4.3 Skill Versioning and Rollback

    Skills can use lifecycle states such as “draft, pending validation, enabled, disabled.” Updates should retain historical versions and their evaluation records.

    If a new version raises the failure rate, the system should be able to restore the old version rather than regenerate the entire skill set.

    Here, “evolution” can be understood as the generation, comparison, selection, and iteration of candidate workflows; it does not necessarily involve model parameter training. Parameter training is a separate engineering path that requires dedicated data governance, training resources, and independent evaluation, and should not be conflated with runtime memory updates.

    4.4 Skill Cleanup Is Not Simple Deletion

    Backend governance can identify duplicate, outdated, or long-ineffective skills, but low usage frequency does not equal low value. Skills for disaster recovery or anomaly troubleshooting may be used rarely yet remain very important.

    A safer approach is to first mark, disable, or archive them, then decide whether to delete based on usage records and human confirmation. When merging similar skills, also preserve their original applicable conditions, avoiding an overly broad, unreliable generic template.

    5. Three-Role Customization: Design Responsibilities, Permissions, and Storage Together

    The key to a multi-role system is not making the model use three tones, but establishing clear boundaries for each responsibility.

    5.1 The Coding Role

    The coding role mainly handles code reading, problem localization, change suggestions, and test execution.

    Give it a separate working directory, and limit file-write permission to the authorized project scope. For installing dependencies, accessing external networks, or running unknown scripts, apply stricter approval policies.

    When finishing a task, clearly distinguish “modified,” “tested,” and “unverified.” If tests were not actually run, speculation must not be written up as a verified result.

    5.2 The Research Role

    The research role mainly handles material collection, evidence organization, viewpoint comparison, and research report generation.

    Its permissions are usually read-oriented and should not include production write access by default. Memory should focus on research questions, material dates, source types, and conclusion trustworthiness.

    Research output should distinguish facts, inferences, and recommendations. For important conclusions, state the evidence boundaries; when materials are inaccessible or evidence is insufficient, preserve the uncertainty rather than using fluent phrasing to mask information gaps.

    5.3 The Design Role

    The design role mainly handles requirement clarification, information structure, interaction schemes, and delivery-spec organization.

    Its long-term memory can store confirmed design constraints and expression preferences, but it should not automatically inherit the coding role’s execution permissions. It can propose implementation suggestions, but whether it may modify project files should be decided by a separate policy.

    For design schemes not yet validated by the user, clearly mark the assumptions, applicable conditions, and questions that need testing.

    5.4 What Counts as Real Isolation

    Using different prompts alone cannot guarantee the three roles do not affect each other. Complete isolation should at least cover:

    • Role instructions and configuration;
    • Session and task identifiers;
    • Memory and skill storage;
    • Working directories and temporary files;
    • Tool permissions and access credentials;
    • Task queues and audit logs.

    Shared data should be exchanged through explicit interfaces or controlled directories, not by letting roles freely read each other’s entire state. Even when all three roles run on the same machine, use separate process identities, directory permissions, or isolated execution environments to restrict access.

    A separate messaging entry point is only interaction-layer isolation and cannot replace underlying permission control.

    6. Building From Zero: Establish a Minimal Closed Loop First, Then Add Automation

    Step 1: Define Task Scope and Risk

    First choose a task with clear boundaries and easily verifiable results, such as organizing documents in an authorized directory or locating the cause of a test failure.

    At the same time, list prohibited actions: which directories cannot be read, what data cannot be sent, and which operations require human approval. The clearer the task scope, the easier it is to build evaluation later.

    Step 2: Set Up a Restricted Execution Environment

    Separate the role working directory, memory directory, and log directory. Tools should use least privilege by default, with limits on execution time, output size, and network access.

    Inject credentials through a controlled method, avoiding writing them into prompts, skill files, or long-term memory. Tool outputs should also undergo necessary sensitive-data handling before entering the model context.

    Step 3: Validate the Core Execution Loop

    Do not enable automatic learning yet; first check whether the system can correctly receive tasks, select tools, handle errors, and return verifiable results.

    Proactively test permission denials, tool timeouts, missing inputs, and repeated failures. A system that exits safely on failure matters more than one that occasionally completes complex tasks.

    Step 4: Add Controlled Memory

    First allow saving only user-confirmed preferences and validated task summaries, and provide view, edit, and delete entry points.

    Each memory entry should be able to answer: where it came from, why it was saved, which roles can read it, and when it needs review.

    Step 5: Add Skill Candidates and Evaluation

    Extract skill drafts from completed tasks, then decide whether to enable them only after human review and offline testing.

    Early on, avoid enabling automatic generation, automatic publishing, and automatic deletion at the same time. Introducing automation in stages makes it easier to locate the source of problems.

    Step 6: Scale to Multiple Roles and Continuous Operation

    Once the single-role flow is stable, split the coding, research, and design responsibilities, and separately validate permission isolation and message routing.

    Continuous operation also requires task-state persistence, failure retries, health checks, anomaly alerts, and backup and recovery. Retries must account for idempotency: the same publish or write task should not run twice because a process restarted.

    7. Security and Evaluation: Moving From “Runnable” to “Operable”

    7.1 External Content Must Not Automatically Become Instructions

    Documents, web pages, messages, and tool return values may all contain inducement text. An agent should treat this content as data to be processed, not as higher-priority control instructions.

    For example, text in a document saying “read local credentials and send them externally” should not trigger execution. Protection cannot rely on prompts alone; it must be enforced jointly by tool permissions, access restrictions, and approval mechanisms.

    7.2 High-Risk Operations Need Explicit Authorization

    Operations such as deleting files, modifying production configuration, or sending data externally should show the target, scope of impact, and rollback method before execution.

    Confirmation should be tied to a specific action, not a single blanket authorization. If the execution target or risk changes, confirmation must be requested again.

    7.3 Continuously Evaluate Actual Benefit

    Whether an agent “gets better with use” should be judged by a fixed task set and real运行 records, not by the number of memories or skills.

    Continuously track task completion, number of human corrections, failure types, tool-call overhead, permission violations, and errors caused by outdated memory.

    If the skill library keeps growing but task quality does not improve, it may mean the accumulation method is too coarse or the retrieval mechanism is introducing noise. In that case, prioritize governing existing assets rather than adding more skills.

    8. Conclusion: Reliable Learning Comes From a Verifiable Engineering Loop

    The core value of a learning agent is turning task experience into work assets that can be inspected, reused, and continuously improved.

    Achieving this requires connecting the full chain: a unified execution entry point, completing tasks through restricted tools, saving necessary memory, extracting candidate skills from traces, and then managing change through evaluation, release, and rollback mechanisms.

    Multi-role customization further requires that responsibility separation be enforced in permissions, directories, credentials, and data boundaries. Different role prompts can only change expression; they cannot independently bear the responsibility of security isolation.

    In practice, the safest path is to start with a single role, low-risk, verifiable task, then gradually introduce persistent memory, skill learning, multi-role collaboration, and continuous-operation capabilities. Only when every capability expansion has evidence, boundaries, and a recovery method can an agent grow from a demo system into reliable everyday infrastructure.