Skip to content

[FEATURE] Add RecordStart and RecordStop screen recording tools #1293

Description

@edenreich

Summary

Add two opt-in tools, RecordStart and RecordStop, so the agent can record the screen to an MP4 file. Like the built-in recorders on each OS (macOS Cmd+Shift+5, Windows Snipping Tool, GNOME screen recorder), the agent picks what to record: the entire screen, a single window, or a region (position plus width and height).

Use cases:

  • Unattended audit trail - record what the agent did on the machine while the user was away.
  • Tutorials - ask the agent to demonstrate a feature and keep the recording, scoped to just the app window or area that matters.

Proposed behaviour

  • RecordStart starts one recording and returns the target file path plus the captured rectangle. It takes an optional capture target:

    • mode: screen (default), window, or region.
    • window (only with mode=window): frontmost (default), app:<name>, pid:<number>, or a bare application name - the same syntax as the Computer tool's target.
    • region (only with mode=region): {x, y, width, height} in the frame coordinate space - the same shape and space as the Computer tool's screenshot region, so the agent can take coordinates straight from a screenshot or accessibility bounding box.
    {"mode": "screen"}
    {"mode": "window", "window": "app:Safari"}
    {"mode": "region", "region": {"x": 0, "y": 80, "width": 1280, "height": 720}}
  • If a recording is already running, RecordStart returns an error instead of starting a second one.

  • RecordStop takes no arguments. It stops the active recording, finalizes the file, and returns its path, duration, and size. If nothing is recording, it returns a clear error.

  • Output: ~/.infer/tmp/recordings/<timestamp>.mp4 (H.264, yuv420p, so it plays in browsers and QuickTime).

  • Max duration: 120s by default (configurable). When the cap is reached, the recording stops and is finalized on its own, and RecordStop still returns the file.

  • Graceful shutdown: when the CLI exits (normal exit, Ctrl+C, SIGTERM), an active recording is stopped and finalized, not left as a truncated/corrupt MP4 or an orphaned ffmpeg process.

  • Cross-platform: macOS, Linux (X11), Windows.

  • Disabled by default.

Implementation notes (reuse what already exists)

  • Config - add a recording section to computer_use.yaml (config/computer_use.go), next to screenshot, so it gets the existing env var mapping for free:

    computer_use:
      recording:
        enabled: false          # INFER_COMPUTER_USE_RECORDING_ENABLED
        max_duration: 120       # seconds, INFER_COMPUTER_USE_RECORDING_MAX_DURATION
        output_dir: ""          # empty = ~/.infer/tmp/recordings
        framerate: 24           # INFER_COMPUTER_USE_RECORDING_FRAMERATE; also pinned as the output rate (-r)

    Register the tools in internal/computer/tools.go only when computer_use.recording.enabled is true (the same way Computer depends on computer_use.enabled).

  • Encoder - use ffmpeg. internal/audio already resolves and downloads ffmpeg into ~/.infer/bin (BinaryStore, speech_to_text.ffmpeg_path), and internal/audio/recorder.go already builds per-OS ffmpeg capture arguments and stops ffmpeg gracefully. Reuse that instead of adding a new dependency.

    • Caveat (found while verifying feat(computer): add RecordStart and RecordStop screen recording tools #1304): the ~/.infer/bin fallback downloads the inference-gateway/binaries asset, which is an audio-only build on every OS (macOS/Windows --disable-everything, Linux --disable-libx264 --disable-libxcb): no H.264 encoder and no avfoundation / x11grab / gdigrab. Recording currently only works with a full ffmpeg on PATH (Homebrew, apt, ...). Tracked as a follow-up below.
  • Capture target -> one rectangle - each mode resolves to a rectangle when the recording starts, so there is only one capture path per OS:

    • screen: the full primary display (the same display the Computer tool sees).
    • region: validate against the frame bounds and scale from frame space to native screen pixels the way captureRegion in internal/computer/executor.go already does (ScaleAPIToScreen). Out-of-bounds or empty regions return the same kind of error as the screenshot action ("region [...] is outside the WxH frame space").
    • window: resolve the window's bounds when the recording starts. No matching window returns an actionable error. robotgo's purego build has no window-bounds API, so feat(computer): add RecordStart and RecordStop screen recording tools #1304 resolves them natively: macOS through a window action in the existing AX helper (needs the Accessibility permission), Linux through EWMH (_NET_ACTIVE_WINDOW / _NET_CLIENT_LIST_STACKING + WM_CLASS), Windows through GetForegroundWindow / DWM extended frame bounds (robotgo only maps an app name to pids).
    • On HiDPI/Retina displays ffmpeg captures physical pixels, so convert logical to physical coordinates (see scalePhysicalToLogical in internal/computer/infrastructure/display/robot_controller.go).
    • libx264 with yuv420p needs even width and height, so round the rectangle down to even numbers.
  • ffmpeg inputs per OS:

    OS Entire screen Region / window rectangle
    macOS -f avfoundation -i "<screen index>:none" (needs the Screen Recording permission) same input + -vf crop=W:H:X:Y (avfoundation has no region option)
    Linux (X11) -f x11grab -i $DISPLAY -f x11grab -video_size WxH -i $DISPLAY+X,Y
    Windows -f gdigrab -i desktop -f gdigrab -offset_x X -offset_y Y -video_size WxH -i desktop
  • Stopping - ffmpeg only writes the MP4 moov atom on a clean shutdown. Stop it by writing q to stdin, which works on every OS (os.Interrupt is not supported on Windows). Kill it only after a timeout.

  • Approval - RecordStart should follow computer_use.approval like the other observation actions. A visible status indicator in the TUI while a recording is running would be good.

Out of scope (follow-ups)

  • Following a window that moves or resizes during the recording. window mode records the window's bounds at start; anything that covers that area is recorded too. Native window capture (gdigrab title=, x11grab -window_id, ScreenCaptureKit on macOS) can come later.
  • Picking a non-primary display.
  • Wayland capture (x11grab does not work there; needs PipeWire/portal).
  • Audio capture, pause/resume, several recordings at once, automatic cleanup/retention of old recordings.
  • Headless RecordStart gated by at least the LLM judge: #1310.
  • A recording-capable ffmpeg for the ~/.infer/bin fallback (see the Encoder caveat above), or skip the download for recording and ask for a full ffmpeg on PATH.
  • Desktop app support: the Desktop runs each chat turn as a fresh infer headless --format ag-ui process, so a recording is finalized when the turn that started it ends and a RecordStop in a later turn finds nothing running. The REC status event is TUI-only (not emitted in AG-UI output), and Desktop settings have no computer_use.recording.enabled toggle.

Verification on #1304

  • macOS (avfoundation, Retina): screen, region, and window modes; the one-at-a-time guard; RecordStop with nothing running; the max_duration cap; finalize on Ctrl+C; headless start/stop and exit-while-recording. All produced playable H.264 yuv420p MP4s and left no ffmpeg running.
  • Linux X11 (Debian 12, Xvfb + openbox, ffmpeg 5.1): the same modes plus app:<name>, a missing window, no DISPLAY, and XDG_SESSION_TYPE=wayland. Found and fixed an output frame-rate drift (x11grab gave 23-26fps and duplicated frames) by pinning the output rate with -r.
  • Windows: not verified yet.

Acceptance Criteria

  • RecordStart / RecordStop are not registered unless computer_use.recording.enabled is true (and INFER_COMPUTER_USE_RECORDING_ENABLED=true enables them).
  • RecordStart with no arguments records the entire primary screen.
  • RecordStart with mode=region records exactly the given frame-space rectangle (scaled to native pixels, rounded to even dimensions). An out-of-bounds or empty region returns a clear error that includes the frame size.
  • RecordStart with mode=window records the bounds of the matched window (frontmost, app:<name>, pid:<number>, or an app name). No matching window returns a clear error.
  • RecordStart returns the file path and the captured rectangle.
  • RecordStart writes to ~/.infer/tmp/recordings/<timestamp>.mp4 (or the configured output_dir) and creates the directory if it does not exist.
  • RecordStop returns the path, duration, and size of a playable MP4 (checked with ffprobe).
  • A recording stops and finalizes on its own at max_duration (default 120s).
  • Calling RecordStart twice, or RecordStop with nothing recording, returns a clear error and does not break the active recording.
  • On CLI exit (normal exit, SIGINT, SIGTERM), an active recording is finalized and no ffmpeg process is left running.
  • Works on macOS, Linux (X11), and Windows in all three modes. If ffmpeg is missing or screen capture is not supported (for example Wayland, or no macOS permission), the tool returns an actionable error.
  • Unit tests cover the per-OS ffmpeg argument building for each mode (screen, region, window), frame-to-screen scaling and even-dimension rounding, region validation, the max-duration cap, and the single-active-recording guard.
  • docs/tools-reference.md and docs/configuration-reference.md document the tools, the capture modes, and the new config keys/env vars.

Activity

  1. added
    enhancement
    on Sep 23, 2026
  2. changed the title [-][FEATURE] Implement RecordStart(position) and RecordStop(position)[/-] [+][FEATURE] Add RecordStart and RecordStop screen recording tools[/+] on Sep 24, 2026
  3. moved this to Todo in 2026on Sep 24, 2026
  4. moved this from Todo to In progress in 2026on Sep 24, 2026
  5. moved this from In progress to QA in 2026on Sep 24, 2026
  6. added a commit that references this issue on Sep 25, 2026
    8718955
  7. inference-gateway-releaser commented on Sep 25, 2026

    @inference-gateway-releaser
    Contributor

    🎉 This issue has been resolved in version 0.208.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

  8. moved this from QA to Done in 2026on Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementreleased

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions