Skip to content

pydantic_ai.computer_use

The computer tool: the actions a model can ask for, and the shapes of the tool’s arguments and result.

A capability that gives an agent a screen adds a tool of kind COMPUTER_KIND and performs its actions on that screen. For a provider with a computer tool of its own, the model adapter sends that tool instead and converts its calls and results.

Positions (x and y) are pixels of the latest screenshot, from its top left corner. A click or scroll without a position happens at the pointer.

The type field picks the action: the class name in snake case, such as click or press_keys. A key is a NamedKey or a single character, in any case. A character presses whatever keys the keyboard layout needs to type it. An upper-case letter presses the same key as its lower-case one. A model adapter turns its provider’s key names, such as the X11 Page_Down, into these.

The actions change only in ways that keep an existing tool doing what the model asked:

  • A new action gets a new type in ComputerToolAction, so an older tool rejects it instead of ignoring it. Actions reject unknown fields for the same reason.
  • An existing action only gains fields whose default keeps today’s behaviour, left out of saved data while at the default. A change a tool must act on, such as scrolling by pixels, is a new action.
  • The values a field accepts, such as the mouse buttons, never grow. A key name is added only for a key no existing name covers.
  • A new field, on an action or a result, never changes what an existing field means.

A result’s content is a short summary, what each action returned, then a screenshot of the screen after the call. The summary’s wording can change between releases; ComputerResult, in the result’s metadata, does not.

A call with a confirmation must not run until a person approves it. The runner enforces this, as ComputerUse does: a custom runner that skips the check runs flagged actions without approval. A runner that ran it after a person approved it sets confirmed on the result. A model adapter tells the provider that a person confirmed the call only when it is set, and otherwise says nobody did.

In the message history, the tool’s calls and results become ComputerCallPart and ComputerReturnPart, whatever the tool’s name.

Point

A position on the screenshot.

Region

A rectangle on the screenshot, from its top left corner to its bottom right one.

right and bottom are just outside it: left=0, right=10 is 10 pixels wide.

Click

Click a mouse button, at a position or where the pointer is.

Attributes

x

From the left edge of the screenshot. Omit both x and y to click where the pointer is.

Type: _Coordinate | None Default: None

y

From the top edge of the screenshot.

Type: _Coordinate | None Default: None

count

1 for a click, 2 for a double click, 3 for a triple click.

Type: Annotated[int, Field(ge=1)] Default: 1

modifiers

Modifier keys held during the click: ctrl, shift, alt or super.

Type: _Modifiers Default: ()

MouseMove

Move the pointer, for example to reveal a hover menu.

Attributes

x

From the left edge of the screenshot.

Type: _Coordinate

y

From the top edge of the screenshot.

Type: _Coordinate

Drag

Press the left button at the first point, move through the rest, and release at the last.

Attributes

path

The points to drag through: at least a start and an end.

Type: Annotated[tuple[Point, …], Field(min_length=2)]

modifiers

Modifier keys held during the drag: ctrl, shift, alt or super.

Type: _Modifiers Default: ()

MouseDown

Press a mouse button and keep it pressed until a mouse_up.

MouseUp

Release a mouse button pressed with mouse_down.

Scroll

Scroll the content under a position, or under the pointer.

Attributes

direction

Which way the content moves into view: down shows what is below.

Type: Literal[‘up’, ‘down’, ‘left’, ‘right’]

amount

Mouse-wheel clicks; one click scrolls about three lines.

Type: Annotated[int, Field(ge=1)]

x

From the left edge of the screenshot. Omit both x and y to scroll where the pointer is.

Type: _Coordinate | None Default: None

y

From the top edge of the screenshot.

Type: _Coordinate | None Default: None

modifiers

Modifier keys held while scrolling: ctrl, shift, alt or super.

shift scrolls sideways in some applications.

Type: _Modifiers Default: ()

TypeText

Type text at the keyboard focus. Use press_keys for shortcuts and special keys.

PressKeys

Press keys together as one combination, then release them.

Attributes

keys

One key per entry, pressed together: ["enter"], ["ctrl", "a"], ["super", "shift", "t"].

Type: _Keys

repeat

How many times to press the combination.

Type: Annotated[int, Field(ge=1)] Default: 1

HoldKeys

Hold keys down for a while, then release them.

Attributes

keys

One key per entry, held together.

Type: _Keys

seconds

How long to hold them.

Type: Annotated[float, Field(gt=0, allow_inf_nan=False)]

Wait

Pause, for example while a page or application loads.

Attributes

seconds

How long to wait.

Type: Annotated[float, Field(gt=0, allow_inf_nan=False)] Default: 1

Screenshot

Look at the screen without acting. A call’s result already ends with a screenshot.

Zoom

Look closely at part of the screen, to read small text or find a small target.

Attributes

region

The part of the screen to look at. Positions in later actions are still on the full screen.

Type: Region

CursorPosition

Report where the pointer is.

ComputerArgs

Bases: TypedDict

The computer tool’s arguments.

Attributes

actions

The actions to perform, in order.

Type: list[ComputerToolAction]

ComputerResult

Bases: TypedDict

A computer call’s outcome, returned as its metadata.

Attributes

performed

How many actions ran: all of them, or those before the one that failed.

Type: int

error

Why an action failed. It is the action right after the performed ones. The actions after it did not run.

Type: NotRequired[str]

actions_changed

True when the actions that ran differ from those the model asked for, for example because an approval changed them. A model adapter then sends the summary instead of reporting the model’s actions as the ones that ran.

Type: NotRequired[bool]

confirmed

Set by the runner when a person approved this call; providers that need an acknowledgement send one only when it is set.

Type: NotRequired[Literal[True]]

ComputerCallPart

Bases: ToolCallPart[ComputerArgs]

A call of the computer tool.

Attributes

actions

The actions the model asked for, or None if the arguments are incomplete (still streaming) or malformed.

Type: list[ComputerToolAction] | None

confirmation

The provider’s reason this call must be approved by a person before it runs, or None.

A provider sets it on actions its safety checks flag, such as accepting a cookie banner or sending a message. A model adapter sets it by putting the reason, as a string, under the 'confirmation' key of the call’s provider_details.

Type: str | None

ComputerReturnPart

Bases: ToolReturnPart[ComputerContent, ComputerResult]

A successful result of the computer tool.

Attributes

result

The call’s outcome. None when the result has no metadata, such as a result a UI rebuilt.

Type: ComputerResult | None

screenshot

The screen after the call. None if the result doesn’t end with an image, such as after it was dropped.

Type: BinaryImage | None

MouseButton

A mouse button.

Type: TypeAlias Default: Literal['left', 'middle', 'right']

Modifier

A modifier key, held during a click, move, drag or scroll.

Type: TypeAlias Default: Literal['ctrl', 'shift', 'alt', 'super']

NamedKey

A key with a name: a modifier, a navigation or editing key, or f1 to f12.

Type: TypeAlias Default: Literal[Modifier, 'enter', 'escape', 'tab', 'backspace', 'delete', 'insert', 'home', 'end', 'pageup', 'pagedown', 'up', 'down', 'left', 'right', 'space', 'printscreen', 'pause', 'menu', 'capslock', 'numlock', 'scrolllock', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12']

Key

A named key, or a single character such as a or +.

Type: TypeAlias Default: NamedKey | Annotated[str, Field(min_length=1, max_length=1)]

ComputerToolAction

What the computer tool accepts: mouse and keyboard actions, plus waiting and looking.

Type: TypeAlias Default: Annotated[Click | MouseMove | Drag | MouseDown | MouseUp | Scroll | TypeText | PressKeys | HoldKeys | Wait | Screenshot | Zoom | CursorPosition, Field(discriminator='type')]

ComputerContent

What the model sees from a computer call: a summary, what each action returned, then the screenshot.

Type: TypeAlias Default: list[str | BinaryImage]

COMPUTER_KIND

The tool kind that marks a tool as the computer tool.

When a request includes a ComputerTool, the provider’s own computer tool is sent to the model in place of the tool of this kind, which still runs the calls.

A runner must set confirmed on the result of a call with a confirmation that a person approved.

Default: ToolKind('computer_use', 'computer', args=ComputerArgs, content=ComputerContent, metadata=ComputerResult)