Learning Agent Architecture and Multi-Role Isolation: A Practical Guide

    A practical guide to learning agents that move beyond one-shot answers: a shared execution core with separate role state, layered memory, skill extraction with offline evaluation, and isolation, scheduling, and operations practices for long-running work.

    1. From Instant Answers to Continuous Work

    A typical conversational system mainly generates a response to the current input. An agent that keeps running also has to manage task state, call external tools, retain necessary context, and reuse experience that has already been validated in later tasks.

    Whether an agent is useful in practice therefore cannot be judged only by whether it can complete a one-off demo. More useful questions include:

    • After a task is interrupted, can it resume from the correct state?
    • After a long conversation, does it still retain key constraints?
    • After completing similar tasks several times, can it reduce repeated exploration?
    • When a tool fails, are retry and stop rules explicit?
    • Do different roles have separate data, permissions, and workspaces?
    • Is new experience validated before it affects later tasks, rather than applied immediately to every future task?

    Together, these questions point to one goal: a task-execution system with a feedback loop.

    It is important to distinguish storing memory, updating skill documents, and training model parameters. The first two can change agent behavior without modifying model parameters. Parameter training is a separate engineering pipeline that needs its own data governance, training process, and evaluation. Not every form of accumulated experience should be described as the model “automatically getting smarter.”

    2. Base Architecture: Shared Execution Core, Separate Entry Points and Runtime State

    A maintainable agent system can use an architecture with multiple entry points, one execution core, and independent role state.

    1. CLI / messaging / editor / scheduled jobs
    2. ↓
    3. Identity and request routing
    4. ↓
    5. Core execution loop
    6. ↙ ↓ ↘
    7. Memory layer Tool layer Skill layer
    8. ↓
    9. Workspace and audit records

    2.1 Entry points connect traffic; they should not reimplement business logic

    Each entry point usually only needs to authenticate identity, parse the request, select a role, convert message formats, and return results. Task decomposition, context assembly, tool execution, and error handling should be provided by the core execution layer whenever possible.

    This reduces behavioral drift. The same task started from a messaging entry point and from a command-line entry point should not apply different permission decisions just because two execution paths were implemented.

    Sharing core code does not mean sharing all runtime state. A role’s sessions, working directory, credentials, and memory must be managed separately so that code reuse does not break isolation boundaries.

    2.2 The core loop advances task state

    A common pattern alternates reasoning and action: assemble context, decide the next step, call a tool, observe the result, and then decide whether to continue or finish.

    The following is illustrative pseudocode only. It does not represent any real product interface:

    1. Receive the task
    2. Verify identity and permissions
    3. Load role rules, relevant memory, and candidate skills
    4. While the task is not finished:
    5. Check time budget, call budget, and cancellation signals
    6. Assemble the current context
    7. Compress context when necessary
    8. Generate the next action
    9. If the action is a tool call:
    10. Check tool permissions and arguments
    11. Run the tool and record the result
    12. Else:
    13. Return an answer or ask the user for more information
    14. Save the task result
    15. Extract candidate experience
    16. Submit candidate experience to evaluation

    A “continuous loop” must not mean unbounded execution. The system needs stop conditions, including timeout, exhausted budget, repeated failure, task completion, and explicit user cancellation. For operations with external side effects, execution state should also be recorded so that resuming a task does not send the same message or modify the same data again.

    2.3 Tool environments should be adapted through an abstraction layer

    Tools may run in a local working directory, an isolated container, or a remote execution environment. Core execution logic can stay relatively stable, but switching environments is not guaranteed to be fully compatible by changing a single setting.

    What should be unified includes:

    • Mapping rules for working directories and file paths
    • How environment variables and credentials are injected
    • Execution timeouts and resource limits
    • Standard output, error output, and exit status
    • File read, upload, and download mechanisms
    • Network access policy and cleanup procedures

    For code of unknown origin, batch file processing, or high-risk tasks, an isolated environment should be preferred. An agent deciding that code “looks safe” is not a substitute for real permission limits.

    3. Layered Memory: What to Store, When to Use It, and When to Delete It

    Appending the entire history to the prompt is not a reliable memory design. It raises context cost and lets stale or irrelevant content interfere with the current task.

    A better approach is to split memory by lifetime and purpose.

    3.1 Working memory: support the current task

    Working memory holds the current goal, constraints, recent tool results, and pending items. It mainly serves the task in progress.

    Its size should be bounded. Near the context limit, history can be compressed, but the compressed result must still preserve unresolved questions, important decisions, locations of key evidence, and actions already taken. In particular, “planned” must not be rewritten as “already completed.”

    For critical facts, keep original records that can be checked again, rather than relying only on a generated summary.

    3.2 Session memory: resume continuous work

    Session memory stores task stage, interaction summaries, and the information needed to resume. For example, a software-development role needs to remember files already changed and checks that failed. A research role needs to keep conclusions still to be verified and gaps in evidence.

    Session memory is not permanent memory. A temporary choice made during one task should not automatically become a long-term user preference.

    3.3 Long-term memory: keep stable, useful information

    Long-term memory can record confirmed preferences, project constraints that remain valid, and work experience worth reusing.

    Each record should preferably include its source, creation time, last confirmation time, scope, and expiry conditions. For sensitive information, it should also be explicit whether storage is allowed, which roles may read it, and when it must be deleted.

    When retrieving long-term memory, consider relevance, freshness, and trustworthiness together. Similarity to the current question does not mean a record is still correct.

    3.4 Updating and deleting facts matters as much as storing them

    A memory system must not only remember. It must also revise and forget. When a user changes a preference, project rules change, or credentials are revoked, old information should be updated or invalidated promptly.

    Deletion should also cover summaries, retrieval indexes, and other derived records. Otherwise, the original text may appear deleted while derived content still restores it.

    4. The Learning Loop: Turning Task Traces into Reusable Skills

    A skill can be understood as a structured description of how to perform a task. It typically includes applicability conditions, input requirements, steps, verification methods, and risk notes. It is not a saved successful conversation, and it is not an execution script that receives extra permissions by default.

    A sound skill-learning process can be split into five steps.

    Step 1: Identify tasks worth capturing

    Prefer tasks that recur, have relatively stable steps, and produce results that can be checked. Examples include inspecting a project directory layout, organizing research materials, or producing a design delivery checklist that follows a defined specification.

    Tasks that depend heavily on personal judgment and lack verification criteria can still be recorded as experience, but they should not be frozen lightly into a mandatory procedure.

    Step 2: Extract general steps

    Remove temporary paths, personal information, credentials, and accidental conditions from the task trace. Keep the steps that actually affect the outcome.

    A skill should state its scope clearly. A procedure for “checking document consistency,” for example, should not automatically become a general procedure for “all content review.”

    Step 3: Define acceptance criteria

    A skill must answer “what counts as done.” Acceptance criteria can be check results, file structure, citation completeness, or user confirmation—not the agent simply claiming success.

    The following is an illustrative skill structure:

    1. Skill name: Pre-delivery project check
    2. Applies when: Read access to the working directory has been granted
    3. Inputs: Project directory, delivery specification, check scope
    4. Steps:
    5. Identify the directory structure
    6. Check required files
    7. Run authorized verification actions
    8. Summarize missing items and failures
    9. Done when:
    10. Every required check has an explicit result
    11. Risk notes:
    12. Do not delete files or modify external resources without authorization

    Step 4: Validate offline before release

    A new skill should start as a candidate and enter the usable skill library only after it passes representative examples. Validation should check not only whether it succeeds, but also whether it raises cost, misses edge cases, or introduces unauthorized behavior.

    Step 5: Version skills and retire them deliberately

    A skill library keeps growing, so duplicates, conflicts, and expired content need to be handled. Usage and validation results can identify skills that may need cleanup, but a skill should not be deleted only because it was used rarely recently.

    A safer approach is to archive it first, keep versions and references, and only then decide whether to remove it completely. Critical skill updates should support rollback.

    5. Offline Optimization: Do Not Treat Accidental Success as a Capability Gain

    Offline optimization can apply to prompts, skill content, tool-selection policy, or task flow. The basic method is to generate candidate options, run them on a fixed evaluation set, compare results, and then decide whether to adopt a candidate.

    Evaluation should cover at least:

    • Effectiveness: whether the task meets acceptance requirements
    • Reliability: whether results stay stable across different inputs
    • Efficiency: whether call count, runtime, and resource use are reasonable
    • Safety: whether unauthorized access, leakage, or dangerous actions appear
    • Recoverability: whether failures can be located and execution resumed

    Do not optimize and accept changes only against the same development examples. That easily overfits those examples. Keep a separate test set, and include abnormal inputs, tool failures, and insufficient context in evaluation.

    If parameter training is considered later, data authorization, redaction, quality filtering, and post-training regression tests are additional requirements. For most individuals and small teams, improving memory, skills, and evaluation first is usually easier to control in cost and risk than introducing parameter training immediately.

    6. Isolation in Practice for Three Roles

    Software development, in-depth research, and design collaboration can share the same core architecture, but they should have separate configuration, storage, and permissions.

    6.1 Software development role

    Responsibilities include understanding requirements, changing code, running checks, and summarizing changes.

    Default permissions should be limited to a designated working directory. Deleting files, installing dependencies, changing the runtime environment, or publishing changes should require confirmation according to risk level.

    Its long-term memory should mainly store project conventions and confirmed technical constraints. It should not store access tokens or unverified guesses about failures.

    6.2 In-depth research role

    Responsibilities include breaking down research questions, organizing sources, comparing viewpoints, and producing reports supported by evidence.

    It needs to distinguish facts, inferences, and information still to be verified. Memory should store source location, retrieval time, and applicable context so that outdated material is not treated as a current fact.

    External material is only an information source. It must not gain the power to change system permissions or execution rules.

    6.3 Design collaboration role

    Responsibilities include clarifying design goals, maintaining visual constraints, organizing options, and checking deliverables.

    Its memory should emphasize audience, layout, color, content hierarchy, and preferences the user has confirmed. Generated options still need checks for readability, consistency, and delivery specifications. Subjective praise is not a substitute for acceptance.

    6.4 Isolation must be enforced at resource boundaries

    Using three different role prompts does not create real isolation. At a minimum, manage separately:

    • Sessions and long-term memory
    • Skill libraries and permission to publish skills
    • Working directories and temporary files
    • Messaging credentials
    • Tool permissions and network access scope
    • Audit records and resource budgets

    Material shared across roles should go through an explicitly authorized common knowledge area. Sensitive tasks also need isolation at the process, file-system, or execution-environment level, not reliance on the agent voluntarily staying inside a boundary.

    7. Continuous Operation: Scheduling, Security, and Operations Are All Required

    Being available around the clock does not mean the model must reason continuously. A more common pattern is to wait for a message or a scheduled event, run the task when the trigger fires, and return to waiting when it finishes.

    To avoid duplicate execution, the scheduler should store task identifiers and state, and design idempotency controls for operations with external side effects. On failure, distinguish retryable errors from non-retryable errors so the same action is not repeated without limit.

    For security, follow least privilege. Retrieved documents, web content, and tool output are untrusted input and must not override system rules. Actions that send data externally, delete data, incur cost, or change permissions should have explicit approval points.

    For operations, at least record the task trigger source, key decisions, tool calls, errors, and final result, while avoiding full sensitive content in logs. Monitoring should watch task backlog, repeated failures, abnormal call volume, and storage growth—not only whether the process is alive.

    Land the system as a small closed loop first, then expand:

    1. Finish a single-role execution path: confirm request intake, tool calls, result return, and cancellation work.
    2. Add task recovery: verify that interruption does not lose critical state or repeat dangerous actions.
    3. Add controlled memory: support source tracking, user corrections, deletion, and expiry.
    4. Add a candidate-skill and evaluation flow: keep unvalidated experience out of production use.
    5. Expand multi-role isolation: check that data, credentials, and permissions do not leak across roles.
    6. Add continuous scheduling last: add budgets, retries, alerts, and backup and recovery.

    Acceptance should not check only one successful path. Also test tool timeouts, bad input, expired memory, duplicate messages, malicious material, insufficient permissions, and user cancellation.

    The real value of a learning agent is not accumulating as much history as possible. It is turning effective experience into work capability that can be retrieved, verified, and revoked. The execution loop moves tasks forward, the memory layer provides continuity, the skill library reduces repeated exploration, evaluation controls quality, and permissions and isolation determine how safely the system can run. Only when these parts form a closed loop can an agent become a reliable long-term working assistant.