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:
composer create-project laravel/agent-kit my-agentThis 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:
OPENAI_API_KEY=sk-your-keyYou 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:
<?php
namespace App\Ai\Agents;
use Laravel\Ai\Concerns\RemembersConversations;
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Contracts\Conversational;
use Laravel\Ai\Contracts\HasTools;
use Laravel\Ai\Contracts\Tool;
use Laravel\Ai\Promptable;
use Laravel\Ai\Providers\Tools\ProviderTool;
use Stringable;
class Assistant implements Agent, Conversational, HasTools
{
use Promptable, RemembersConversations;
/**
* Get the instructions that the agent should follow.
*/
public function instructions(): Stringable|string
{
return <<<'MD'
You are a helpful assistant.
MD;
}
/**
* Get the tools available to the agent.
*
* @return list<Agent|Tool|ProviderTool>
*/
public function tools(): iterable
{
return [
// ...Mcp::client('github')->tools(),
];
}
}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:
You are a weather assistant for a team spread across many cities.
Answer questions about the weather and nothing else. Keep replies to a
sentence or two. You are talking in a chat window, not writing a report.
Always name the city a reading is for.
Today is {{ now()->toFormattedDateString() }}.Next, update app/Ai/Agents/Assistant.php so its instructions method returns that view:
/**
* Get the instructions that the agent should follow.
*/
public function instructions(): Stringable|string
{
return view('instructions.assistant');
}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:
php artisan make:tool CurrentWeatherToolEvery 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:
<?php
namespace App\Ai\Tools;
use Illuminate\Contracts\JsonSchema\JsonSchema;
use Illuminate\Support\Facades\Http;
use Laravel\Ai\Contracts\Tool;
use Laravel\Ai\Tools\Request;
use Stringable;
class CurrentWeatherTool implements Tool
{
/**
* Get the description of the tool's purpose.
*/
public function description(): Stringable|string
{
return 'Get the current weather in a city.';
}
/**
* Execute the tool.
*/
public function handle(Request $request): Stringable|string
{
$city = $request->string('city')->trim()->toString();
$place = Http::get('https://geocoding-api.open-meteo.com/v1/search', [
'name' => $city,
'count' => 1,
])->json('results.0');
if ($place === null) {
return "No city named [{$city}] could be found. Ask the user to confirm the spelling.";
}
$current = Http::get('https://api.open-meteo.com/v1/forecast', [
'latitude' => $place['latitude'],
'longitude' => $place['longitude'],
'current' => 'temperature_2m,wind_speed_10m',
])->json('current');
return "{$place['name']}, {$place['country']}: {$current['temperature_2m']}°C, wind {$current['wind_speed_10m']} km/h.";
}
/**
* Get the tool's schema definition.
*/
public function schema(JsonSchema $schema): array
{
return [
'city' => $schema->string()
->description('The city to look up, such as "Lisbon" or "Austin, Texas".')
->required(),
];
}
}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:
use App\Ai\Tools\CurrentWeatherTool;
/**
* Get the tools available to the agent.
*
* @return list<Agent|Tool|ProviderTool>
*/
public function tools(): iterable
{
return [
new CurrentWeatherTool,
];
}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:
You are a weather assistant for a team spread across many cities.
Use the `CurrentWeatherTool` tool before answering any question about the weather.
It is your only source, so never answer from memory.
Answer questions about the weather and nothing else. Keep replies to a
sentence or two. You are talking in a chat window, not writing a report.
Always name the city a reading is for.
Today 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:
<?php
use App\Ai\Agents\Assistant;
use Laravel\Converse\Facades\Converse;
Converse::agent('weather', Assistant::class)
->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:
php artisan converse:listThe 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:
+---------+-------+-------------------------+-----------------+----------+-----------+
| Bot | Kind | Handlers | Connections | Debounce | Schedules |
+---------+-------+-------------------------+-----------------+----------+-----------+
| weather | agent | App\Ai\Agents\Assistant | slack, terminal | 0s | - |
+---------+-------+-------------------------+-----------------+----------+-----------+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:
php artisan converse:chat weatherAsk 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:
┌ You ─────────────────────────────────────────────────────────┐
│ Do I need a jacket in Lisbon? │
└──────────────────────────────────────────────────────────────┘
⋮ is thinking...
⋮ Running CurrentWeatherTool...
⏺ CurrentWeatherTool(city: "Lisbon") 812ms
⎿ Lisbon, Portugal: 18.4°C, wind 12.6 km/h.
weather ───────────────────────────────────────────────────────
It is 18°C and breezy in Lisbon, so a light jacket is enough.
498 tokens · 2.4sType 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:
<?php
use App\Ai\Agents\Assistant;
it('reports the weather for a city', function () {
expect(Assistant::class)
->prompt('Do I need a jacket in Lisbon?')
->toSatisfy('Gives the current temperature in Lisbon');
});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:
composer test -- --evalsWarning
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:
https://weather-agent.laravel.cloud/converse/weather/slackNote
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:
php artisan converse:setup slackThe 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.
Note
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:
use App\Ai\Agents\Assistant;
use Laravel\Converse\Facades\Converse;
Converse::agent('weather', Assistant::class)
->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:
use App\Ai\Tools\CurrentWeatherTool;
use Laravel\Mcp\Facades\Mcp;
/**
* Get the tools available to the agent.
*
* @return list<Agent|Tool|ProviderTool>
*/
public function tools(): iterable
{
return [
new CurrentWeatherTool,
...Mcp::client('github')->tools(),
];
}The github client authenticates with a GitHub personal access token, so set MCP_GITHUB_TOKEN in .env before returning its tools.