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

# Aan de slag - GitHub Copilot SDK voor Laravel

> Maak je eerste Laravel-command dat Copilot gebruikt en leer de basisworkflow van de Laravel Copilot SDK.

## Je eerste Laravel-app met Copilot bouwen

In deze gids bouw je een commandline-assistent met de Laravel Copilot SDK.
Je begint met het versturen van één prompt en gaat daarna verder met sessions, events en tools.

## Vereisten

Controleer het volgende voordat je begint.

* De GitHub Copilot CLI is geïnstalleerd en geauthenticeerd
* PHP `8.4+`
* Laravel `13.x`

Controleer of de CLI beschikbaar is.

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

## De SDK installeren

Installeer het package met Composer.

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

Publiceer indien nodig de configuratie.

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

Stel zo nodig het pad naar de CLI in via `.env`.

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

## Je eerste bericht versturen

Maak een command en roep `Copilot::run()` aan.

```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());
    }
}
```

Voer het command uit.

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

## Context behouden met een session

Gebruik `Copilot::start()` als je meerdere prompts in één gesprek wilt gebruiken.

```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 verwerken

Registreer met `on()` een event-handler om berichten van de assistent en fouten te bekijken.

```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');
});
```

## Een custom tool toevoegen

Definieer een tool met een JSON-schema en een 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);
```

## Een interactieve assistent bouwen

Door sessions, events en tools te combineren kun je een interactief Artisan-command maken.

```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);
    }
}
```

Voer het command uit.

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

## Hoe tools werken

Bij het definiëren van een tool geef je de volgende drie zaken op.

1. Wat de tool doet.
2. Welke parameters de tool ontvangt.
3. Welke handler-code er wordt uitgevoerd.

Copilot bepaalt op basis van de gebruikersinvoer of de tool wordt aangeroepen, waarna de SDK de handler uitvoert en het resultaat retourneert.

## Functies om hierna te proberen

### Een MCP-server verbinden

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

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

### Een custom agent maken

```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.',
        ],
    ],
);
```

### Het systeembericht aanpassen

```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.',
    ),
);
```

## Verbinden met een externe CLI-server

Start de Copilot CLI in servermodus.

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

Stel vervolgens de verbindings-URL in via `.env`.

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

Als `COPILOT_URL` is ingesteld, start de SDK geen nieuw CLI-proces, maar maakt deze verbinding met de bestaande server.

## Telemetrie en observability

Configureer telemetrie in `config/copilot.php`.

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

Of stel het direct in.

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

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

## Verder leren

* [Authenticatie](/nl/packages/laravel-copilot-sdk/auth)
* [MCP](/nl/packages/laravel-copilot-sdk/mcp)
* [Custom providers](/nl/packages/laravel-copilot-sdk/custom-providers)
* [Telemetrie](/nl/packages/laravel-copilot-sdk/telemetry)
* [SessionConfig](/nl/packages/laravel-copilot-sdk/session-config)
* [SessionEvent](/nl/packages/laravel-copilot-sdk/session-event)
* [Overzicht Laravel Copilot SDK](/nl/packages/laravel-copilot-sdk)
* [Officiële SDK-repository](https://github.com/github/copilot-sdk)

## Volgende stappen

<Columns cols={2}>
  <Card title="Authenticatie" href="/nl/packages/laravel-copilot-sdk/auth">
    Kies een authenticatiemethode die past bij je lokale omgeving en CI.
  </Card>

  <Card title="SessionConfig" href="/nl/packages/laravel-copilot-sdk/session-config">
    Configureer modellen, hooks, MCP-servers en runtime-gedrag.
  </Card>

  <Card title="SessionEvent" href="/nl/packages/laravel-copilot-sdk/session-event">
    Begrijp de Laravel-specifieke event-helpers en lifecycle-verwerking.
  </Card>

  <Card title="Permission requests" href="/nl/packages/laravel-copilot-sdk/permission-request">
    Bekijk de permissieflow om tools met expliciete goedkeuring uit te voeren.
  </Card>

  <Card title="Tools" href="/nl/packages/laravel-copilot-sdk/tools">
    Roep applicatiecode aan vanuit Copilot.
  </Card>

  <Card title="MCP" href="/nl/packages/laravel-copilot-sdk/mcp">
    Verbind kant-en-klare tools van MCP-servers.
  </Card>
</Columns>

Hiermee heb je de kernflow van de Laravel Copilot SDK doorlopen, van een enkele prompt tot een session met toolintegratie.

<Info>
  Referenties: [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

- [Laravel Cloud - GitHub Copilot SDK voor Laravel](/nl/packages/laravel-copilot-sdk/laravel-cloud.md)
- [Authenticatie - GitHub Copilot SDK for Laravel](/nl/packages/laravel-copilot-sdk/auth.md)
- [GitHub Copilot SDK voor Laravel](/nl/packages/laravel-copilot-sdk/index.md)
- [GitHub Actions - GitHub Copilot SDK voor Laravel](/nl/packages/laravel-copilot-sdk/github-actions.md)
- [Testen - GitHub Copilot SDK voor Laravel](/nl/packages/laravel-copilot-sdk/fake.md)
