Skip to main content
The TaskRequestBuilder class provides a fluent interface for configuring task requests with detailed options.

Import

Creating a Builder

Use agent.new_task() to create a builder:

Methods

with_name

Set a descriptive name for the task (used in logging and tracing).
str
required
Task name for identification

with_max_steps

Set the maximum number of steps (actions) the task can take.
int
required
Maximum number of steps (default is 400)
Each step corresponds to one action (tap, swipe, etc.) executed by the agent.

with_output_format

Specify a Pydantic model class for structured, type-safe output.
type[BaseModel]
required
Pydantic model class defining the output structure
Use detailed field descriptions to help the LLM extract correct data.

with_output_description

Provide a natural language description of the expected output format.
str
required
Description of the expected output format

using_profile

Specify which agent profile to use for this task.
str | AgentProfile
required
Profile name (string) or AgentProfile instance

with_trace_recording

Enable or disable execution tracing for debugging and visualization.
bool
default:true
Whether to enable trace recording
str | Path
Directory path to save traces (defaults to temp directory)
Traces include screenshots at each step, making debugging much easier.

with_llm_output_saving

Configure where to save the final LLM output.
str
required
File path where LLM output will be saved (will be overwritten)

with_thoughts_output_saving

Configure where to save the agent’s thought process.
str
required
File path where agent thoughts will be saved (will be overwritten)
Agent thoughts reveal the reasoning process, helpful for understanding decisions.

without_llm_output_saving

Disable LLM output saving (if it was previously enabled).

without_thoughts_output_saving

Disable agent thoughts saving (if it was previously enabled).

with_locked_app_package

Lock task execution to a specific app package (Android) or bundle ID (iOS).
str
required
The app package name (Android) or bundle ID (iOS)
Only the package name should be specified, not the full path to the app or activity name.
When enabled:
  • Verifies the app is open before starting
  • Attempts to launch the app if not in foreground
  • Monitors app changes during execution
  • Automatically relaunches if user accidentally leaves the app
Android Example:
iOS Example:
The app lock feature requires the Contextor agent to be configured in your LLM profile. See the Tasks and Task Requests guide for more details.
Use adb shell pm list packages on Android or consult iOS documentation to find the correct package/bundle ID.

build

Build and return the final TaskRequest object.
TaskRequest[TOutput]
The constructed task request ready for execution

Complete Example

Method Chaining

All builder methods (except build()) return the builder instance, allowing fluent method chaining:

Type Safety

The builder maintains type information for output:

Comparison

βœ… Full control over all options
βœ… Type-safe
βœ… Self-documenting

Next Steps

Agent SDK

Learn about the Agent class

Types

Explore TaskRequest and other types