AI Agent Execution Layer Design: Presets, Sessions, and Plugins

    An AI agent’s execution layer turns model outputs into controlled actions. This article examines task-specific presets, reasoning controls, recoverable sessions, context management, plugins, multi-agent orchestration, and security boundaries. It also outlines evaluation metrics and a phased implementation approach for building an observable, recoverable agent runtime.

    1. Beyond the Model: What the Execution Layer Enables

    Large language models interpret intent and generate content, but they cannot independently read or write files, run commands, save progress, or call external services. An execution layer around the model makes these capabilities available. It translates model outputs into controlled actions, records the results of each step, and determines whether a failure requires a retry, a rollback, or human intervention.

    This layer is often called an agent runtime, orchestration framework, or agent workbench. Whatever the name, it typically has five responsibilities:

    1. Task scheduling: Break down user goals and order steps according to their dependencies.
    2. Tool invocation: Map structured model requests to specific functions and validate their arguments.
    3. Context management: Control how much information reaches the model on each call to stay within its context window.
    4. State persistence: Save sessions, intermediate artifacts, and execution logs so interrupted work can resume.
    5. Permission control: Restrict the directories, networks, and system capabilities the agent can access.

    As model capabilities improve, execution-layer engineering often becomes a major factor in the user experience. The same model can behave quite differently across runtimes, largely because of differences in context organization, error handling, and state management.

    2. Task-Specific Agent Presets

    Using one configuration for every task creates two problems. Simple tasks incur unnecessary overhead, such as retrieval and planning. Complex tasks may lack essential components, such as isolated subtasks or dynamically loaded skills.

    A practical approach is to provide multiple presets, each defining a set of capability switches and parameters.

    A typical preset specifies:

    • Whether context compression and summarization are enabled
    • Whether web search is allowed
    • Which skill packages or external plugins are loaded
    • Whether explicit planning and task lists are enabled
    • Whether the agent can spawn sub-agents
    • The maximum number of steps and task timeout

    The following example illustrates four common presets:

    1. presets:
    2. minimal: # Small changes and quick checks
    3. compression: false
    4. web_search: false
    5. skills: []
    6. planning: false
    7. sub_agents: false
    8. max_steps: 20
    9. standard: # Everyday development and documentation
    10. compression: true
    11. web_search: false
    12. skills: [code_edit, test_runner]
    13. planning: true
    14. sub_agents: false
    15. max_steps: 60
    16. research: # Research and information synthesis
    17. compression: true
    18. web_search: true
    19. skills: [web_reader, summarizer]
    20. planning: true
    21. sub_agents: false
    22. max_steps: 100
    23. orchestrated: # Large, multi-module tasks
    24. compression: true
    25. web_search: true
    26. skills: [code_edit, test_runner]
    27. planning: true
    28. sub_agents: true
    29. max_steps: 200

    The minimal preset deliberately disables compression, search, skills, planning, and sub-agents. Its value lies in a short, predictable execution path with low overhead—appropriate for changing a single function or checking a piece of logic.

    Choosing a preset is effectively an estimate of task complexity. If that estimate is wrong, users should be able to switch presets without rebuilding the session.

    3. Configurable Reasoning Effort

    Reasoning effort controls how much internal reasoning the model applies before producing an answer. Greater effort can improve accuracy on complex problems, but it also tends to increase latency and token consumption. The execution layer should therefore expose reasoning effort as a user-adjustable setting with clearly defined levels.

    A runtime might offer three or four levels, such as off, high, and maximum. The levels should have clear use cases:

    1. Off: Suitable for predictable tasks such as format conversion, renaming, and simple completion.
    2. High: A balanced default for most coding and analytical tasks.
    3. Maximum: Reserved for cross-file reasoning, difficult bug investigations, or architectural comparisons, with a correspondingly longer timeout.

    Reasoning levels should work alongside presets. For example, minimal can disable deep reasoning by default, while orchestrated can default to a higher level. Users should still be able to override these settings.

    This keeps simple tasks inexpensive while preserving control over complex work.

    4. Reconstructable Sessions

    A session is the basic unit of agent work. A reliable session system should support two operations: reconstructing state from persisted data and branching into a new execution path from a historical point.

    A common implementation combines event sourcing with snapshots. Each model interaction, tool invocation, and user input is recorded as an append-only event. The current state is periodically saved as a snapshot. Recovery loads the latest snapshot and replays subsequent events.

    1. from dataclasses import dataclass, field
    2. from typing import Any
    3. @dataclass
    4. class Event:
    5. seq: int
    6. kind: str # "user_input" | "model_output" | "tool_call" | "tool_result"
    7. payload: dict[str, Any]
    8. @dataclass
    9. class Session:
    10. session_id: str
    11. events: list[Event] = field(default_factory=list)
    12. snapshot: dict[str, Any] | None = None
    13. snapshot_seq: int = 0
    14. def append(self, kind: str, payload: dict[str, Any]) -> None:
    15. self.events.append(Event(seq=len(self.events) + 1, kind=kind, payload=payload))
    16. def rebuild_state(self) -> dict[str, Any]:
    17. state = dict(self.snapshot or {})
    18. for event in self.events:
    19. if event.seq <= self.snapshot_seq:
    20. continue
    21. state = apply_event(state, event) # Update state according to the event type
    22. return state
    23. def fork(self, at_seq: int, new_id: str) -> "Session":
    24. kept = [e for e in self.events if e.seq <= at_seq]
    25. return Session(session_id=new_id, events=kept)

    This design offers three benefits.

    First, after a process crash or network interruption, the runtime can reconstruct progress through the last complete event rather than starting over.

    Second, branching lets users return to an earlier step, change instructions or presets, and run a different path while preserving the original for comparison.

    Third, the event log provides an audit trail for investigating how the agent reached a decision.

    Replay must be deterministic. If a tool depends on external state, such as the current time or a remote API response, its result should be stored in the event payload. Replay should use the recorded value rather than invoke the tool again.

    5. Context Compression and Retrieval

    Context windows are finite, while conversation history, file contents, and tool outputs grow throughout a long task. Without active management, earlier constraints may fall out of the model’s effective context, reducing reasoning quality.

    Execution layers typically combine three techniques.

    Truncation and Summarization

    Replace older tool outputs with structured summaries that retain details such as file paths, key function names, and error types. Discard the original long text from the active context, but preserve references that allow it to be retrieved.

    Summarization should use a separate small model or rule-based process.

    On-Demand Retrieval

    Rather than placing an entire repository in context, retrieve relevant snippets from an index for each query. The index can use keywords, symbol tables, vector similarity, or a combination of these approaches.

    Fixed Context Anchors

    Keep the task objective, user constraints, permission rules, and current plan in stable positions in the context, outside the compression process. This helps the model retain its purpose even when much of the history has been condensed.

    Compression also needs an explicit trigger policy. A common approach is to start when token usage exceeds a chosen proportion of the context window, leaving enough room for the compressed output.

    Compression operations should themselves be recorded in the event log to support auditing and rollback.

    6. Extending Capabilities with Plugins and Skills

    An execution layer’s capabilities depend on the tools it can access. Plugins allow internal teams or third-party developers to add capabilities without changing the runtime’s core code.

    A skill is a higher-level package, typically containing instructions, scripts, and activation conditions that tell the agent when to load it.

    A plugin system should follow several principles:

    • Declarative manifests: Each plugin supplies a descriptor listing its name, version, tools, required permissions, and parameter schemas. The runtime uses this information for registration and validation.
    • Validation before execution: Validate argument types and value ranges before running a tool. Return invalid requests to the model with an error so it can correct them.
    • Isolated execution: Run plugins in separate processes or restricted environments, with timeouts and resource quotas managed by the execution layer.
    • On-demand loading: Inject skill instructions into context only when their activation conditions are met, avoiding unnecessary context consumption.

    The following example illustrates a plugin manifest:

    1. {
    2. "name": "repo-test-runner",
    3. "version": "1.2.0",
    4. "tools": [
    5. {
    6. "name": "run_tests",
    7. "description": "Run unit tests in the specified directory and return a failure summary",
    8. "parameters": {
    9. "path": {"type": "string", "required": true},
    10. "timeout_sec": {"type": "integer", "default": 120}
    11. }
    12. }
    13. ],
    14. "permissions": ["fs.read", "process.spawn"]
    15. }

    Permission declarations are a critical part of the manifest. The execution layer should grant only declared capabilities and display the permission list when the user first enables the plugin.

    7. Multi-Agent Orchestration

    A single agent working on a long task can accumulate context noise: information from earlier exploration may distort later judgments. Multi-agent orchestration reduces this problem through role separation and isolated contexts.

    Three common patterns are:

    1. Planner and executor: The planner produces a sequence of steps. The executor completes them and returns a condensed result after each step.
    2. Main agent and sub-agents: The main agent delegates independent subtasks to sub-agents, each with its own context. Sub-agents return result summaries.
    3. Executor and validator: After the executor makes changes, the validator assesses test results and code review findings. Failed validation sends the work back for revision.

    Context isolation is central to these patterns. The main agent receives conclusions and artifact references, not the sub-agent’s full exploration history. This limits the size of the main context and reduces interference between subtasks.

    The orchestration layer must also manage concurrent changes. If multiple sub-agents modify the same file, their results can be difficult to merge. A safer approach is to give each sub-agent an independent working copy or branch, then let the main agent consolidate the results and request human confirmation for conflicts.

    8. Permissions and Security Boundaries

    Agents can execute commands, modify files, and access networks, so their permission model requires stricter controls than a conventional chat application.

    Following the principle of least privilege, the execution layer should provide:

    • Workspace isolation: Restrict file access to user-designated directories by default, blocking reads and writes outside those boundaries.
    • Command allowlists: Limit executable system commands. High-risk operations—such as deletion, forced overwrites, or permission changes—must require user confirmation.
    • Network egress controls: Determine network access by preset and record the destination of every external request.
    • Credential isolation: Inject credentials through environment variables or a secrets management service, keeping them out of session logs and model context.
    • Reversible operations: Create snapshots before modifying files so changes can be rolled back easily.

    Permission policies should be tied to presets. A minimal preset should not grant network or subprocess capabilities, while an orchestrated preset requires more granular approval workflows.

    Permission changes should also be recorded in the event log.

    9. Metrics for Evaluating the Execution Layer

    Evaluation should cover more than whether an agent eventually completes a task. Process quality matters as well.

    The following metrics provide a useful baseline:

    1. Task completion rate: The proportion of successful tasks on a fixed test set, grouped by preset.
    2. Average step count and elapsed time: Measures of execution efficiency that can reveal unproductive loops.
    3. Tool-call error rate: The proportion of argument validation failures and runtime exceptions, helping identify plugin quality issues.
    4. Context utilization rate: The proportion of retrieved snippets that the model actually cites.
    5. Recovery success rate: The proportion of successful snapshot-based recoveries after simulated interruptions.
    6. Human intervention count: The number of confirmation requests per task, helping assess whether permission policies are too restrictive or too permissive.

    Report these metrics separately for each preset. If minimal has a stable completion rate while orchestrated varies significantly, orchestration logic or task decomposition may need improvement rather than the underlying model.

    10. A Phased Implementation Approach

    Build an execution layer in stages.

    Phase 1: Implement a single agent, one preset, and a basic toolset. Establish the event log early, prioritizing observability and recoverability.

    Phase 2: Introduce reasoning levels, context compression, and plugin manifests while strengthening permission controls.

    Phase 3: Add multi-agent orchestration and more complex skills, supported by a complete evaluation pipeline.

    Each phase should use reproducible test tasks as acceptance criteria. Execution-layer complexity grows quickly. Expanding capabilities without adequate logging and clear permission boundaries makes failures harder to diagnose and their impact harder to contain.