Overview
Concrete function that intercepts model input items, strips base64 image data from screenshot tool results, and injects transient user-image messages for vision-capable LLMs.
Description
The shapeScreenshotItems function is a model input filter applied before every model call. For each `function_call_result` item from a screenshot tool (`capture_screenshot`, `capture_screenshot_with_highlight`, `capture_tab_screenshot`), it parses the output JSON, extracts the `imageData` field if `sendToLLM=true`, replaces it with a placeholder string, and inserts a transient user message containing the real image as `input_image` content. Transient messages are marked with `__transient_screenshot__` in `providerData` so they can be pruned before persistence or compression via `pruneTransientScreenshotItems`.
Usage
- During agent execution: automatically called by `runExecution` via `callModelInputFilter`.
- Before persistence: call `pruneTransientScreenshotItems` to remove transient image messages from session history.
- Check if item is transient: use `isTransientScreenshotItem`.
Code Reference
Source Location
- Repository: AIPex
- File: packages/core/src/utils/screenshot-shaping.ts
- Lines: L40-128 (shapeScreenshotItems), L134-150 (pruneTransientScreenshotItems)
Signature
export function shapeScreenshotItems(items: AgentInputItem[]): AgentInputItem[]
export function pruneTransientScreenshotItems(items: AgentInputItem[]): AgentInputItem[]
export function isTransientScreenshotItem(item: AgentInputItem): boolean
export const TRANSIENT_SCREENSHOT_MARKER = "__transient_screenshot__";
Import
import {
shapeScreenshotItems,
pruneTransientScreenshotItems,
} from "@aipexstudio/aipex-core";
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| items |
AgentInputItem[] |
Yes |
Array of conversation items from the SDK
|
Outputs
| Name |
Type |
Description
|
| returns |
AgentInputItem[] |
Modified array with imageData stripped and transient image messages injected
|
Usage Examples
As Model Input Filter
import { shapeScreenshotItems } from "@aipexstudio/aipex-core";
// Used internally by AIPex.runExecution():
const result = await run(agent, input, {
stream: true,
callModelInputFilter: async ({ modelData }) => ({
input: shapeScreenshotItems(modelData.input),
instructions: modelData.instructions,
}),
});
Prune Before Persistence
import { pruneTransientScreenshotItems } from "@aipexstudio/aipex-core";
// Remove transient screenshot messages before saving session
const itemsToPersist = pruneTransientScreenshotItems(session.getItems());
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.