Skip to main content
Dynamic user input lets your agent decide when it needs information from the user and proactively request it during execution. Unlike the User Input pattern where you predefine which tools need user input, this pattern gives the agent autonomy to pause and ask for information whenever it realizes it doesn’t have what it needs. This pattern is ideal when:
  • The interaction flow is unpredictable: The agent might need different information based on context
  • You want a conversational experience: Let the agent guide the user through a form-like interaction
  • The agent should be intelligent about what it needs: Rather than blindly requesting predefined fields, the agent determines what’s missing

How It Works

The UserControlFlowTools toolkit provides your agent with a special get_user_input tool. When the agent realizes it’s missing information:
  1. Agent calls get_user_input with a list of fields it needs filled
  2. Execution pauses and requirements are added to the returned RunOutput
  3. user_input_schema populated in the requirement, with the input schema the agent created
  4. You collect the user’s input and set field values in user_input_schema
  5. Call continue_run() to resume with the filled values
  6. Repeat if needed: Agent may request more information based on previous responses
The key difference from other HITL patterns: the agent decides what fields to request and when to request them.
In this example, the agent identifies that it’s missing the email subject and recipient address, so it proactively calls get_user_input to collect that information. Pretty smart!

Understanding the get_user_input Tool

When your agent calls the get_user_input tool, it provides a list of fields using this format:
The agent constructs these fields intelligently based on what it needs. For example, if it’s trying to send an email but doesn’t have the recipient, it might request:
These fields then appear in tool.user_input_schema as UserInputField objects that you can iterate through and fill. For a detailed breakdown of the UserInputField structure, see Understanding UserInputField.

The While Loop Pattern

Notice the while run_response.is_paused: loop? This is crucial for dynamic user input, because the agent might request input multiple times:
The agent could:
  1. First ask for email details
  2. Send the email
  3. Realize it needs meeting details
  4. Pause again to request those fields
  5. Complete the task
This multi-round capability makes the pattern extremely flexible.
Important: Always check field.value before prompting. If the agent has already filled a field based on context (like extracting it from the user’s message), field.value won’t be None and you shouldn’t overwrite it.

Customizing Toolkit Behavior

The UserControlFlowTools toolkit comes with default instructions that guide the agent, but you can customize them:
You can also disable the tool entirely if needed:

Handling Pre-Filled Values

The agent can pre-fill some fields based on the conversation context. This works the same way as in User Input—always check field.value before prompting:
For a more detailed explanation of how pre-filled values work, see the Handling Pre-Filled Values section in the User Input documentation.

Best Practices

  1. Always use a while loop: The agent may need multiple rounds of input
  2. Check field values: Don’t overwrite fields the agent has already filled
  3. Provide clear prompts: Use the field.description to help users understand what’s needed
  4. Validate input: Add your own validation before setting field.value
  5. Handle interruptions gracefully: Store run_id to resume later if needed

Async Support

Dynamic user input works seamlessly with async agents. Use arun() and acontinue_run() for asynchronous flows:

Streaming Support

Dynamic user input also works with streaming. The agent will emit events until it needs user input, then pause:

When to Use This Pattern

Use Dynamic User Input when:
  • The agent needs to adapt its questions based on previous responses
  • You want the agent to intelligently determine what information is missing
  • The interaction flow changes based on context
Use User Input when:
  • You know exactly which tool fields require user input upfront
  • The input requirements are always the same
  • You want more explicit control over what gets asked
Remember that tools marked with @tool(requires_user_input=True) are mutually exclusive with @tool(requires_confirmation=True) and @tool(external_execution=True).A tool can only use one of these patterns at a time.

Usage Examples

Agentic User Input

Let the agent dynamically request user input

Developer Resources