User Input Required All Fields
This example demonstrates how to use the requires_user_input parameter to collect input for all fields in a tool. It shows how to handle user input schema and collect values for each required field.
Create a Python file
1from typing import List23from kern.agent import Agent4from kern.db.sqlite import SqliteDb5from kern.models.openai import OpenAIResponses6from kern.tools import tool7from kern.tools.function import UserInputField8from kern.utils import pprint91011@tool(requires_user_input=True)12def send_email(subject: str, body: str, to_address: str) -> str:13 """14 Send an email.1516 Args:17 subject (str): The subject of the email.18 body (str): The body of the email.19 to_address (str): The address to send the email to.20 """21 return f"Sent email to {to_address} with subject {subject} and body {body}"222324agent = Agent(25 model=OpenAIResponses(id="gpt-5.2"),26 tools=[send_email],27 markdown=True,28 db=SqliteDb(db_file="tmp/example.db"),29)3031run_response = agent.run("Send an email please")32if run_response.is_paused: # Or agent.run_response.is_paused33 for requirement in run_response.active_requirements:34 if requirement.needs_user_input:35 input_schema: List[UserInputField] = requirement.user_input_schema # type: ignore3637 for field in input_schema:38 # Get user input for each field in the schema39 field_type = field.field_type40 field_description = field.description4142 # Display field information to the user43 print(f"\nField: {field.name}")44 print(f"Description: {field_description}")45 print(f"Type: {field_type}")4647 # Get user input48 if field.value is None:49 user_value = input(f"Please enter a value for {field.name}: ")5051 # Update the field value52 field.value = user_value5354 run_response = agent.continue_run(55 run_id=run_response.run_id,56 requirements=run_response.requirements,57 )58 pprint.pprint_run_response(run_response)5960# Or for simple debug flow61# agent.print_response("Send an email please")Set up your virtual environment
1uv venv --python 3.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateInstall dependencies
1uv pip install -U kern-ai openaiExport your OpenAI API key
1export OPENAI_API_KEY="your_openai_api_key_here"1$Env:OPENAI_API_KEY="your_openai_api_key_here"Run Agent
1python user_input_required_all_fields.py