Agent Kit
Introduction
Agent Kit is a Laravel starter kit for building AI agents that work alongside your team in Slack, Telegram, and GitHub. It brings together the Laravel AI SDK for writing your agents and tools, Laravel Converse for connecting them to chat platforms, and Laravel MCP for calling tools on external MCP servers. Conversation memory, webhook routing, and queue processing are already configured, so you can focus on what your agent does.
Agent Kit doesn't include a web frontend or user authentication. If you want users to chat with your agent on your application's own pages, start from one of Laravel's full-stack starter kits and follow the Converse web chat guide instead.
Creating an Application
Agent Kit requires PHP 8.4 or higher. Create a new application using Composer's create-project command:
1composer create-project laravel/agent-kit my-agent1composer create-project laravel/agent-kit my-agent
This command installs your application's dependencies, creates its .env file and SQLite database, generates an application key, and runs your database migrations. It then runs the Laravel Boost installer, which asks which coding agents you use, such as Claude Code or Cursor, and sets up guidelines for the AI SDK, Converse, and Agent Kit.
Configuring Your AI Provider
A new application uses OpenAI by default. Add your OpenAI API key to .env:
1OPENAI_API_KEY=sk-your-key1OPENAI_API_KEY=sk-your-key
You may use any provider the AI SDK supports. For example, if you'd rather use Anthropic, set ANTHROPIC_API_KEY in .env and change the default option in config/ai.php to anthropic.
Application Structure
Agent Kit follows Laravel's directory structure, trimmed down for agents with a few additions:
app/Ai/Agentsholds your agents. A new application starts with anAssistantagent.app/Ai/Toolsholds the tools your agents can call. Artisan creates this directory the first time you runmake:tool.routes/bot.phpregisters the bots that connect your agents to chat platforms.tests/Evalsholds your evals, which send real prompts to your agents and grade their answers.
Building Your First Agent
To see how the pieces fit together, we'll build a weather agent that answers questions in Slack. You'll write its instructions, give it a tool that looks up live weather data, chat with it in your terminal, verify its answers with an eval, and connect it to Slack.
Writing the Instructions
A new application starts with an Assistant agent in app/Ai/Agents/Assistant.php. The class defines the instructions the agent follows and the tools it can call:
1<?php23namespace App\Ai\Agents;45use Laravel\Ai\Concerns\RemembersConversations;6use Laravel\Ai\Contracts\Agent;7use Laravel\Ai\Contracts\Conversational;8use Laravel\Ai\Contracts\HasTools;9use Laravel\Ai\Contracts\Tool;10use Laravel\Ai\Promptable;11use Laravel\Ai\Providers\Tools\ProviderTool;12use Stringable;1314class Assistant implements Agent, Conversational, HasTools15{16 use Promptable, RemembersConversations;1718 /**19 * Get the instructions that the agent should follow.20 */21 public function instructions(): Stringable|string22 {23 return <<<'MD'24 You are a helpful assistant.25 MD;26 }2728 /**29 * Get the tools available to the agent.30 *31 * @return list<Agent|Tool|ProviderTool>32 */33 public function tools(): iterable34 {35 return [36 // ...Mcp::client('github')->tools(),37 ];38 }39}1<?php23namespace App\Ai\Agents;45use Laravel\Ai\Concerns\RemembersConversations;6use Laravel\Ai\Contracts\Agent;7use Laravel\Ai\Contracts\Conversational;8use Laravel\Ai\Contracts\HasTools;9use Laravel\Ai\Contracts\Tool;10use Laravel\Ai\Promptable;11use Laravel\Ai\Providers\Tools\ProviderTool;12use Stringable;1314class Assistant implements Agent, Conversational, HasTools15{16 use Promptable, RemembersConversations;1718 /**19 * Get the instructions that the agent should follow.20 */21 public function instructions(): Stringable|string22 {23 return <<<'MD'24 You are a helpful assistant.25 MD;26 }2728 /**29 * Get the tools available to the agent.30 *31 * @return list<Agent|Tool|ProviderTool>32 */33 public function tools(): iterable34 {35 return [36 // ...Mcp::client('github')->tools(),37 ];38 }39}
The RemembersConversations trait stores each conversation in your database, so the agent keeps earlier messages from a Slack thread in its conversation history.
An agent's instructions method may return a plain string or a Blade view. Returning a view lets you include live application data, such as today's date, directly in the prompt. Because a new application doesn't include a resources directory, create resources/views/instructions/assistant.blade.php:
1You are a weather assistant for a team spread across many cities.23Answer questions about the weather and nothing else. Keep replies to a4sentence or two. You are talking in a chat window, not writing a report.5Always name the city a reading is for.67Today is {{ now()->toFormattedDateString() }}.1You are a weather assistant for a team spread across many cities.23Answer questions about the weather and nothing else. Keep replies to a4sentence or two. You are talking in a chat window, not writing a report.5Always name the city a reading is for.67Today is {{ now()->toFormattedDateString() }}.
Next, update app/Ai/Agents/Assistant.php so its instructions method returns that view:
1/**2 * Get the instructions that the agent should follow.3 */4public function instructions(): Stringable|string5{6 return view('instructions.assistant');7}1/**2 * Get the instructions that the agent should follow.3 */4public function instructions(): Stringable|string5{6 return view('instructions.assistant');7}
Giving the Agent a Tool
Tools let an agent look up live data and take actions. Without a tool, the model can only draw on what it learned during training, so it has no way to check today's weather. Generate a weather tool using the make:tool Artisan command:
1php artisan make:tool CurrentWeatherTool1php artisan make:tool CurrentWeatherTool
Every tool defines three methods: description explains what the tool does, schema declares the arguments it accepts, and handle runs when the model calls it. This tool fetches live weather data from Open-Meteo, which is free and doesn't require an API key. Replace the contents of app/Ai/Tools/CurrentWeatherTool.php with the following:
1<?php23namespace App\Ai\Tools;45use Illuminate\Contracts\JsonSchema\JsonSchema;6use Illuminate\Support\Facades\Http;7use Laravel\Ai\Contracts\Tool;8use Laravel\Ai\Tools\Request;9use Stringable;1011class CurrentWeatherTool implements Tool12{13 /**14 * Get the description of the tool's purpose.15 */16 public function description(): Stringable|string17 {18 return 'Get the current weather in a city.';19 }2021 /**22 * Execute the tool.23 */24 public function handle(Request $request): Stringable|string25 {26 $city = $request->string('city')->trim()->toString();2728 $place = Http::get('https://geocoding-api.open-meteo.com/v1/search', [29 'name' => $city,30 'count' => 1,31 ])->json('results.0');3233 if ($place === null) {34 return "No city named [{$city}] could be found. Ask the user to confirm the spelling.";35 }3637 $current = Http::get('https://api.open-meteo.com/v1/forecast', [38 'latitude' => $place['latitude'],39 'longitude' => $place['longitude'],40 'current' => 'temperature_2m,wind_speed_10m',41 ])->json('current');4243 return "{$place['name']}, {$place['country']}: {$current['temperature_2m']}°C, wind {$current['wind_speed_10m']} km/h.";44 }4546 /**47 * Get the tool's schema definition.48 */49 public function schema(JsonSchema $schema): array50 {51 return [52 'city' => $schema->string()53 ->description('The city to look up, such as "Lisbon" or "Austin, Texas".')54 ->required(),55 ];56 }57}1<?php23namespace App\Ai\Tools;45use Illuminate\Contracts\JsonSchema\JsonSchema;6use Illuminate\Support\Facades\Http;7use Laravel\Ai\Contracts\Tool;8use Laravel\Ai\Tools\Request;9use Stringable;1011class CurrentWeatherTool implements Tool12{13 /**14 * Get the description of the tool's purpose.15 */16 public function description(): Stringable|string17 {18 return 'Get the current weather in a city.';19 }2021 /**22 * Execute the tool.23 */24 public function handle(Request $request): Stringable|string25 {26 $city = $request->string('city')->trim()->toString();2728 $place = Http::get('https://geocoding-api.open-meteo.com/v1/search', [29 'name' => $city,30 'count' => 1,31 ])->json('results.0');3233 if ($place === null) {34 return "No city named [{$city}] could be found. Ask the user to confirm the spelling.";35 }3637 $current = Http::get('https://api.open-meteo.com/v1/forecast', [38 'latitude' => $place['latitude'],39 'longitude' => $place['longitude'],40 'current' => 'temperature_2m,wind_speed_10m',41 ])->json('current');4243 return "{$place['name']}, {$place['country']}: {$current['temperature_2m']}°C, wind {$current['wind_speed_10m']} km/h.";44 }4546 /**47 * Get the tool's schema definition.48 */49 public function schema(JsonSchema $schema): array50 {51 return [52 'city' => $schema->string()53 ->description('The city to look up, such as "Lisbon" or "Austin, Texas".')54 ->required(),55 ];56 }57}
The first request resolves the city's coordinates, and the second fetches the current temperature and wind speed at those coordinates. If Open-Meteo can't find the city, the tool returns a plain message so the model can ask the user to check the spelling. The model reads description and the argument descriptions in schema to decide when to call the tool and what arguments to pass.
Next, register the tool in app/Ai/Agents/Assistant.php by returning it from the tools method:
1use App\Ai\Tools\CurrentWeatherTool;23/**4 * Get the tools available to the agent.5 *6 * @return list<Agent|Tool|ProviderTool>7 */8public function tools(): iterable9{10 return [11 new CurrentWeatherTool,12 ];13}1use App\Ai\Tools\CurrentWeatherTool;23/**4 * Get the tools available to the agent.5 *6 * @return list<Agent|Tool|ProviderTool>7 */8public function tools(): iterable9{10 return [11 new CurrentWeatherTool,12 ];13}
The AI SDK passes each tool to the model under its class name, so you can refer to CurrentWeatherTool by name in your prompt. Update resources/views/instructions/assistant.blade.php to require the tool for every weather question:
1You are a weather assistant for a team spread across many cities.23Use the `CurrentWeatherTool` tool before answering any question about the weather.4It is your only source, so never answer from memory.56Answer questions about the weather and nothing else. Keep replies to a7sentence or two. You are talking in a chat window, not writing a report.8Always name the city a reading is for.910Today is {{ now()->toFormattedDateString() }}.1You are a weather assistant for a team spread across many cities.23Use the `CurrentWeatherTool` tool before answering any question about the weather.4It is your only source, so never answer from memory.56Answer questions about the weather and nothing else. Keep replies to a7sentence or two. You are talking in a chat window, not writing a report.8Always name the city a reading is for.910Today is {{ now()->toFormattedDateString() }}.
Registering the Bot
A bot connects an agent to one or more chat platforms. You register bots in routes/bot.php, giving each bot a name, an agent class, and the connections it listens on. A new application registers Assistant as assistant without any platform connections. Replace routes/bot.php to name the bot weather and enable the slack connection:
1<?php23use App\Ai\Agents\Assistant;4use Laravel\Converse\Facades\Converse;56Converse::agent('weather', Assistant::class)7 ->connection('slack');1<?php23use App\Ai\Agents\Assistant;4use Laravel\Converse\Facades\Converse;56Converse::agent('weather', Assistant::class)7 ->connection('slack');
The bot's name becomes part of its webhook path, so this bot receives Slack events at /converse/weather/slack. Once connected, the bot replies to direct messages and channel mentions. After someone mentions the bot in a channel thread, Converse subscribes the bot to that thread so follow-up replies don't need another mention.
To verify your bot registration, run the converse:list Artisan command:
1php artisan converse:list1php artisan converse:list
The output lists weather as an agent bot listening on slack and terminal. Converse attaches the terminal connection to every bot automatically so you can chat with it from the command line:
1+---------+-------+-------------------------+-----------------+----------+-----------+2| Bot | Kind | Handlers | Connections | Debounce | Schedules |3+---------+-------+-------------------------+-----------------+----------+-----------+4| weather | agent | App\Ai\Agents\Assistant | slack, terminal | 0s | - |5+---------+-------+-------------------------+-----------------+----------+-----------+1+---------+-------+-------------------------+-----------------+----------+-----------+2| Bot | Kind | Handlers | Connections | Debounce | Schedules |3+---------+-------+-------------------------+-----------------+----------+-----------+4| weather | agent | App\Ai\Agents\Assistant | slack, terminal | 0s | - |5+---------+-------+-------------------------+-----------------+----------+-----------+
Chatting With the Agent
Before connecting your agent to Slack, try it out locally in your terminal with converse:chat. Terminal chat runs synchronously in your shell, so it doesn't need a queue worker, a deployment, or a Slack App:
1php artisan converse:chat weather1php artisan converse:chat weather
Ask a question about the weather. As the agent responds, the terminal prints each tool call and its output, followed by the agent's reply, token count, and elapsed time:
1┌ You ─────────────────────────────────────────────────────────┐2│ Do I need a jacket in Lisbon? │3└──────────────────────────────────────────────────────────────┘45 ⋮ is thinking...6 ⋮ Running CurrentWeatherTool...7 ⏺ CurrentWeatherTool(city: "Lisbon") 812ms8 ⎿ Lisbon, Portugal: 18.4°C, wind 12.6 km/h.910 weather ───────────────────────────────────────────────────────11 It is 18°C and breezy in Lisbon, so a light jacket is enough.1213 498 tokens · 2.4s1┌ You ─────────────────────────────────────────────────────────┐2│ Do I need a jacket in Lisbon? │3└──────────────────────────────────────────────────────────────┘45 ⋮ is thinking...6 ⋮ Running CurrentWeatherTool...7 ⏺ CurrentWeatherTool(city: "Lisbon") 812ms8 ⎿ Lisbon, Portugal: 18.4°C, wind 12.6 km/h.910 weather ───────────────────────────────────────────────────────11 It is 18°C and breezy in Lisbon, so a light jacket is enough.1213 498 tokens · 2.4s
Type exit or press Escape to leave the chat.
Evaluating the Agent
Because an agent's wording varies from run to run, exact string assertions are brittle. Evals send real prompts to your agent and ask a model to grade whether each answer meets the criteria you describe. Agent Kit includes Pest's evals plugin, which provides the toSatisfy expectation. Replace the example eval in tests/Evals/AssistantTest.php with a test for your weather agent:
1<?php23use App\Ai\Agents\Assistant;45it('reports the weather for a city', function () {6 expect(Assistant::class)7 ->prompt('Do I need a jacket in Lisbon?')8 ->toSatisfy('Gives the current temperature in Lisbon');9});1<?php23use App\Ai\Agents\Assistant;45it('reports the weather for a city', function () {6 expect(Assistant::class)7 ->prompt('Do I need a jacket in Lisbon?')8 ->toSatisfy('Gives the current temperature in Lisbon');9});
Because this eval prompts Assistant directly rather than through a Converse thread, the agent doesn't receive the built-in tools Converse adds during chat, such as ListMessages.
Pest skips evals during normal test runs so your unit tests stay fast and free. Run your evals by passing --evals to the test Composer script:
1composer test -- --evals1composer test -- --evals
Evals send live requests to your AI provider and grade each answer with OpenAI by default, so every run incurs API costs. To grade answers using a different provider, set PEST_EVALS_LARAVEL_SCORING_PROVIDER and PEST_EVALS_LARAVEL_SCORING_MODEL in .env.
Deploying the Agent
Before you connect your bot to Slack, your application must be reachable at a public HTTPS URL so Slack can verify your webhook endpoint and deliver events. The fastest way to get your agent online is to deploy it to Laravel Cloud, which gives each environment a free laravel.cloud domain with HTTPS and lets you attach a custom domain later.
Push your application to a Git repository on GitHub, GitLab, or Bitbucket, then create a Laravel Cloud application from that repository. In your environment's settings, attach a database, enable a queue worker, and add your OPENAI_API_KEY environment variable before deploying. Converse processes every incoming Slack event on your queue, so a queue worker must be running for the bot to reply.
Once deployed, your bot's Slack webhook URL is your environment's domain followed by the bot's webhook path:
1https://weather-agent.laravel.cloud/converse/weather/slack1https://weather-agent.laravel.cloud/converse/weather/slack
If you'd rather try your agent in Slack before deploying, run composer run dev to start a local development server and queue worker together. Expose that server with a tunnel such as Expose, ngrok, or Cloudflare Tunnel, and enter the tunnel's HTTPS URL when converse:setup asks for your application's URL.
Connecting the Agent to Slack
Converse connects your bot to a chat platform through the converse:setup Artisan command. Make sure your bot is already registered on the slack connection in routes/bot.php, because Converse responds with a 404 status code to webhooks for any connection a bot isn't registered on. Run the setup command for Slack:
1php artisan converse:setup slack1php artisan converse:setup slack
The command walks you through creating the Slack App, writes its credentials to your local .env file, and points the Slack App at your bot's webhook URL. Copy the variables converse:setup wrote into your Laravel Cloud environment's variables and redeploy. Then run php artisan converse:setup slack again and enter your deployed URL. Re-run this command whenever your application's URL changes.
Next, invite the bot to each channel it should read by sending /invite @weather in the channel. The bot receives direct messages without an invitation.
Now mention @weather in a channel you invited it to. While CurrentWeatherTool runs, Slack shows the status "Running CurrentWeatherTool...", and the bot then replies in the thread.
If your bot uses slash commands, add them on your Slack App's Slash Commands page, since converse:setup doesn't create them for you. Running converse:setup slack again updates your existing slash commands to point at the new URL too.
If the bot doesn't reply to a mention, check that your environment has a running queue worker and that OPENAI_API_KEY is set.
Next Steps
Now that your weather agent is answering questions in Slack, you're ready to expand what it can do. To return structured output, require human tool approval, configure provider failover, or fake agents in your tests, check out the AI SDK documentation.
To send interactive cards, handle slash commands, or react to messages in chat, check out the Converse documentation. Its AI agents section explains built-in agent tools, tool approvals, and scheduled turns.
You may also connect your bot to Telegram or GitHub. Add the connections in routes/bot.php:
1use App\Ai\Agents\Assistant;2use Laravel\Converse\Facades\Converse;34Converse::agent('weather', Assistant::class)5 ->connection('slack', 'telegram', 'github');1use App\Ai\Agents\Assistant;2use Laravel\Converse\Facades\Converse;34Converse::agent('weather', Assistant::class)5 ->connection('slack', 'telegram', 'github');
Then run converse:setup for each new connection, such as php artisan converse:setup telegram.
Agent Kit also ships with Laravel MCP, and config/mcp.php already defines clients for GitHub, Linear, and Playwright. To give your agent the tools from an MCP server, return them from its tools method in app/Ai/Agents/Assistant.php:
1use App\Ai\Tools\CurrentWeatherTool;2use Laravel\Mcp\Facades\Mcp;34/**5 * Get the tools available to the agent.6 *7 * @return list<Agent|Tool|ProviderTool>8 */9public function tools(): iterable10{11 return [12 new CurrentWeatherTool,13 ...Mcp::client('github')->tools(),14 ];15}1use App\Ai\Tools\CurrentWeatherTool;2use Laravel\Mcp\Facades\Mcp;34/**5 * Get the tools available to the agent.6 *7 * @return list<Agent|Tool|ProviderTool>8 */9public function tools(): iterable10{11 return [12 new CurrentWeatherTool,13 ...Mcp::client('github')->tools(),14 ];15}
The github client authenticates with a GitHub personal access token, so set MCP_GITHUB_TOKEN in .env before returning its tools.