Skip to main content

Build your first Copilot-powered Laravel app

In this guide, you build a command-line assistant with the Laravel Copilot SDK. You start with a single prompt, then move to sessions, events, and tools.

Prerequisites

Before you begin, make sure you have:
  • GitHub Copilot CLI installed and authenticated
  • PHP 8.4+
  • Laravel 13.x
Verify the CLI is available:

Install the SDK

Install the package with Composer:
Optional configuration:
If needed, set the CLI path in your .env:

Send your first message

Create a command and call Copilot::run():
Run the command:

Keep context with sessions

Use Copilot::start() when you need multiple prompts in one conversation:

Handle session events

Register an event handler with on() to inspect assistant messages and failures:

Add a custom tool

Define a tool with a JSON schema and a handler:

Build an interactive assistant

Combine sessions, events, and tools into an interactive Artisan command:
Run the command:

How tools work

When you define a tool, you provide:
  1. What the tool does.
  2. Which parameters it accepts.
  3. Which handler code should run.
Copilot decides when to call the tool based on user input. The SDK executes your handler and returns the result back to Copilot.

Explore more features

Connect to MCP servers

Create custom agents

Customize the system message

Connect to an external CLI server

Run the Copilot CLI in server mode:
Then set the URL in .env:
When COPILOT_URL is set, the SDK connects to that server instead of starting a new CLI process.

Telemetry and observability

Configure telemetry in config/copilot.php:
Or configure it directly:

Learn more

Next steps

Authentication

Choose the right auth method for local and CI environments.

Tools

Let Copilot call your application code.

Session config

Configure models, hooks, MCP servers, and runtime behavior.

MCP

Connect pre-built tools from MCP servers.

Custom providers

Integrate additional provider and model strategies.

Telemetry

Export traces for debugging and observability.
You now covered the core Laravel Copilot SDK flow from single prompts to tool-enabled sessions.
Last modified on April 29, 2026