AI agents in Laravel with Laragents
说明与用途
Laragents 通过提供工具调用循环、上下文压缩、记忆持久化和规则处理,简化了 Laravel 中 AI 代理的集成。
问题
Integrating AI agents into Laravel applications requires handling tool loops, context management, memory, and rules beyond simple model calls.
结果
Laragents streamlines AI agent integration in Laravel, reducing boilerplate, preventing infinite loops, managing context efficiently, and persisting memory and rules across sessions.
工作流
- Install Laragents via Composer and publish config/migrations
- Define domain tools by extending the Tool class and implementing name, description, schema, and execute
- Configure the loop with model, session, context, and tool registry
- Run the loop to handle tool calls and generate responses
- Implement context compression to keep conversation within token limits
- Persist memory in a queued job after compression or on scheduled sweep
- Read memory and rules into the prompt before each model call
- Handle empty‑streaks and iteration caps to avoid infinite loops
证据
I wrote all of that twice, in two applications, and the second time I extracted it. It is called laragents.
Two things in there are not obvious until they cost you something.
The third one reads like access control and is not.
- 记录日期: 2026-09-05T16:33:02.907Z