@@ -233,6 +233,51 @@ This is useful when you need to isolate session configuration or use different s
233233
234234---
235235
236+ ## User Input Handling
237+
238+ Handle user input requests when the AI uses the ` ask_user ` tool to gather information from the user.
239+
240+ ``` java
241+ var session = client. createSession(
242+ new SessionConfig ()
243+ .setOnUserInputRequest((request, invocation) - > {
244+ System . out. println(" Agent asks: " + request. getQuestion());
245+
246+ // Check if choices are provided
247+ if (request. getChoices() != null && ! request. getChoices(). isEmpty()) {
248+ System . out. println(" Options: " + request. getChoices());
249+ // Return one of the provided choices
250+ String selectedChoice = request. getChoices(). get(0 );
251+ return CompletableFuture . completedFuture(
252+ new UserInputResponse ()
253+ .setAnswer(selectedChoice)
254+ .setWasFreeform(false )
255+ );
256+ }
257+
258+ // Freeform input
259+ String userAnswer = getUserInput(); // your input method
260+ return CompletableFuture . completedFuture(
261+ new UserInputResponse ()
262+ .setAnswer(userAnswer)
263+ .setWasFreeform(true )
264+ );
265+ })
266+ ). get();
267+ ```
268+
269+ The ` UserInputRequest ` contains:
270+ - ` getQuestion() ` - The question the AI is asking
271+ - ` getChoices() ` - Optional list of choices for the user to select from
272+
273+ The ` UserInputResponse ` should include:
274+ - ` setAnswer(String) ` - The user's answer
275+ - ` setWasFreeform(boolean) ` - ` true ` if the answer was freeform text, ` false ` if it was from the provided choices
276+
277+ See [ UserInputHandler] ( apidocs/com/github/copilot/sdk/json/UserInputHandler.html ) Javadoc for more details.
278+
279+ ---
280+
236281## Permission Handling
237282
238283Approve or deny permission requests from the AI.
0 commit comments