LarAgent v0.7: MCP, Native Events & More!

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 AgentListener

Register it in your AppServiceProvider:

Event::listen(
    \LarAgent\Events\AgentInitialized::class,
    \App\Listeners\AgentListener::class
);

πŸ”Ή Main Lifecycle Events

EventDescription
AgentInitializedFired when agent setup completes
ConversationStartedFired when a new response begins
ConversationEndedFired when response completes
ToolChangedFired when tools are dynamically added/removed
AgentClearedFired when agent history resets
EngineErrorFired when LLM engine throws exception

πŸ”Ή Hook Events (Before/After)

EventPurpose
BeforeResponse / AfterResponseAround LLM calls
BeforeToolExecution / AfterToolExecutionTrack or modify tool runs
BeforeSaveHistoryIntercept history saving
BeforeStructuredOutputValidate 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() and make() β€” faster, cleaner message handling
  • 🧩 Full MCP integration for dynamic external tools
  • πŸ”” Laravel events for lifecycle and hooks
  • πŸ—οΈ Improved chat-history customization

Happy coding! πŸš€