Benutzereingabe-Anfrage
Wenn Sie den HandleronUserInputRequest konfigurieren, kann der Agent den Benutzer über das Tool ask_user befragen.
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.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);
},
]);
Aktuelle Informationen finden Sie im GitHub-Repository.