Laravel AI integration
Usesanvex/laravel-ai to give Laravel AI agents access to Sanvex drivers (GitHub, Gmail, Slack, and others) as tools.
Install
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
ImplementHasTools and return Sanvex tools from tools():
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.
driver: "system" is always allowed so the model can discover what exists.
Discover drivers (all registered):
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: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 soSanvexManager::for($owner) applies for that request.
See Tenancy.
