TaskRequestBuilder class provides a fluent interface for configuring task requests with detailed options.
Import
Creating a Builder
Useagent.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
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)
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)
- 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
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.
build
Build and return the finalTaskRequest object.
TaskRequest[TOutput]
The constructed task request ready for execution
Complete Example
Method Chaining
All builder methods (exceptbuild()) return the builder instance, allowing fluent method chaining:
Type Safety
The builder maintains type information for output:Comparison
- With Builder
- Direct Call
β Type-safe
β Self-documenting
Next Steps
Agent SDK
Learn about the Agent class
Types
Explore TaskRequest and other types

