Skip to content

Feature/add ai collector - #2061

Merged
barryvdh merged 7 commits into
fruitcake:masterfrom
NielsSmits1:feature/add-ai-collector
Jul 2, 2026
Merged

Feature/add ai collector#2061
barryvdh merged 7 commits into
fruitcake:masterfrom
NielsSmits1:feature/add-ai-collector

Conversation

@NielsSmits1

Copy link
Copy Markdown
Contributor

Add AiCollector for laravel/ai agent runs

Adds an AiCollector (and provider) that shows each laravel/ai agent invocation in the debug bar as a single entry: prompt, instructions, model/provider, tool calls and token usage. Built in the same style as the existing PennantCollector.

Screenshot 2026-07-02 at 11 09 28

How it works

  • One entry per invocation. ToolInvoked fires during a run and AgentPrompted at the end; tool calls are buffered by invocationId and folded into the entry recorded on AgentPrompted (AgentStreamed is handled identically).
  • Guarded, zero overhead when unused. The provider only registers when Laravel\Ai\AiManager exists — apps without laravel/ai are unaffected, just like PennantCollectorProvider guards on FeatureManager.
  • No new front-end assets. Reuses the existing JsonVariableListWidget / HtmlVariableListWidget / VariableListWidget, chosen the same way as SessionCollector / RouteCollector.
  • Kept lean. Prompt/response/tool bodies are truncated at 20k chars; attachments are counted only.

Configuration

'collectors' => [
    'ai' => env('DEBUGBAR_COLLECTORS_AI', true),
],
'options' => [
    'ai' => [
        'values' => env('DEBUGBAR_OPTIONS_AI_VALUES', true), // Collect prompt/response/tool bodies
    ],
],

Set 'values' => false for metadata only (agent, model, provider, usage, attachment count), handy when prompts are sensitive or large. laravel/ai is added to require-dev only — never a hard require.

Tests

AiCollectorTest (5 tests): provider registration, folding tool calls into the matching invocation, per-invocation buffer consumption, the values toggle, and truncation.

Caveat

Debugbar captures data per HTTP request, so you only see AI runs for synchronous calls (QUEUE_CONNECTION=sync or inline); for queued jobs a Telescope watcher fits better.

Niels Smits and others added 7 commits July 2, 2026 10:21
Adds an AiCollector (and provider) in the style of PennantCollector, showing
each laravel/ai agent invocation as a single entry with the prompt, instructions,
model/provider, tool calls and token usage.

The provider only registers when Laravel\Ai\AiManager exists, so apps without
laravel/ai are unaffected. laravel/ai is added to require-dev only. Tool calls
are buffered per invocationId and folded into the entry recorded on AgentPrompted.
Prompt/response/tool bodies are truncated at 20k chars; the 'ai.values' option
disables body collection for sensitive prompts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Covers provider registration (guarded on laravel/ai), folding buffered tool
calls into the matching invocation, per-invocation buffer consumption, the
'values' toggle omitting prompt/response/tool bodies, and body truncation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
build/report.junit.xml is generated by PHPUnit (phpunit.xml.dist logging) and
should not be committed. Remove it from tracking and ignore it, consistent with
the existing /build/phpstan and /build/docs entries.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Removed step to remove incompatible PHP dependencies for version 8.2.
@barryvdh
barryvdh merged commit d103d12 into fruitcake:master Jul 2, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants