For the complete documentation index, see llms.txt. This page is also available as Markdown.

安装

逐步说明如何在您的应用中安装 Neuron 并创建智能体。

要求

  • PHP:^8.1

安装

运行下面的 composer 命令以安装最新版本:

composer require neuron-core/neuron-ai

创建一个 Agent

您可以使用下面的命令轻松创建您的第一个 agent:

./vendor/bin/neuron make:agent App\\Neuron\\MyAgent
.\vendor\bin\neuron make:agent App\Neuron\MyAgent
namespace App\Neuron;

use NeuronAI\Agent\Agent;
use NeuronAI\Agent\SystemPrompt;
use NeuronAI\Providers\Anthropic\Anthropic;

class MyAgent extends Agent
{
    protected function provider(): AIProviderInterface
    {
        // 返回一个 AI 提供商(Anthropic、OpenAI、Ollama、Gemini 等)
        return new Anthropic(
            key: 'ANTHROPIC_API_KEY',
            model: 'ANTHROPIC_MODEL',
        );
    }

    public function instructions(): string
    {
        return (string) new SystemPrompt(
            background: ["你是一个使用 Neuron 框架创建的友好 AI Agent。"],
        );
    }
}

与 Agent 对话

向 agent 发送提示,以从底层 LLM 获取响应:

监控与调试

你使用 Neuron 构建的许多应用都会包含多个步骤,以及对 LLM 调用、工具、外部记忆系统等的多次调用。随着这些应用变得越来越复杂,能够检查你的 agentic 系统内部究竟发生了什么就变得至关重要。做到这一点的最佳方式是借助 Inspector.

Laravel 应用程序视频教程

最后更新于