Extending the Agent Runtime: Vision Capabilities, Two-Phase Reasoning, and Mobile Remote Access

    This article explores how to extend an open, plugin-based agent runtime without modifying its core. It covers three practical areas: adding image understanding to text-only models through a vision-to-text pipeline, improving output stability with a two-phase plan-and-execute pattern, and enabling secure mobile remote collaboration through pairing codes, message signing, and layered permissions. It also discusses general principles for plugin design, input preprocessing, and security boundaries, with illustrative code examples for each pattern.

    1. Background

    The agent runtime is responsible for orchestrating model inference, tool calls, context management, and interaction with the external environment. Recently, more and more teams have adopted open runtimes: the core handles only scheduling, while all concrete capabilities are mounted as plugins. This design is highly extensible, but it introduces a practical problem: the default configuration rarely delivers ideal results out of the box.

    Developers typically encounter three categories of pain points.

    First, the default system prompt and tool set may not fit the specific task, so output quality fluctuates. The model must decide on its own which tool to use and in what order; the longer the task, the more easily deviations accumulate.

    Second, model capabilities may not match task requirements. Many reasoning models only accept text input and cannot directly read screenshots, photos of tables, or UI prototypes, even though these materials are extremely common in day-to-day development.

    Third, usage is confined to the desktop terminal. When developers are away from their machines, they may want to check task progress or add an instruction, but they have no access to the running environment.

    This article uses these three problems as a thread to discuss how to fill capability gaps at the configuration layer and the plugin layer, while keeping the core code upgradeable.

    2. Basic Principles of Plugin-Based Extension

    In an open runtime, extensions generally have three landing points, each suited to different types of requirements.

    • Configuration layer: Switch inference parameters, tool visibility, and system prompts through profiles or environment variables. This has the lowest cost and is suitable for adjusting behavioral strategies.
    • Plugin layer: Register new tools, new commands, or new UI components that are scheduled uniformly by the runtime. Suitable for adding capabilities such as image parsing, remote communication, and task boards.
    • External service layer: Move heavy workloads like vision recognition and index building into separate processes or services, invoked through standard protocols. Suitable for capabilities that are resource-intensive or need independent scaling.

    When implementing extensions, follow these three principles.

    Principle 1: Do not modify the core. When the core version is upgraded, plugins can keep working as long as they depend on stable extension interfaces. If a team maintains a fork, every upgrade requires re-merging, which is very costly in the long run.

    Principle 2: Tool descriptions are the interface. The model makes decisions based on tool names, parameter descriptions, and return formats. Vague descriptions lead to tool misuse; precise descriptions usually improve call accuracy noticeably. Descriptions should clearly state the applicable scenarios, required parameters, and the form of the return value on failure.

    Principle 3: Failures must be visible. When an extension fails, it should return a structured error including the error type, the cause, and a flag indicating whether the operation is retryable. Silently swallowing exceptions hides problems and makes troubleshooting the most time-consuming part later.

    Below is an illustrative tool declaration showing the elements a description should contain. This is a generic pattern and does not correspond to the interface of any specific framework.

    1. # Illustrative code: describing an image analysis tool declaratively
    2. ANALYZE_IMAGE_TOOL = {
    3. "name": "analyze_image",
    4. "description": (
    5. "Read an image and return a textual result. "
    6. "Suitable for OCR, UI troubleshooting, and extracting data from charts."
    7. ),
    8. "parameters": {
    9. "image_path": {"type": "string", "required": True,
    10. "description": "Local path of the image; only files inside the workspace are allowed"},
    11. "prompt": {"type": "string", "required": False,
    12. "default": "Describe the image content in detail",
    13. "description": "Analysis instruction, e.g., 'extract all text line by line'"},
    14. },
    15. "returns": {"type": "string", "on_error": "structured error object"},
    16. }

    3. Adding Image Understanding to a Text-Only Model

    The common approach to let a text-only model “see” images is vision-to-text conversion: a vision model first converts the image into structured text, and that text is then passed to the main model as context. In this way, the main model can leverage information from images without needing multimodal capabilities itself.

    3.1 Call Flow

    A complete image analysis typically involves the following steps:

    1. The main model determines that the current task requires inspecting an image and calls the image tool.
    2. The tool reads the file and validates its format, size, and resolution, failing fast if limits are exceeded.
    3. Based on the task intent, it assembles an analysis instruction, such as “extract all numbers from the table” or “identify the clickable elements in the UI.”
    4. It invokes the vision backend and obtains a textual result.
    5. The result is written back into the conversation as the tool’s return value for the main model to continue reasoning.

    The analysis instruction in step 3 is critical. The generic default “describe the image” instruction often misses details. Text extraction, UI diagnosis, and translation each need their own instruction templates. It is recommended to design the analysis instruction as an optional parameter and provide common templates in the documentation so callers can choose as needed.

    3.2 Choosing a Vision Backend

    The vision backend can be a cloud-based multimodal service or a locally deployed vision model; each has its own trade-offs.

    • Cloud services generally offer stronger recognition capabilities and consume no local compute, but images leave the local machine, so data compliance requirements must be evaluated.
    • Local models offer better privacy and controllable latency, but they require GPU memory and an inference framework, and recognition quality is limited by model size.

    From an engineering perspective, the backend should be abstracted behind a unified interface so that upper-layer logic is decoupled from any specific service. Switching backends then only requires replacing the implementation, with no changes to callers.

    1. from typing import Protocol
    2. class VisionBackend(Protocol):
    3. """Unified interface for vision backends; both cloud and local implementations follow this contract."""
    4. def describe(self, image_bytes: bytes, prompt: str) -> str: ...
    5. def analyze_image(path: str, prompt: str, backend: VisionBackend) -> str:
    6. data = load_and_validate(path) # Validate type and size, and strip metadata
    7. return backend.describe(data, prompt)

    3.3 Input Preprocessing and Security

    Before an image enters the model, the following processing should be completed.

    • Format and size validation: Reject unsupported formats; compress oversized files or reject them outright to avoid exhausting memory.
    • Metadata stripping: Some images contain information such as capture location or device serial numbers, which should be removed before sending.
    • Path constraints: Only allow reading files inside the workspace to prevent path traversal into sensitive directories.
    • Treat content as data: Text inside an image may contain phrases like “ignore previous instructions.” The model should interpret image recognition results as data, not execute them as instructions.

    4. Two-Phase Reasoning Mode

    The more tools there are, the more easily the model gets distracted in the first turn. It must first choose among a large number of tools before it can enter real task understanding, which often results in unclear plans and skipped steps. An effective approach is to split a task into two phases.

    • Planning phase: Expose only a small set of necessary tools with a concise system prompt. The model’s job is to clarify the goal, break it into steps, list required materials, and output a plan.
    • Execution phase: Once the plan is confirmed, open the full tool set to perform file modifications, run commands, and verify results.

    This design offers two benefits. First, planning quality is more stable because the model’s attention is focused on the task itself. Second, the execution phase has a clear boundary: users can approve write operations only after confirming the plan.

    The costs are equally clear. Two phases mean one extra interaction; the state must store the plan; and the handoff between the planning result and the execution process needs handling—for example, how to fall back to the planning phase when the plan becomes invalid midway.

    1. from enum import Enum
    2. class Phase(Enum):
    3. PLAN = "plan" # Minimal tool set, planning only
    4. EXECUTE = "execute" # Full tool set, execute according to the plan
    5. READ_ONLY_TOOLS = ["read_file", "analyze_image", "list_directory"]
    6. ALL_TOOLS = READ_ONLY_TOOLS + ["write_file", "run_command", "apply_patch"]
    7. def tools_for(phase: Phase) -> list[str]:
    8. return READ_ONLY_TOOLS if phase is Phase.PLAN else ALL_TOOLS

    When evaluating this kind of pattern, do not rely on subjective impressions. It is recommended to fix a set of representative tasks, run them under both single-phase and two-phase modes, and record task completion rate, number of steps, elapsed time, and manual correction count. Use the data to decide whether to enable the pattern.

    5. Mobile Remote Collaboration

    Checking progress and adding instructions while away from the desk is a real need for developers. Remote collaboration typically consists of three parts: the runtime running on the local machine, a relay service responsible for forwarding messages, and a mobile web page.

    Local runtime ⇄ Relay service ⇄ Mobile page

    5.1 Pairing Mechanism

    Pairing is the first gate of remote collaboration. A common approach is to generate a one-time pairing code on the local machine; the user then scans a QR code or enters the code on the phone to complete binding. Keep the following points in mind when designing it.

    • The pairing code must be randomly generated and have a short validity period.
    • Each pairing code can be used only once and is invalidated immediately after use.
    • The binding must record a device identifier and support viewing and revoking bound devices from the local machine.
    1. import secrets
    2. import time
    3. def issue_pairing_code(ttl_seconds: int = 300) -> tuple[str, float]:
    4. """Generate a one-time pairing code and return the code with its expiration timestamp."""
    5. code = secrets.token_urlsafe(16)
    6. expires_at = time.time() + ttl_seconds
    7. return code, expires_at

    5.2 Transport and Signing

    Remote messages should be encrypted with TLS end to end. At the application layer, each instruction should also carry a signature and a timestamp; the receiver verifies the signature and rejects expired messages to prevent replay attacks. Session keys should be negotiated after successful pairing and destroyed when the session ends.

    5.3 Layered Permissions

    The most easily overlooked risk on mobile is that it holds the same permissions as the desktop. Layered permissions are recommended:

    • Read-only operations: Viewing task status, reading output logs, and browsing change summaries—allowed by default.
    • Write operations: Adding instructions, confirming plans, and triggering builds—require user confirmation.
    • High-risk operations: Performing deletions, modifying permissions, and running unknown commands—should be disabled by default or require secondary confirmation on the local machine.

    5.4 Boundaries of the Relay Service

    The relay service only needs to forward encrypted messages. It should not hold plaintext source code, access credentials, or user data. This way, even if the relay service is compromised, attackers cannot directly obtain workspace content. Likewise, logs should not record message bodies—only timestamps, device identifiers, and operation types.

    6. Supporting Capabilities: Task Boards, Diff Views, and State Traceability

    When an agent executes long