LlmClient

This class provides the Robot interface for llm interactions with an LLM server.

  • Type: LIBRARY

  • Scope: TEST

Keywords

Assert State

Assert that the screen matches a state description.

Return

None

Raises

  • AssertionError: If the state does not match the description.

Positional and named arguments

Name

Type

Default Value

Kind

Required

Documentation

description

string

POSITIONAL_OR_NAMED

Yes

Description of the expected screen state.

image

None

None

POSITIONAL_OR_NAMED

No

Image to inspect. If omitted, a screenshot is grabbed.

custom_system_prompt

None

None

POSITIONAL_OR_NAMED

No

Optional system prompt override.

Example

Assert State    a Continue button is visible

Check For Visual Corruption

Detect if an image is corrupted.

Return

dictionary[string, Any]

A dict containing the LLM's assessment of whether the image is corrupted and a description.

Raises

  • VQAValidationError: If the image is assessed as corrupted by the LLM.

Positional and named arguments

Name

Type

Default Value

Kind

Required

Documentation

image

None

None

POSITIONAL_OR_NAMED

No

The image to check. If no image is provided, a new screenshot is grabbed.

custom_prompt

None

None

POSITIONAL_OR_NAMED

No

Optional custom prompt to guide the LLM.

Example

${result}=    Check For Visual Corruption

Configure Llm Client

Configure the LLM client with the given parameters.

Supported parameters are model, server_url, endpoint, max_tokens, api_key_env, image_format, collect_usage and provider.

provider applies a preset for a hosted service, which explicit parameters override:

  • openrouter: OpenRouter, key read from OPENROUTER_API_KEY.
  • copilot: GitHub Copilot, key read from GITHUB_TOKEN (e.g. export GITHUB_TOKEN=$(gh auth token)).
  • gemini: Google Gemini API, key read from GEMINI_API_KEY.

The API key is sent as a bearer token and read from the environment variable named by api_key_env (default YARF_LLM_API_KEY), so that it never appears in the Robot logs. No Authorization header is sent if the variable is unset.

Models that only support the OpenAI Responses API can be used by setting endpoint=/responses. For models that do not accept WEBP images, set image_format to PNG or JPEG.

Set collect_usage=True to record the token usage, inference time and cost of each request, see Get Llm Usage. It is off by default.

Return

None

Raises

  • TypeError: If unknown parameters are provided.

  • ValueError: If parameter values are of incorrect type or the provider is unknown.

Positional and named arguments

Name

Type

Default Value

Kind

Required

Documentation

kwargs

Any

VAR_NAMED

No

Configuration parameters for the LLM client.

Example

Configure Llm Client
...    model=qwen3-vl:2b-instruct
...    server_url=http://localhost:11434/v1
Configure Llm Client    provider=copilot    model=gpt-4.1
Configure Llm Client    provider=openrouter
...    model=qwen/qwen3-vl-8b-instruct
Configure Llm Client    provider=gemini    model=gemini-2.5-flash
Configure Llm Client    collect_usage=True

Execute Gui Action

Execute a GUI action as specified by the LLM response.

Return

None

Raises

  • ValueError: If the action type is unsupported or if required fields are missing.

Positional and named arguments

Name

Type

Default Value

Kind

Required

Documentation

action

dictionary

POSITIONAL_OR_NAMED

Yes

A dict containing the action_type, text and point, the proportional [x, y] position on the screen, e.g. [0.5, 0.5] for its center.

description

string

POSITIONAL_OR_NAMED

No

The description provided to the LLM.

Example

${action}=    Get Single Gui Action    click the Continue button
Execute Gui Action    ${action}    click the Continue button
${action}=    Create Dictionary    action_type=Left Click
...    text=${None}    point=${{[0.5, 0.5]}}
Execute Gui Action    ${action}

Get Llm Usage

Get the accumulated usage of all LLM requests made by this library instance, e.g. during the current test. Requires collect_usage=True in Configure Llm Client.

inference_time is the summed wall-clock time of the requests in seconds, including network latency. Retries of transient server errors are counted separately in retries; only the final attempt of each request counts in requests and inference_time. cost (OpenRouter credits) and nano_aiu (Copilot billing units) are None if the server does not report them.

Return

dictionary[string, Any]

A dict with the model, number of requests and retries, token counts, inference time, output throughput and cost.

Example

Configure Llm Client    collect_usage=True
${usage}=    Get Llm Usage
Log    ${usage}[total_tokens]

Get Object Position

Get the position of an object on the screen in relative coordinates.

Return

list[float]

The object position as normalized relative coordinates [x, y], where each value is typically in the range 0..1.

Raises

  • VQADetectionError: If the LLM indicates that the object was not

Positional and named arguments

Name

Type

Default Value

Kind

Required

Documentation

description

string

POSITIONAL_OR_NAMED

Yes

Description of the object to locate.

image

None

None

POSITIONAL_OR_NAMED

No

Image to inspect. If omitted, a screenshot is grabbed.

custom_system_prompt

None

None

POSITIONAL_OR_NAMED

No

Optional system prompt override.

Example

${point}=    Get Object Position    the Continue button

Get Single Gui Action

Get a single GUI action from the LLM.

Return

dictionary[string, Any]

The next GUI action, a dict with action_type, text and point. For pointer-based actions, point is the proportional [x, y] position on the screenshot, e.g. [0.5, 0.5] for its center; otherwise it is None.

Positional and named arguments

Name

Type

Default Value

Kind

Required

Documentation

task

string

POSITIONAL_OR_NAMED

Yes

The task description to provide to the LLM.

image

None

None

POSITIONAL_OR_NAMED

No

Image to inspect. If omitted, a screenshot is grabbed.

custom_system_prompt

None

None

POSITIONAL_OR_NAMED

No

Optional system prompt override.

Example

${action}=    Get Single Gui Action    click the Continue button

Multiple Step Action

Perform a multiple step action by prompting the LLM iteratively until a "Finish" action is returned.

Return

None

Raises

  • RuntimeError: If the LLM cannot finish within max_steps.

Positional and named arguments

Name

Type

Default Value

Kind

Required

Documentation

task

string

POSITIONAL_OR_NAMED

Yes

The task description to complete.

custom_system_prompt

None

None

POSITIONAL_OR_NAMED

No

Optional system prompt override.

max_steps

integer

50

POSITIONAL_OR_NAMED

No

Number of actions to attempt before stopping.

Example

Multiple Step Action    click the Continue button    max_steps=10

Prompt Llm

Send a prompt (text-only or text+image) to the LLM and get the response.

Return

string

The response from the LLM.

Positional and named arguments

Name

Type

Default Value

Kind

Required

Documentation

prompt

string

POSITIONAL_OR_NAMED

Yes

The text prompt to send to the LLM.

image

None

None

POSITIONAL_OR_NAMED

No

Optional image (PIL Image or path) to include in the prompt.

system_prompt

None

None

POSITIONAL_OR_NAMED

No

Optional system prompt to guide the LLM.

Example

${answer}=    Prompt Llm    Describe the screen
${image}=    Grab Screenshot
${answer}=    Prompt Llm    What is shown?    ${image}