- Collecting required parameters
- Getting user preferences
- Gathering missing information
How It Works
When you mark a tool withrequires_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 will be filled by the agent automatically based on 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 tools. When a tool requires user input, it will have a user_input_schema 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
If you want the user to provide all fields instead of letting the agent fill some automatically, simply omit theuser_input_fields parameter or pass an empty list:
Handling Pre-Filled Values
When you specifyuser_input_fields, you’re telling the agent which parameters the user should provide. The agent will automatically fill in the 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 fills 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 seamlessly with async agents. Just 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
Developer Resources
- View Cookbook