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

# Erste Schritte - GitHub Copilot SDK für Laravel

> Erstellen Sie Ihr erstes Laravel-Command mit Copilot und lernen Sie die grundlegenden Workflows des Laravel Copilot SDK.

## Ihre erste Copilot-fähige Laravel-Anwendung erstellen

In dieser Anleitung erstellen Sie mit dem Laravel Copilot SDK einen Kommandozeilen-Assistenten.
Wir beginnen mit dem Senden eines einzelnen Prompts und gehen dann zu Sessions, Events und Tools über.

## Voraussetzungen

Bevor Sie beginnen, stellen Sie Folgendes sicher.

* Die GitHub Copilot CLI ist installiert und authentifiziert
* PHP `8.4+`
* Laravel `13.x`

Prüfen Sie die Verfügbarkeit der CLI.

```bash theme={null}
copilot --version
```

## SDK installieren

Installieren Sie das Paket mit Composer.

```bash theme={null}
composer require revolution/laravel-copilot-sdk
```

Veröffentlichen Sie bei Bedarf die Konfiguration.

```bash theme={null}
php artisan vendor:publish --tag=copilot-config
```

Setzen Sie ggf. den CLI-Pfad in `.env`.

```dotenv theme={null}
COPILOT_CLI_PATH=copilot
```

## Erste Nachricht senden

Erstellen Sie einen Command und rufen Sie `Copilot::run()` auf.

```php theme={null}
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Revolution\Copilot\Facades\Copilot;

class CopilotDemo extends Command
{
    protected $signature = 'copilot:demo';
    protected $description = 'Demo Copilot SDK';

    public function handle()
    {
        $response = Copilot::run(prompt: 'What is 2 + 2?');

        $this->info($response->content());
    }
}
```

Führen Sie den Command aus.

```bash theme={null}
php artisan copilot:demo
```

## Kontext über Sessions halten

Wenn Sie mehrere Prompts in einer Konversation nutzen möchten, verwenden Sie `Copilot::start()`.

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

Copilot::start(function (CopilotSession $session) {
    $response = $session->sendAndWait(prompt: 'What is 2 + 2?');
    $this->info('Answer: '.$response->content());

    $response = $session->sendAndWait(prompt: 'Now multiply that by 3');
    $this->info('Answer: '.$response->content());
});
```

## Session-Events verarbeiten

Registrieren Sie mit `on()` einen Event-Handler und behandeln Sie Assistenten-Nachrichten oder Fehler.

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

Copilot::start(function (CopilotSession $session) {
    $session->on(function (SessionEvent $event): void {
        if ($event->isAssistantMessage()) {
            $this->info($event->content());
        } elseif ($event->failed()) {
            $this->error($event->errorMessage() ?? 'Unknown error');
        }
    });

    $session->sendAndWait(prompt: 'Tell me a short Laravel joke');
});
```

## Benutzerdefinierte Tools hinzufügen

Definieren Sie Tools mit einem JSON-Schema und einem Handler.

```php theme={null}
use Illuminate\JsonSchema\JsonSchema;
use Revolution\Copilot\Contracts\CopilotSession;
use Revolution\Copilot\Facades\Copilot;
use Revolution\Copilot\Types\SessionConfig;
use Revolution\Copilot\Types\Tool;

$parameters = JsonSchema::object([
    'topic' => JsonSchema::string()
        ->description('Topic to look up')
        ->required(),
])->toArray();

$config = new SessionConfig(
    tools: [
        Tool::define(
            name: 'lookup_fact',
            description: 'Returns a fact for a topic.',
            parameters: $parameters,
            handler: function (array $params): array {
                $topic = $params['topic'] ?? '';

                return [
                    'textResultForLlm' => "Fact for {$topic}",
                    'resultType' => 'success',
                    'sessionLog' => "lookup_fact: {$topic}",
                    'toolTelemetry' => [],
                ];
            },
        ),
    ],
);

Copilot::start(function (CopilotSession $session) {
    $response = $session->sendAndWait(
        prompt: 'Use lookup_fact to tell me something about Laravel.'
    );

    $this->info($response->content());
}, config: $config);
```

## Interaktiven Assistenten bauen

Wenn Sie Sessions, Events und Tools kombinieren, können Sie einen interaktiven Artisan-Command erstellen.

```php theme={null}
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\JsonSchema\JsonSchema;
use Revolution\Copilot\Contracts\CopilotSession;
use Revolution\Copilot\Facades\Copilot;
use Revolution\Copilot\Types\SessionConfig;
use Revolution\Copilot\Types\SessionEvent;
use Revolution\Copilot\Types\Tool;
use Revolution\Copilot\Types\ToolResultObject;

use function Laravel\Prompts\error;
use function Laravel\Prompts\info;
use function Laravel\Prompts\note;
use function Laravel\Prompts\spin;
use function Laravel\Prompts\text;

class CopilotAssistant extends Command
{
    protected $signature = 'copilot:assistant';
    protected $description = 'Interactive Copilot assistant';

    public function handle()
    {
        $facts = [
            'PHP' => 'A popular general-purpose scripting language for web development.',
            'Laravel' => 'A web application framework with expressive, elegant syntax.',
            'Composer' => 'Dependency manager for PHP.',
        ];

        $parameters = JsonSchema::object([
            'topic' => JsonSchema::string()
                ->description('Topic to look up')
                ->required(),
        ])->toArray();

        $config = new SessionConfig(
            tools: [
                Tool::define(
                    name: 'lookup_fact',
                    description: 'Returns a fun fact about a given topic.',
                    parameters: $parameters,
                    handler: function (array $params) use ($facts) {
                        $topic = $params['topic'] ?? '';
                        $fact = $facts[$topic] ?? "No fact available for {$topic}.";

                        return new ToolResultObject(
                            textResultForLlm: $fact,
                            resultType: 'success',
                            sessionLog: "lookup_fact: {$topic}",
                            toolTelemetry: [],
                        );
                    },
                ),
            ],
        );

        Copilot::start(function (CopilotSession $session) {
            info('Copilot assistant');
            info("Session: {$session->id()}");
            info("Try: Use lookup_fact to tell me about Laravel");

            $session->on(function (SessionEvent $event): void {
                if ($event->isAssistantMessage()) {
                    note($event->content());
                } elseif ($event->failed()) {
                    error($event->errorMessage() ?? 'Unknown error');
                }
            });

            while (true) {
                $prompt = text(
                    label: 'You',
                    placeholder: 'Ask me anything...',
                    required: true,
                    hint: 'Ctrl+C to exit',
                );

                spin(
                    callback: fn () => $session->sendAndWait($prompt),
                    message: 'Thinking...',
                );

                echo "\n";
            }
        }, config: $config);
    }
}
```

Führen Sie den Command aus.

```bash theme={null}
php artisan copilot:assistant
```

## So funktionieren Tools

Beim Definieren eines Tools geben Sie folgende drei Aspekte an.

1. Was das Tool tut.
2. Welche Parameter es entgegennimmt.
3. Welcher Handler-Code ausgeführt werden soll.

Copilot entscheidet anhand der Nutzereingabe über den Tool-Aufruf, und das SDK führt den Handler aus und liefert das Ergebnis zurück.

## Weitere Funktionen zum Ausprobieren

### MCP-Server anbinden

```php theme={null}
use Revolution\Copilot\Types\SessionConfig;

$config = new SessionConfig(
    mcpServers: [
        'github' => [
            'type' => 'http',
            'url' => 'https://api.githubcopilot.com/mcp/',
        ],
    ],
);
```

### Benutzerdefinierten Agenten erstellen

```php theme={null}
use Revolution\Copilot\Types\SessionConfig;

$config = new SessionConfig(
    customAgents: [
        [
            'name' => 'pr-reviewer',
            'displayName' => 'PR Reviewer',
            'description' => 'Reviews pull requests for best practices',
            'prompt' => 'You are an expert code reviewer. Focus on security, performance, and maintainability.',
        ],
    ],
);
```

### System-Nachricht anpassen

```php theme={null}
use Revolution\Copilot\Types\SessionConfig;
use Revolution\Copilot\Types\SystemMessageConfig;

$config = new SessionConfig(
    systemMessage: new SystemMessageConfig(
        content: 'You are a helpful assistant for our engineering team. Always be concise.',
    ),
);
```

## Mit einem externen CLI-Server verbinden

Starten Sie die Copilot CLI im Server-Modus.

```bash theme={null}
copilot --headless --port 4321
```

Konfigurieren Sie anschließend die Ziel-URL in `.env`.

```dotenv theme={null}
COPILOT_URL=tcp://127.0.0.1:4321
```

Wenn `COPILOT_URL` gesetzt ist, startet das SDK keinen neuen CLI-Prozess, sondern verbindet sich mit dem bestehenden Server.

## Telemetrie und Observability

Konfigurieren Sie die Telemetrie in `config/copilot.php`.

```php theme={null}
'telemetry' => [
    'otlpEndpoint' => 'http://localhost:4318',
],
```

Oder setzen Sie sie direkt.

```php theme={null}
use Revolution\Copilot\Facades\Copilot;
use Revolution\Copilot\Types\TelemetryConfig;

Copilot::useStdio([
    'telemetry' => new TelemetryConfig(
        otlpEndpoint: 'http://localhost:4318',
    ),
]);
```

## Weiterführendes

* [Authentifizierung](/de/packages/laravel-copilot-sdk/auth)
* [MCP](/de/packages/laravel-copilot-sdk/mcp)
* [Benutzerdefinierte Provider](/de/packages/laravel-copilot-sdk/custom-providers)
* [Telemetrie](/de/packages/laravel-copilot-sdk/telemetry)
* [SessionConfig](/de/packages/laravel-copilot-sdk/session-config)
* [SessionEvent](/de/packages/laravel-copilot-sdk/session-event)
* [Laravel Copilot SDK – Überblick](/de/packages/laravel-copilot-sdk)
* [Offizielles SDK-Repository](https://github.com/github/copilot-sdk)

## Nächste Schritte

<Columns cols={2}>
  <Card title="Authentifizierung" href="/de/packages/laravel-copilot-sdk/auth">
    Wählen Sie die passende Authentifizierungsmethode für lokale Umgebungen und CI aus.
  </Card>

  <Card title="SessionConfig" href="/de/packages/laravel-copilot-sdk/session-config">
    Konfigurieren Sie Modelle, Hooks, MCP-Server und das Laufzeitverhalten.
  </Card>

  <Card title="SessionEvent" href="/de/packages/laravel-copilot-sdk/session-event">
    Verstehen Sie Laravel-spezifische Event-Helper und die Lebenszyklusverarbeitung.
  </Card>

  <Card title="Berechtigungsanfragen" href="/de/packages/laravel-copilot-sdk/permission-request">
    Überprüfen Sie den Berechtigungsablauf zur Ausführung von Tools mit expliziter Zustimmung.
  </Card>

  <Card title="Tools" href="/de/packages/laravel-copilot-sdk/tools">
    Rufen Sie aus Copilot Ihren Anwendungscode auf.
  </Card>

  <Card title="MCP" href="/de/packages/laravel-copilot-sdk/mcp">
    Binden Sie vorgefertigte Tools eines MCP-Servers an.
  </Card>
</Columns>

Damit haben Sie die zentralen Abläufe des Laravel Copilot SDK vom Einzel-Prompt bis zur Tool-integrierten Session einmal komplett durchlaufen.

<Info>
  Referenz: [Laravel Copilot SDK README](https://github.com/invokable/laravel-copilot-sdk/blob/main/README.md), [Laravel Copilot SDK Getting Started](https://github.com/invokable/laravel-copilot-sdk/blob/main/docs/getting-started.md), [GitHub Copilot SDK](https://github.com/github/copilot-sdk)
</Info>


## Related topics

- [GitHub Copilot SDK für Laravel](/de/packages/laravel-copilot-sdk/index.md)
- [GitHub Actions - GitHub Copilot SDK für Laravel](/de/packages/laravel-copilot-sdk/github-actions.md)
- [Authentifizierung - GitHub Copilot SDK für Laravel](/de/packages/laravel-copilot-sdk/auth.md)
- [Testing - GitHub Copilot SDK für Laravel](/de/packages/laravel-copilot-sdk/fake.md)
- [Laravel Cloud - GitHub Copilot SDK für Laravel](/de/packages/laravel-copilot-sdk/laravel-cloud.md)
