How to Install Neuron AI and Build Your First Agent in a Webman PHP App

This guide walks you through installing the Webman framework, adding the Neuron AI package via Composer, generating a custom Agent class, configuring its provider with an API key, and interacting with the agent through a controller to receive responses from a large language model.

Open Source Tech Hub
Open Source Tech Hub
Open Source Tech Hub
How to Install Neuron AI and Build Your First Agent in a Webman PHP App

Chapter Introduction

This section explains how to install Neuron AI in a Webman application and create an Agent.

Requirements

PHP ^8.4

Composer ^2.0

Installation

Run the following Composer commands to install the latest versions.

Install Webman framework

Official documentation: https://www.workerman.net/doc/webman/install.html

# Default interactive installer
composer create-project workerman/webman:~2.0

# Disable interactive installer (used in this guide)
composer create-project workerman/webman:~2.0 --no-interaction neuron.ai.tinywan.com

Install Neuron framework

composer require neuron-core/neuron-ai

Create an Agent

Use the command below to generate your first Agent class.

./vendor/bin/neuron make:agent app\
euron\\ZaiAgent

The generated class looks like the following:

<?php
/**
 * @desc ZaiAgent
 * @author Tinywan(ShaoBo Wan)
 */
declare(strict_types=1);

namespace app
euron;

use NeuronAI\Agent\Agent;
use NeuronAI\Agent\SystemPrompt;
use NeuronAI\Providers\AIProviderInterface;
use NeuronAI\Providers\ZAI\ZAI;

class ZaiAgent extends Agent
{
    protected function provider(): AIProviderInterface
    {
        return new ZAI(
            key: "sk-xxxx",
            model: "glm-5",
            parameters: [], // Add custom params (temperature, logprobs, etc)
        );
    }

    public function instructions(): string
    {
        return (string) new SystemPrompt(
            background: [
                "你是由开源技术小栈开发的 Agent。",
            ],
        );
    }
}

Obtain an API key at https://bigmodel.cn/usercenter/proj-mgmt/apikeys

Chat with the Agent

Send a prompt to the Agent and retrieve the LLM response:

<?php
/**
 * @desc ZaiAgent
 * @author Tinywan(ShaoBo Wan)
 */
declare(strict_types=1);

namespace app\controller;

use support\Request;
use NeuronAI\Chat\Messages\UserMessage;

class IndexController
{
    public function index(Request $request)
    {
        $message = \app
euron\ZaiAgent::make()
            ->chat(new UserMessage('你是是大模型?'))
            ->getMessage();
        return $message->getContent();
    }
}
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LLMAgentPHPComposerWebmanNeuron AI
Open Source Tech Hub
Written by

Open Source Tech Hub

Sharing cutting-edge internet technologies and practical AI resources.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.