Skip to content

v0.3.1 - Fix multi-loop trait collision

Choose a tag to compare

@dalehurley dalehurley released this 18 Feb 20:22
· 10 commits to main since this release

Bug Fix

Fatal error when composing multiple loop traits

Agents using more than one loop trait together (e.g. ReActLoop, ChainOfThoughtLoop, PlanExecuteLoop) would crash on instantiation with a PHP fatal error:

```
Trait method Laragentic\Loops\ChainOfThoughtLoop::onMaxIterationsReached has not been applied
because of collision with Laragentic\Loops\ReActLoop::onMaxIterationsReached
```

Root cause: ReActLoop and ChainOfThoughtLoop both defined 9 identical methods. PHP requires trait method collisions to be explicitly resolved in the consuming class, which isn't feasible to ask every agent author to do.

Fix: Shared methods have been extracted into two new concern traits:

  • Laragentic\Concerns\HasIterationCallbacks — shared iteration-phase callback registrations (onMaxIterationsReached, onIterationStart, onIterationEnd, onBeforeAction, onAfterAction)
  • Laragentic\Concerns\ExecutesLoopTools — shared tool execution helpers (executeLoopToolCalls, executeLoopTool, resolveToolMap, formatObservation)

PHP de-duplicates traits that appear via multiple paths, so any combination of loop traits now composes cleanly.

No breaking changes

All existing public APIs are unchanged. Agents using a single loop trait are unaffected. The formatObservation() method remains overridable. ReActLoop gains a new overridable buildReActObservation() method for customising the full ReAct observation prompt (guidance text + tool results).

Upgrading

No changes required. Update your composer.json constraint to ^0.3.1 and run composer update.