- Collecting required parameters
- Getting user preferences
- Gathering missing information
How It Works
When you mark a tool with@tool(requires_user_input=True), your agent will:
- Pause execution before calling the tool
- Set
is_pausedtoTrueon the run response - Populate
user_input_schemawith the fields that need to be filled - Wait for you to provide the requested values
- Continue execution once you call
continue_run()with the filled values
Collecting Specific Fields
You can control which fields require user input using theuser_input_fields parameter. Fields not in this list remain in the tool schema and may be filled by the agent from the conversation context.
In the example below, the agent pauses to collect the to_address parameter from the user for the send_email tool:
subject and body based on the user’s request (“Hello” and “Hello, world!”), but will pause and ask the user for the to_address since it’s in the user_input_fields list.
Understanding UserInputField
TheRunOutput object has a list of requirements. When a tool requires user input, you will find a requirement object with a user_input_schema field, populated with UserInputField objects:
If
field.value is already set (not None), it means the agent has pre-filled it from the conversation context. You can either use that value or override it with user input.The same UserInputField structure is used in Dynamic User Input, where the agent dynamically creates these fields when it needs information.Collecting All Fields
Omittinguser_input_fields or passing an empty list leaves all parameters in the tool schema. It does not force the user to provide every field. To require user input for all parameters, list every field explicitly:
user_input_schema for your application to fill before continuing the run.
Handling Pre-Filled Values
When you specifyuser_input_fields, you’re telling the agent which parameters the user should provide. The agent can fill in other parameters based on the conversation context.
For example, with user_input_fields=["to_address"] on a send_email(subject, body, to_address) function:
subjectandbody(not in the list) → Agent can fill these from context,value="Hello"etc.to_address(in the list) → User must provide this,value=None
user_input_schema will include all parameters, but you only need to collect values for fields where value=None:
Async Support
User input works with async agents. Usearun() and acontinue_run():
Dynamic User Input also supports async patterns with the same methods.
Streaming Support
User input also works with streaming. The agent will emit events until it needs user input, then pause:Usage Examples
Basic User Input
Simple user input collection
All Fields Input
Collecting all tool parameters from user
Async User Input
Using user input with async agents
Streaming User Input
User input with streaming responses