illuma-law/healthcheck-ai 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

illuma-law/healthcheck-ai

Composer 安装命令:

composer require illuma-law/healthcheck-ai

包简介

Focused AI failover chain and agent registry health checks for Spatie's Laravel Health package.

README 文档

README

Tests Packagist License Latest Stable Version

A comprehensive suite of AI health checks for Spatie's Laravel Health package.

This package provides robust health checks specifically designed to monitor your AI integrations, ensuring that your LLM prompt providers, embedding chains, and AI Agent registries are operational and properly configured.

Features

  • Prompt Chain Check: Validates your LLM failover chains (e.g., OpenAI → Anthropic) by sending a small canary prompt.
  • Embedding Chain Check: Verifies that your embedding providers are generating vectors with the expected dimensions.
  • Agent Registry Check: Inspects your AI agents to ensure that Model and Provider attributes are present and that the corresponding API credentials exist in your environment.
  • Caching: Expensive API calls to AI providers are cached to prevent your health check endpoint from exhausting your rate limits.

Installation

Require this package with composer:

composer require illuma-law/healthcheck-ai

Configuration

You can publish the configuration file to customize the default cache TTLs, embedding dimensions, and canary texts used during the checks:

php artisan vendor:publish --tag="healthcheck-ai-config"

This will create a config/healthcheck-ai.php file:

return [
    // How long to cache embedding check results to save API calls
    'embedding_cache_ttl_seconds' => 300,
    
    // Default expected dimensions for vector embeddings
    'embedding_dimensions' => 1024,
    
    // The short text sent to the embedding provider
    'embedding_canary_text' => 'AI embedding health check',
    
    // How long to cache the LLM prompt check results
    'prompt_cache_ttl_seconds' => 300,
    
    // The prompt sent to the LLM to verify it is responsive
    'prompt_text' => 'Reply with exactly: OK',
    
    // Request timeout in seconds
    'prompt_timeout_seconds' => 25,
];

Usage & Integration

Add the checks to your Health::checks() registration within a Service Provider (usually AppServiceProvider).

1. Prompt Chain Check

This check monitors a sequence of LLM providers. If the primary provider fails but a fallback succeeds, it marks the health check as degraded (Warning) instead of failing completely.

use IllumaLaw\HealthCheckAi\AiPromptChainHealthCheck;
use Spatie\Health\Facades\Health;

Health::checks([
    AiPromptChainHealthCheck::new()
        ->cacheTtl(600) // Optional override
        ->timeout(10) // Optional override
        ->resolveChainUsing(function () {
            // Define your fallback chain
            return [
                ['provider' => 'openai', 'model' => 'gpt-4o'],
                ['provider' => 'anthropic', 'model' => 'claude-3-5-sonnet-latest'],
            ];
        }),
]);

2. Embedding Chain Check

This check is vital if you rely on vector embeddings (e.g., pgvector or Typesense). It queries your embedding models and verifies that the output vectors match your expected dimensions.

use IllumaLaw\HealthCheckAi\AiEmbeddingChainHealthCheck;
use Spatie\Health\Facades\Health;

Health::checks([
    AiEmbeddingChainHealthCheck::new()
        ->dimensions(1536) // e.g., OpenAI text-embedding-3-small
        ->resolveChainUsing(function () {
            return [
                ['provider' => 'openai', 'model' => 'text-embedding-3-small'],
            ];
        }),
]);

3. Agent Registry Check

If you are using the laravel/ai SDK with attributes for Agents, this check inspects a given list of Agent classes using PHP Reflection. It verifies that each class defines its Provider and Model attributes and that your application has the credentials required for that provider.

use IllumaLaw\HealthCheckAi\AiAgentRegistryCheck;
use Spatie\Health\Facades\Health;

Health::checks([
    AiAgentRegistryCheck::new()
        ->resolveAgentsUsing(function () {
            // Return a list of your Agent class names
            return [
                 \App\Agents\SupportAgent::class,
                 \App\Agents\SummarizerAgent::class,
            ];
        })
        ->hasCredentialsUsing(function (string $provider) {
            // Define how to check if credentials exist for a given provider
            if ($provider === 'openai') {
                return !empty(config('ai.providers.openai.api_key'));
            }
            if ($provider === 'anthropic') {
                return !empty(config('ai.providers.anthropic.api_key'));
            }
            return false;
        }),
]);

Testing

Run the test suite:

composer test

License

The MIT License (MIT). Please see License File for more information.

illuma-law/healthcheck-ai 适用场景与选型建议

illuma-law/healthcheck-ai 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 62 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「health」 「laravel」 「ai」 「llm」 「illuma-law」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 illuma-law/healthcheck-ai 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 illuma-law/healthcheck-ai 我们能提供哪些服务?
定制开发 / 二次开发

基于 illuma-law/healthcheck-ai 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 62
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 40
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-20