Skip to main content

Laravel AI integration

Use sanvex/laravel-ai to give Laravel AI agents access to Sanvex drivers (GitHub, Gmail, Slack, and others) as tools.

Install

Requires sanvex/core, laravel/ai ^0.6.0, and Laravel 12 or 13. Configure at least one driver first (Integration guide or Quickstart). The package registers SanvexAi as app(SanvexAi::class) or app('sanvex.ai').

Add tools to an agent

Implement HasTools and return Sanvex tools from tools():
The agent receives one tool per operation (for example Sanvex_Github_Repositories_List) with parameters the model can fill in directly. Gmail messages.list returns subject, from, to, date, and snippet (not raw IDs only). Use readOnly() for inbox assistants. Inject SanvexAi in a controller or action instead of app() if you prefer:

Choose an approach

Recommendation: start with per-operation tools for the drivers you need. Add the router only when you have a clear reason.

Per-operation tools

One driver

Several drivers

Read-only agents

Safe default for support or reporting bots:

Allow only specific actions

Block dangerous actions

Exclude a whole resource

Combine filters

only() and except() stack; readOnly() applies last.

Filter patterns (multi-driver)

With one driver, short names are enough: repositories.delete, issues.list. With several drivers, prefix by driver when resource names overlap (for example repositories on GitHub and Bitbucket):

Generic router tool

A single tool accepts JSON: driver, resource, action, args.
Limit which drivers the model may use:
driver: "system" is always allowed so the model can discover what exists. Discover drivers (all registered):
Configured drivers only:
Call an operation (example):
Use args: {} when an action takes no parameters.

Mix both approaches

Common pattern: typed GitHub tools plus a router for less-used integrations.

Inspect drivers without calling the API

Useful when building prompts or debugging agent setup:
Each entry includes whether the driver is configured and which resources/actions are available.

Multi-tenant apps

Out of the box, tools resolve credentials for the global Sanvex scope. For per-user accounts, resolve drivers with your tenant context before the agent runs, or wrap tool execution so SanvexManager::for($owner) applies for that request. See Tenancy.

Troubleshooting

  • Usage — call drivers directly in PHP
  • MCP — expose Sanvex to Cursor, Claude Desktop, and other MCP clients
  • Packages — which Composer packages to install