> ## Documentation Index
> Fetch the complete documentation index at: https://kawax.biz/llms.txt
> Use this file to discover all available pages before exploring further.

# Ask user

> Reagieren Sie mit dem Handler onUserInputRequest des Laravel Copilot SDK auf Benutzerfragen über das Tool ask_user.

## Benutzereingabe-Anfrage

Wenn Sie den Handler `onUserInputRequest` konfigurieren, kann der Agent den Benutzer über das Tool `ask_user` befragen.

```php theme={null}
use Revolution\Copilot\Facades\Copilot;
use Revolution\Copilot\Contracts\CopilotSession;
use Revolution\Copilot\Types\UserInputRequest;
use Revolution\Copilot\Types\UserInputResponse;

Copilot::start(function (CopilotSession $session) {
    $response = $session->sendAndWait(prompt: 'ユーザーに好きな言語を聞いて');
    dump($response->content());
}, config: [
    'model' => 'gpt-5',
    'onUserInputRequest' => function (UserInputRequest $request): UserInputResponse {
        // $request->question - Inhalt der Frage
        // $request->choices - Array mit Auswahlmöglichkeiten (optional)
        // $request->allowFreeform - Ob Freitext erlaubt ist (Standard: true)

        dump("Question from agent: {$request->question}");
        if ($request->choices) {
            dump('Choices: '.implode(', ', $request->choices));
        }

        // Antwort des Benutzers zurückgeben
        return new UserInputResponse(
            answer: 'PHP',
            wasFreeform: true, // War es Freitext statt Auswahl?
        );
    },
]);
```

## Klasse UserInputRequest

Eine Benutzereingabe-Anfrage vom Agenten.

| Eigenschaft     | Typ      | Beschreibung                                        |
| --------------- | -------- | --------------------------------------------------- |
| `question`      | `string` | Die an den Benutzer zu stellende Frage              |
| `choices`       | `?array` | Auswahlmöglichkeiten bei Mehrfachauswahl (optional) |
| `allowFreeform` | `?bool`  | Ob Freitext erlaubt ist (Standard: `true`)          |

## Klasse UserInputResponse

Die Antwort auf eine Benutzereingabe-Anfrage.

| Eigenschaft   | Typ      | Beschreibung                                                                       |
| ------------- | -------- | ---------------------------------------------------------------------------------- |
| `answer`      | `string` | Die Antwort des Benutzers                                                          |
| `wasFreeform` | `bool`   | Ob die Antwort per Freitext erfolgte (`true`, wenn nicht aus Auswahlmöglichkeiten) |

## Praxisbeispiel

Verwendung in einem interaktiven Command.

```php theme={null}
use Revolution\Copilot\Facades\Copilot;
use Revolution\Copilot\Contracts\CopilotSession;
use Revolution\Copilot\Types\UserInputRequest;
use Revolution\Copilot\Types\UserInputResponse;

// Innerhalb eines Artisan-Commands
Copilot::start(function (CopilotSession $session) use ($command) {
    $response = $session->sendAndWait(prompt: 'プロジェクトの設定を行います');
    $command->info($response->content());
}, config: [
    'onUserInputRequest' => function (UserInputRequest $request) use ($command): UserInputResponse {
        if ($request->choices) {
            // Bei vorhandenen Auswahlmöglichkeiten die Methode choice verwenden
            $answer = $command->choice(
                $request->question,
                $request->choices,
                $request->choices[0] ?? null
            );

            return new UserInputResponse(answer: $answer, wasFreeform: false);
        }

        // Freitext
        $answer = $command->ask($request->question);

        return new UserInputResponse(answer: $answer, wasFreeform: true);
    },
]);
```

<Info>
  Aktuelle Informationen finden Sie im [GitHub-Repository](https://github.com/invokable/laravel-copilot-sdk).
</Info>


## Related topics

- [Laravel Prompts](/de/prompts.md)
- [Session-Hooks](/de/packages/laravel-copilot-sdk/hooks.md)
- [Artisan-Konsole](/de/artisan.md)
- [Add User Dict Word](/de/packages/laravel-voicevox/engine-api/user-dictionary/add-user-dict-word.md)
- [Import User Dict Words](/de/packages/laravel-voicevox/engine-api/user-dictionary/import-user-dict-words.md)
