1. Go to this page and download the library: Download inspector-apm/neuron-ai library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
inspector-apm / neuron-ai example snippets
namespace App\Neuron;
use NeuronAI\Agent;
use NeuronAI\SystemPrompt;
use NeuronAI\Providers\AIProviderInterface;
use NeuronAI\Providers\Anthropic\Anthropic;
class DataAnalystAgent extends Agent
{
public function provider(): AIProviderInterface
{
return new Anthropic(
key: 'ANTHROPIC_API_KEY',
model: 'ANTHROPIC_MODEL',
);
}
public function instructions(): string
{
return new SystemPrompt(
background: [
"You are a data analyst expert in creating reports from SQL databases."
]
);
}
}
$agent = DataAnalystAgent::make();
$response = $agent->chat(
new UserMessage("Hi, I'm Valerio. Who are you?")
);
echo $response->getContent();
// I'm a data analyst. How can I help you today?
$response = $agent->chat(
new UserMessage("Do you know my name?")
);
echo $response->getContent();
// Your name is Valerio, as you said in your introduction.
namespace App\Neuron;
use NeuronAI\Agent;
use NeuronAI\Providers\AIProviderInterface;
use NeuronAI\Providers\Anthropic\Anthropic;
use NeuronAI\SystemPrompt;
use NeuronAI\Tools\ToolProperty;
use NeuronAI\Tools\Tool;
use NeuronAI\Tools\Toolkits\MySQL\MySQLToolkit;
class DataAnalystAgent extends Agent
{
public function provider(): AIProviderInterface
{
return new Anthropic(
key: 'ANTHROPIC_API_KEY',
model: 'ANTHROPIC_MODEL',
);
}
public function instructions(): string
{
return new SystemPrompt(
background: [
"You are a data analyst expert in creating reports from SQL databases."
]
);
}
public function tools(): array
{
return [
MySQLToolkit:make(
\DB::connection()->getPdo()
),
];
}
}
namespace App\Neuron;
use NeuronAI\Agent;
use NeuronAI\MCP\McpConnector;
use NeuronAI\Providers\AIProviderInterface;
use NeuronAI\Providers\Anthropic\Anthropic;
use NeuronAI\Tools\ToolProperty;
use NeuronAI\Tools\Tool;
class DataAnalystAgent extends Agent
{
public function provider(): AIProviderInterface
{
...
}
public function instructions(): string
{
...
}
public function tools(): array
{
return [
// Connect to an MCP server
...McpConnector::make([
'command' => 'npx',
'args' => ['-y', '@modelcontextprotocol/server-everything'],
])->tools(),
];
}
}
namespace App\Neuron;
use NeuronAI\Providers\AIProviderInterface;
use NeuronAI\Providers\Anthropic\Anthropic;
use NeuronAI\RAG\Embeddings\EmbeddingsProviderInterface;
use NeuronAI\RAG\Embeddings\VoyageEmbeddingProvider;
use NeuronAI\RAG\RAG;
use NeuronAI\RAG\VectorStore\PineconeVectorStore;
use NeuronAI\RAG\VectorStore\VectorStoreInterface;
class MyChatBot extends RAG
{
public function provider(): AIProviderInterface
{
return new Anthropic(
key: 'ANTHROPIC_API_KEY',
model: 'ANTHROPIC_MODEL',
);
}
public function embeddings(): EmbeddingsProviderInterface
{
return new VoyageEmbeddingProvider(
key: 'VOYAGE_API_KEY',
model: 'VOYAGE_MODEL'
);
}
public function vectorStore(): VectorStoreInterface
{
return new PineconeVectorStore(
key: 'PINECONE_API_KEY',
indexUrl: 'PINECONE_INDEX_URL'
);
}
}
use App\Neuron\MyAgent;
use NeuronAI\Chat\Messages\UserMessage;
use NeuronAI\StructuredOutput\SchemaProperty;
/*
* Define the output structure as a PHP class.
*/
class Person
{
#[SchemaProperty(description: 'The user name')]
public string $name;
#[SchemaProperty(description: 'What the user love to eat')]
public string $preference;
}
// Talk to the agent requiring the structured output
$person = MyAgent::make()->structured(
new UserMessage("I'm John and I like pizza!"),
Person::class
);
echo $person->name ' like '.$person->preference;
// John like pizza
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.