lyre/ai-agents 问题修复 & 功能扩展

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

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

lyre/ai-agents

Composer 安装命令:

composer require lyre/ai-agents

包简介

Forward-only Agents/Bots orchestration on top of Laravel + OpenAI Responses API.

README 文档

README

Forward-only Agents/Bots package using OpenAI Responses API with first-class Laravel orchestration.

Install

composer require lyre/ai-agents
php artisan vendor:publish --tag=ai-agents-config
php artisan vendor:publish --tag=ai-agents-migrations
php artisan migrate

Quick start

use Lyre\AiAgents\Facades\Agents;

Agents::registerTool([
    'name' => 'lookup_customer',
    'type' => 'function',
    'description' => 'Lookup customer by phone',
    'parameters_schema' => [
        'type' => 'object',
        'properties' => [
            'phone' => ['type' => 'string'],
        ],
        'required' => ['phone'],
    ],
    'handler' => fn (array $args) => ['customer' => ['phone' => $args['phone'], 'tier' => 'gold']],
]);

$agent = Agents::registerAgent([
    'name' => 'support-bot',
    'model' => 'gpt-4.1-mini',
    'instructions' => 'You are a support specialist.',
    'temperature' => 0.2,
    'max_output_tokens' => 800,
]);

$result = Agents::run($agent->id, 'Find customer with phone +254700111222', [
    'user_id' => auth()->id(),
    'ip' => request()->ip(),
]);

Streaming

$stream = Agents::stream('support-bot', 'Explain invoice #INV-22');

foreach ($stream as $chunk) {
    echo $chunk;
}

Prompt templates

Templates live in ai_agents_prompt_templates and are linked to an agent via agents.prompt_template_id. The resolver renders template content with {{variable}} substitution and supports inheritance.

Inheritance

Set extends_template_id on a template to compose it on top of a parent. The resolver walks root → leaf and concatenates content with the configured separator (default \n\n). Inheritance is depth-capped (prompts.max_inheritance_depth, default 3) and cycle-safe — on detection the resolver logs a warning and falls back to the leaf alone.

Variables

Any {{token}} in a template is substituted at resolve time. Variables are merged from these sources, lowest-to-highest priority:

  1. Each template's variables JSON column (parent first, child overrides).
  2. System defaults: assistant_name, agent_id, model.
  3. agent.metadata.template_variables.
  4. Caller-supplied map passed to resolveInstructionsForAgent($agent, $variables).

Section contributors

Host apps can append extra sections to the resolved prompt without forking the resolver:

use Lyre\AiAgents\Contracts\PromptSectionContributor;
use Lyre\AiAgents\Models\Agent;

class ImageCatalogSection implements PromptSectionContributor
{
    public function name(): string { return 'image_catalog'; }
    public function shouldApply(Agent $agent): bool { /* … */ }
    public function render(Agent $agent): ?string { /* … */ }
}

// In a service provider:
$this->app->bind(ImageCatalogSection::class);
$this->app->tag([ImageCatalogSection::class], PromptSectionContributor::TAG);

Structured output (text.format)

Set agent.metadata.response_format to a Responses API JSON-schema config and the runner forwards it as text.format on every call:

$agent->metadata = array_merge($agent->metadata ?? [], [
    'response_format' => [
        'type' => 'json_schema',
        'name' => 'kenchic_whatsapp_response',
        'strict' => true,
        'schema' => [/* … */],
    ],
]);
$agent->save();

Built-in tools

Lead capture (submit_lead)

app(\Lyre\AiAgents\Services\AgentKnowledgeService::class)
    ->ensureLeadToolForAllAgents('https://your-app.test/api/leads');

The tool name is config-driven via tools.lead.tool_name (default submit_lead). Any agent that previously had the legacy submit_lead_to_axis tool will be migrated idempotently on next call.

Human handover (request_human_handover)

app(\Lyre\AiAgents\Services\AgentKnowledgeService::class)
    ->ensureHandoverToolForAllAgents('https://your-app.test/api/handover');

The handler endpoint receives the function-call arguments plus Lyre's run/conversation context and is responsible for whatever handover semantics the host app needs (flipping a flag, paging on-call, etc.).

Events dispatched

  • Lyre\AiAgents\Events\AgentRunStarted
  • Lyre\AiAgents\Events\AgentToolCalled
  • Lyre\AiAgents\Events\AgentRunCompleted
  • Lyre\AiAgents\Events\AgentRunFailed
  • Lyre\AiAgents\Events\ConversationUpdated
  • Lyre\AiAgents\Events\UsageRecorded

Local development

"repositories": [
    {
        "type": "path",
        "url": "../packages/lyre-ai-agents-laravel",
        "options": {
            "symlink": true
        }
    }
]

Frontend safety

  • Frontend should call your backend proxy route, not OpenAI directly.
  • If direct OpenAI is needed, use short-lived scoped credentials in trusted environments only.

Output length limits

Two optional env vars bound how long an agent's reply can be. Both default to unset, which keeps the prior behaviour (no character cap; the agent's own max_output_tokens, if any, is used).

# Global fallback for max_output_tokens when an agent has none set (native OpenAI limit).
AI_AGENTS_MAX_OUTPUT_TOKENS=800

# Hard cap on the final assistant TEXT, enforced by the package via truncation
# (OpenAI has no character limit). Skipped for structured json_schema responses.
AI_AGENTS_MAX_OUTPUT_CHARACTERS=1000

Precedence for tokens: the agent's own max_output_tokens column wins; otherwise AI_AGENTS_MAX_OUTPUT_TOKENS; otherwise unset. max_output_characters truncates the final output_text (and the stored assistant message) to that many characters. For live SSE streaming, deltas are forwarded verbatim, so use max_output_tokens to bound what streams in real time — the character cap backstops the persisted/returned text.

Table naming

By default, the package uses these tables: agents, agent_tools, conversations, conversation_messages, agent_runs, usage_logs, events.

You can set a global prefix for multi-project flexibility:

AI_AGENTS_TABLE_PREFIX=axis_

Or override individual table names:

AI_AGENTS_TABLE_CONVERSATIONS=axis_conversations
AI_AGENTS_TABLE_CONVERSATION_MESSAGES=axis_conversation_messages

lyre/ai-agents 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-18