Agent Engineering: A Practical Guide to Runtime Constraints and Knowledge Accumulation

    This article explains how to treat LLM agents as engineered systems rather than relying on model inference alone. It covers the four core layers of a runtime harness—context management, tool calling and orchestration, permissions and security boundaries, and state persistence—with an illustrative code skeleton. It also discusses using LLMs to maintain a personal knowledge base, preventing source map leakage in release artifacts, and a practical implementation checklist.

    1. Design Agents as Engineered Systems

    LLMs can handle increasingly complex tasks, but most production issues do not come from model inference itself. They come from the runtime environment around the model: whether context is controllable, whether tool calls are auditable, whether failures can be recovered, and whether high-risk actions have human oversight. This runtime constraint layer built around the model is often called a harness. The same model can perform very differently under different runtime constraints.

    Understanding this has two direct benefits. First, teams expand their focus from repeatedly tuning prompts to designing runtime structure. Second, system reliability can be verified item by item through code, configuration, and process, rather than hoping the model makes the right judgment every time.

    2. Four Core Layers of a Runtime Framework

    2.1 Context Management

    The model’s context window is limited. As a task grows longer, early information can be pushed out or diluted. Engineering practice commonly uses three approaches:

    • Layered loading: system instructions remain persistent, task instructions are injected on demand, and large files are passed only as summaries and location information.
    • Rolling summaries: when conversation history exceeds a threshold, completed steps are compressed into structured state.
    • External memory: key decisions and intermediate results are written to files or databases and retrieved when needed.

    More context is not always better. Irrelevant information can interfere with reasoning and also increase cost and latency. Context should have an explicit token budget, and compression should be triggered when the budget is exceeded.

    2.2 Tool Calling and Orchestration

    Tools are the interface through which agents interact with the external world. Each tool should have a clear input schema, parameter validation, timeout and retry policies, and structured return values. Tool outputs are data and should not be executed directly as new instructions. This is especially important when reading external content such as web pages, files, or emails. Otherwise, malicious text embedded in that content could induce the model to perform operations beyond its permissions.

    The orchestration layer decides the order of calls. It can be a fixed pipeline or model-driven planning under constraints. Core business flows are better suited to fixed pipelines because they are more predictable. Exploratory tasks are better left to model planning, but should be paired with stricter step limits and termination conditions.

    2.3 Permissions and Security Boundaries

    The principle of least privilege is a basic requirement: an agent should receive only the tools and data scope needed to complete the current task. Irreversible operations such as deletion, sending, deployment, and permission changes should include human confirmation nodes. Permission policies should be written in code or configuration, not only in prompts, because prompts cannot provide enforceable guarantees.

    2.4 State Persistence and Recoverability

    Long-running tasks may fail due to network fluctuations, rate limits, or process interruptions. Writing the input, output, and state of each step to persistent storage enables resume-from-checkpoint execution and also supports later auditing. State records should include the task identifier, current step, completed actions, pending confirmations, and failure reason. When resuming execution, the system should first validate whether completed actions are still valid before deciding whether to skip them.

    3. An Illustrative Code Skeleton

    The following code is intended to illustrate structure and does not correspond to the interface of any specific framework:

    1. class AgentRunner:
    2. def __init__(self, model, tools, policy, store):
    3. self.model = model
    4. self.tools = tools # name -> tool object
    5. self.policy = policy # permission and confirmation rules
    6. self.store = store # state persistence
    7. def run(self, task_id, goal):
    8. state = self.store.load(task_id) or {"steps": [], "done": False}
    9. context = build_context(goal, state, budget=self.policy.max_tokens)
    10. while not state["done"]:
    11. action = self.model.plan(context)
    12. if not self.policy.allows(action):
    13. action = self.request_human_approval(action)
    14. result = self.tools[action.name].invoke(action.args, timeout=30)
    15. state["steps"].append({"action": action.name, "result": result})
    16. self.store.save(task_id, state)
    17. context = compress(context, state)
    18. state["done"] = self.model.is_finished(state)
    19. return state

    This skeleton illustrates several points: permission checks occur before execution, every step is persisted, context is compressed after each round, and the loop has an explicit termination condition. A real system would also need timeout handling, error classification, and log redaction.

    4. Maintaining a Personal Knowledge Base with LLMs

    Knowledge management is a good fit for agents. A practical approach can be divided into four layers:

    1. Raw source layer: articles, papers, data files, and images are archived together with source URLs and acquisition time.
    2. Compilation layer: the model generates a summary for each source, categorizes content by concept, writes entries, and creates cross-links.
    3. Index layer: an overview index and a brief description of each document are maintained so the model can quickly locate relevant content.
    4. Output layer: Q&A results, charts, and slides are generated as files for human review and further processing.

    At a small scale, index files plus document summaries are often enough to support Q&A. As scale grows, retrieval-augmented approaches can be introduced, but the bottleneck of the simple approach should be validated first before deciding whether to add complexity.

    Two caveats are important. First, model-generated content may contain factual deviations, and key conclusions should be checked against the original sources. Second, knowledge base maintainers should clarify which content is written by humans and which is generated by models, to avoid source confusion and support later tracing and revision.

    5. Information Leakage Risk in Published Artifacts

    When publishing frontend projects or command-line tools, one common risk is that debug mapping files (source maps) are accidentally included in the release package. These files record the correspondence between minified code and original code, and can restore obfuscated code to approximate source code, exposing internal implementation and comments. Similar incidents in the industry show that this problem is not uncommon, and a single oversight can cause impact.

    Mitigations include the following:

    • Disable source map output for production in the build configuration, or upload it only to an internal error monitoring system.
    • Add a check step to the release pipeline that scans the artifact directory for mapping files and sensitive strings.
    • Audit the content manifest of the release package and confirm that no extra files have been packaged.
    • Automatically scan for secrets, tokens, and internal domains, and block the release when any are found.

    The following check command can be used as a step in the pipeline:

    1. if find dist -name "*.map" | grep -q .; then
    2. echo "Source map files found; release blocked"
    3. exit 1
    4. fi

    6. Implementation Checklist

    • Does context have a token budget, and is compression triggered when it is exceeded?
    • Does each tool define input validation, timeout, and error returns?
    • Are high-risk operations subject to permission policies and human confirmation?
    • Is long-task state persisted at each step, and can it be recovered from an interruption point?
    • Is knowledge base content source-labeled, and are key conclusions manually verified?
    • Are release artifacts scanned for source maps and sensitive information?