LarAgent v0.7: MCP, Native Events & More!
This release focuses on fast, stateless interactions, dynamic capability via MCP, and deep Laravel-native observability through events.
π New Methods
LarAgent introduces two new, developer-friendly methods for interacting with agents without maintaining persistent chat histories.
πΉ ask() β one-liner interaction
Ideal for quick, stateless prompts:
echo WeatherAgent::ask('What is the weather like?');πΉ make() β chainable syntax
Gives you more control while staying clean and expressive, replacing "for" method:
echo WeatherAgent::make()
->message('What is the weather like?')
->temperature(0.7)
->respond();Use make() when you need a temporary agent instance with custom temperature, model, or configuration but no stored chat history.
π§© Model Context Protocol (MCP) Integration
LarAgent now supports MCP β the Model Context Protocol, enabling agents to dynamically load tools and resources from external MCP servers.
βοΈ Configuration Example
'mcp_servers' => [
'github' => [
'type' => \Redberry\MCPClient\Enums\Transporters::HTTP,
'base_url' => 'https://api.githubcopilot.com/mcp',
'timeout' => 30,
'token' => env('GITHUB_API_TOKEN', null),
],
'mcp_server_memory' => [
'type' => \Redberry\MCPClient\Enums\Transporters::STDIO,
'command' => ['npx', '-y', '@modelcontextprotocol/server-memory'],
'timeout' => 30,
'cwd' => base_path(),
],
],π§ Dynamic MCP Registration
Define MCP servers in your agent via:
protected $mcpServers = ['github', 'mcp_server_memory'];Or dynamically:
public function registerMcpServers() {
return [
'github:tools|only:get_issues',
'mcp_server_memory:resources'
];
}
New implementation supports the manual use too of tools and resources from MCP servers. Learn more here: https://docs.laragent.ai/core-concepts/mcp
π Laravel Native Events Support
LarAgent now dispatches Laravel events for every key lifecycle action β letting you listen, log, or modify agent behavior with your own listeners.
π§© Quickstart
Generate a listener:
php artisan make:listener AgentListenerRegister it in your AppServiceProvider:
Event::listen(
\LarAgent\Events\AgentInitialized::class,
\App\Listeners\AgentListener::class
);πΉ Main Lifecycle Events
| Event | Description |
|---|---|
AgentInitialized | Fired when agent setup completes |
ConversationStarted | Fired when a new response begins |
ConversationEnded | Fired when response completes |
ToolChanged | Fired when tools are dynamically added/removed |
AgentCleared | Fired when agent history resets |
EngineError | Fired when LLM engine throws exception |
πΉ Hook Events (Before/After)
| Event | Purpose |
|---|---|
BeforeResponse / AfterResponse | Around LLM calls |
BeforeToolExecution / AfterToolExecution | Track or modify tool runs |
BeforeSaveHistory | Intercept history saving |
BeforeStructuredOutput | Validate structured responses |
Each event provides an AgentDTO with full agent configuration and context.
β‘ Other Improvements
Improved chat-history behavior with customizable random keys:
protected static function generateRandomKey(): string {
return self::class . '-' . Session::get('latest_topic');
}π Summary
v0.7 Highlights
- β¨
ask()andmake()β faster, cleaner message handling - π§© Full MCP integration for dynamic external tools
- π Laravel events for lifecycle and hooks
- ποΈ Improved chat-history customization
Happy coding! π