### Query Documentation via HTTP GET Source: https://docs.neuron-ai.dev/overview/fast-learning-by-video Example of an HTTP GET request to query the documentation dynamically. The 'ask' query parameter should contain a specific, self-contained question in natural language. ```http GET https://docs.neuron-ai.dev/overview/fast-learning-by-video.md?ask= ``` -------------------------------- ### Querying Documentation Dynamically Source: https://docs.neuron-ai.dev/resources This example shows how to perform an HTTP GET request to query the documentation dynamically using the `ask` query parameter. ```HTTP GET https://docs.neuron-ai.dev/resources.md?ask= ``` -------------------------------- ### Laravel Travel Agent Project Setup Source: https://docs.neuron-ai.dev/resources/examples Commands to set up the Laravel Travel Agent project, including installing dependencies, building assets, and running migrations. ```bash composer install npm run build php artisan migrate ``` -------------------------------- ### Querying Documentation via HTTP GET Source: https://docs.neuron-ai.dev/agent/middleware This example shows how to perform an HTTP GET request to query the documentation dynamically using the `ask` query parameter. ```http GET https://docs.neuron-ai.dev/agent/middleware.md?ask= ``` -------------------------------- ### Interacting with the Agent Source: https://docs.neuron-ai.dev/agent/tools Example of how to use the agent to get a summary of a YouTube video by providing a message. ```php use NeuronAI\Chat\Messages\UserMessage; $message = YouTubeAgent::make($user)->chat( new UserMessage('What about this video: https://www.youtube.com/watch?v=WmVLcj-XKnM') )->getMessage(); echo $message->getContent(); /** Based on the transcription, I'll provide a summary of this powerful environmental message from "Mother Nature": This video presents ... Three most important takeaways: 1. Nature has existed ... 2. The wellbeing of humanity is ... 3. How humans choose to act toward Nature determines ... */ ``` -------------------------------- ### Querying Documentation via API Source: https://docs.neuron-ai.dev/agent/tools Example of how to query the documentation dynamically using an HTTP GET request. ```http GET https://docs.neuron-ai.dev/agent/tools.md?ask= ``` -------------------------------- ### Install Amp HTTP Client Source: https://docs.neuron-ai.dev/agent/async Install the necessary package to enable Amp's HTTP client for asynchronous requests. ```bash composer require amphp/http-client ``` -------------------------------- ### Install OpenSearch Client Source: https://docs.neuron-ai.dev/rag/vector-store Install the official OpenSearch PHP client using Composer. This is a prerequisite for using OpenSearch as a vector store. ```bash composer require opensearch-project/opensearch-php ``` -------------------------------- ### Querying Documentation Source: https://docs.neuron-ai.dev/agent/messages Example of how to query the documentation dynamically using an HTTP GET request with the 'ask' query parameter. ```http GET https://docs.neuron-ai.dev/agent/messages.md?ask= ``` -------------------------------- ### MySQL & PostgreSQL Toolkit Example Source: https://docs.neuron-ai.dev/agent/tools Example of how to include the MySQLToolkit and PGSQLToolkit in your agent. ```php ``` -------------------------------- ### YouTubeAgent Example Source: https://docs.neuron-ai.dev/agent/tools This example demonstrates how to define a tool for an Agent to retrieve YouTube video transcriptions for summarization. ```php namespace App\Neuron; use NeuronAI\Agent\Agent; use NeuronAI\Agent\SystemPrompt; use NeuronAI\Providers\AIProviderInterface; use NeuronAI\Providers\Anthropic\Anthropic; use NeuronAI\Tools\PropertyType; use NeuronAI\Tools\Tool; use NeuronAI\Tools\ToolProperty; class YouTubeAgent extends Agent { protected function provider(): AIProviderInterface { // return an AI provider instance (Anthropic, OpenAI, Ollama, Gemini, etc.) return new Anthropic( key: 'ANTHROPIC_API_KEY', model: 'ANTHROPIC_MODEL', ); } protected function instructions(): string { return (string) new SystemPrompt( background: ["You are an AI Agent specialized in writing YouTube video summaries."], steps: [ "Get the url of a YouTube video, or ask the user to provide one.", "Use the tools you have available to retrieve the transcription of the video.", "Write the summary.", ], output: [ "Write a summary in a paragraph without using lists. Use just fluent text.", "After the summary add a list of three sentences as the three most important take away from the video.", ] ); } protected function tools(): array { return [ Tool::make( 'get_transcription', 'Retrieve the transcription of a youtube video.' )->addProperty( new ToolProperty( name: 'video_url', type: PropertyType::STRING, description: 'The URL of the YouTube video.', required: true ) )->setCallable(function (string $video_url) { return "Video transcripton..."; }) ]; } } ``` -------------------------------- ### Example Node Using AsyncHttpClient Source: https://docs.neuron-ai.dev/workflow/loops-and-branches This example demonstrates a node that might utilize an AmpHttpClient, often injected when using AsyncExecutor for parallel agentic tasks. ```php use NeuronAI\HttpClient\AmpHttpClient; class DescriptionGenerationNode extends Node { public function __invoke(TextProcessEvent $event, WorkflowState $state): StopEvent { $input = new UserMessage('Describe this image'); $input->addContent( new ImageContent(...) ); $response = AsyncAgent::make() ->chat($input) ->getMessage(); return new StopEvent(result: $response); } } ``` -------------------------------- ### Using the Calculator Toolkit Source: https://docs.neuron-ai.dev/agent/tools Example of how to attach the entire CalculatorToolkit to an agent. ```php ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.neuron-ai.dev/workflow/multi-step-workflow Demonstrates how to dynamically query documentation by appending an 'ask' query parameter to the page URL. ```http GET https://docs.neuron-ai.dev/workflow/multi-step-workflow.md?ask= ``` -------------------------------- ### ArrayProperty Example Source: https://docs.neuron-ai.dev/agent/tools This example shows how to define an ArrayProperty that expects an array of strings. ```php namespace App\Neuron\Tools; use NeuronAI\Tools\PropertyType; use NeuronAI\Tools\Tool; use NeuronAI\Tools\ArrayProperty; use NeuronAI\Tools\ToolProperty; class MyTool extends Tool { public function __construct(){...} protected function properties(): array { return [ new ArrayProperty( name: 'prop_array', description: 'Describe the value you expect', required: true, items: new ToolProperty( name: 'prop', type: PropertyType::STRING, description: 'Describe the value you expect', required: true ) ) ]; } public function __invoke(string $arg){...} } ``` -------------------------------- ### Install Neuron Source: https://docs.neuron-ai.dev Install Neuron in your project using Composer. ```bash composer require neuron-core/neuron-ai ``` -------------------------------- ### Calendar Toolkit Example Source: https://docs.neuron-ai.dev/agent/tools Example of how to include the CalendarToolkit in your agent. ```php ``` -------------------------------- ### Query Documentation with HTTP GET Source: https://docs.neuron-ai.dev/overview Use this method to dynamically query the documentation. Perform an HTTP GET request on the current page URL with the `ask` query parameter. The question should be specific, self-contained, and written in natural language. ```http GET https://docs.neuron-ai.dev/overview.md?ask= ``` -------------------------------- ### OpenAI Provider Example Source: https://docs.neuron-ai.dev Example of how to use the OpenAI AI provider with Neuron. ```php namespace App\Neuron; use NeuronAI\Agent\Agent; use NeuronAI\Chat\Messages\UserMessage; use NeuronAI\Providers\AIProviderInterface; use NeuronAI\Providers\OpenAI\OpenAI; class MyAgent extends Agent { protected function provider(): AIProviderInterface { return new OpenAI( key: 'OPENAI_API_KEY', model: 'OPENAI_MODEL', ); } } $message = MyAgent::make() ->chat(new UserMessage("Hi!")) ->getMessage(); echo $message->getContent(); // Hi, how can I help you today? ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.neuron-ai.dev/rag Perform an HTTP GET request to the current page URL with the 'ask' query parameter to dynamically query the documentation. Use this when information is not explicitly present or for clarification. ```http GET https://docs.neuron-ai.dev/rag.md?ask= ``` -------------------------------- ### Adding a Toolkit to an Agent Source: https://docs.neuron-ai.dev/agent/tools Example demonstrating how to integrate a toolkit, like CalculatorToolkit, into an agent. ```php ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.neuron-ai.dev/overview/upgrade Perform an HTTP GET request to the current page URL with the `ask` query parameter to dynamically query the documentation. The question should be specific and self-contained. ```http GET https://docs.neuron-ai.dev/overview/upgrade.md?ask= ``` -------------------------------- ### Install Elasticsearch Client Source: https://docs.neuron-ai.dev/rag/vector-store Install the official Elasticsearch PHP client using Composer. This is required before using Elasticsearch as a vector store. ```bash composer require elasticsearch/elasticsearch ``` -------------------------------- ### Querying Documentation via HTTP GET Source: https://docs.neuron-ai.dev/agent/async Perform an HTTP GET request to the current page URL with an 'ask' query parameter to dynamically query the documentation. ```http GET https://docs.neuron-ai.dev/agent/async.md?ask= ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.neuron-ai.dev/workflow/persistence Perform an HTTP GET request to the current page URL with the 'ask' query parameter to dynamically query the documentation. Use this when the answer is not explicitly present, requires clarification, or you need related documentation. ```http GET https://docs.neuron-ai.dev/workflow/persistence.md?ask= ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.neuron-ai.dev/workflow/getting-started Perform an HTTP GET request to a page URL with the 'ask' query parameter to dynamically query documentation. Use this for clarifications or retrieving related information not explicitly present. ```http GET https://docs.neuron-ai.dev/workflow/getting-started.md?ask= ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.neuron-ai.dev/agent/chat-history-and-memory Perform an HTTP GET request to the current page URL with the 'ask' query parameter to dynamically query the documentation. The question should be specific and self-contained. ```http GET https://docs.neuron-ai.dev/agent/chat-history-and-memory.md?ask= ``` -------------------------------- ### Install Google Auth for Gemini Vertex AI Source: https://docs.neuron-ai.dev/providers/ai-provider Before using the Gemini Vertex AI provider, install the google/auth composer package. ```bash composer require google/auth ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.neuron-ai.dev/agent/observability Perform an HTTP GET request to the current page URL with the `ask` query parameter to dynamically query documentation. The question should be specific and in natural language. ```http GET https://docs.neuron-ai.dev/agent/observability.md?ask= ``` -------------------------------- ### Query Documentation via API Source: https://docs.neuron-ai.dev/workflow/middleware Perform an HTTP GET request to the documentation URL with the 'ask' query parameter to dynamically query information. ```http GET https://docs.neuron-ai.dev/workflow/middleware.md?ask= ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.neuron-ai.dev/agent Perform an HTTP GET request on a documentation URL with the 'ask' query parameter to dynamically query the documentation. Use this for specific questions, clarifications, or to retrieve related sections when information is not explicitly present on the current page. ```http GET https://docs.neuron-ai.dev/agent.md?ask= ``` -------------------------------- ### Adding a Provider Tool to an Agent Source: https://docs.neuron-ai.dev/agent/tools Example of how to add a provider tool, such as 'web_search', to an agent's configuration. ```php use NeuronAI\Tools\ProviderTool; class MyAgent extends Agent { protected function provider(): AIProviderInterface { return new OpenAIResponses( key: 'OPENAI_API_KEY', model: 'OPENAI_MODEL', ); } protected function tools(): array { return [ ProviderTool::make( type: 'web_search' )->setOptions([...]), ]; } } ``` -------------------------------- ### Query Documentation Dynamically Source: https://docs.neuron-ai.dev/providers Perform an HTTP GET request to query documentation dynamically. Use the 'ask' query parameter with a specific, self-contained question in natural language to get direct answers and relevant excerpts. ```http GET https://docs.neuron-ai.dev/providers.md?ask= ``` -------------------------------- ### Querying Documentation via HTTP GET Source: https://docs.neuron-ai.dev/agent/agent Dynamically query this documentation by performing an HTTP GET request to the current page URL with an 'ask' query parameter. The question should be specific and in natural language. ```http GET https://docs.neuron-ai.dev/agent/agent.md?ask= ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.neuron-ai.dev/rag/retrieval Perform an HTTP GET request to the current page URL, appending the 'ask' query parameter with a natural language question to retrieve specific information from the documentation. ```http GET https://docs.neuron-ai.dev/rag/retrieval.md?ask= ``` -------------------------------- ### Define YouTube Agent with SystemPrompt Source: https://docs.neuron-ai.dev/agent/agent Implement the `instructions()` method to define agent behavior using the `SystemPrompt` class. This method encapsulates background, steps, and output format for the LLM. ```php chat(new UserMessage("Hi, who are you?")) ->getMessage(); echo $response->getContent(); ``` -------------------------------- ### Define YouTube Agent with Simple String Instructions Source: https://docs.neuron-ai.dev/agent/agent Alternatively, provide a simple string to the `instructions()` method for basic agent behavior. This is suitable for straightforward tasks. ```php ``` -------------------------------- ### Query Documentation via HTTP GET Source: https://docs.neuron-ai.dev/agent/streaming To get information not explicitly on the current page, perform an HTTP GET request to the page URL with an 'ask' query parameter containing your question. ```http GET https://docs.neuron-ai.dev/agent/streaming.md?ask= ``` -------------------------------- ### Execute Workflow with Branches Source: https://docs.neuron-ai.dev/workflow/loops-and-branches This example shows how to initialize and run a workflow that utilizes branching logic. The workflow includes nodes for different branches (A1, A2, B1, B2). ```php $state = Workflow::make() ->addNodes([ new InitialNode(), new A1Node(), new A2Node(), new B1Node(), new B2Node(), ]) ->init() ->run(); ``` -------------------------------- ### Implement MyAIProvider Source: https://docs.neuron-ai.dev/providers/ai-provider A basic template for a new AI provider implementation. This example uses Guzzle for HTTP requests and demonstrates the chat method. ```php namespace App\Neuron\Providers; use GuzzleHttp\Client; use GuzzleHttp\RequestOptions; use NeuronAI\Chat\Messages\AssistantMessage; use NeuronAI\Chat\Messages\Message; use NeuronAI\Providers\AIProviderInterface; use NeuronAI\Providers\HandleWithTools; use NeuronAI\Providers\MessageMapperInterface; class MyAIProvider implements AIProviderInterface { use HandleWithTools; /** * The http client. * * @var Client */ protected Client $client; /** * System instructions. * * @var string */ protected string $system; /** * The component responsible for mapping the NeuronAI Message to the AI provider format. * * @var MessageMapperInterface */ protected MessageMapperInterface $messageMapper; public function __construct( protected string $key, protected string $model ) { $this->client = new Client([ 'base_uri' => 'https://api.provider.com/v1', 'headers' => [ 'Content-Type' => 'application/json', 'Authorization' => "Bearer {$this->key}", ] ]); } /** * @inerhitDoc */ public function systemPrompt(string $prompt): AIProviderInterface { $this->system = $prompt; return $this; } public function messageMapper(): MessageMapperInterface { return $this->messageMapper ?? $this->messageMapper = new MessageMapper(); } /** * @inerhitDoc */ public function chat(array $messages): Message { $result = $this->client->post('chat', [ RequestOptions::JSON => [ 'model' => $this->model, 'messages' => \array_map(function (Message $message) { return $message->jsonSerialize(); }, $messages) ] ])->getBody()->getContents(); $result = \json_decode($result, true); return new AssistantMessage($result['content']); } } ``` -------------------------------- ### Query Documentation Source: https://docs.neuron-ai.dev/resources/examples Perform an HTTP GET request to query the documentation dynamically. The 'ask' query parameter should contain a specific, self-contained question in natural language. ```http GET https://docs.neuron-ai.dev/resources/examples.md?ask= ``` -------------------------------- ### Querying Documentation via HTTP GET Source: https://docs.neuron-ai.dev/agent/error-handling To get information not directly on the page, make an HTTP GET request to the current page URL with an `ask` query parameter. The question should be specific and in natural language. ```http GET https://docs.neuron-ai.dev/agent/error-handling.md?ask= ``` -------------------------------- ### Mistral Provider Example Source: https://docs.neuron-ai.dev Example of how to use the Mistral AI provider with Neuron. ```php namespace App\Neuron; use NeuronAI\Agent\Agent; use NeuronAI\Chat\Messages\UserMessage; use NeuronAI\Providers\AIProviderInterface; use NeuronAI\Providers\Gemini\Mistral; class MyAgent extends Agent { protected function provider(): AIProviderInterface { return new Mistral( key: 'MISTRAL_API_KEY', model: 'MISTRAL_MODEL', ); } } $message = MyAgent::make() ->chat(new UserMessage("Hi!")) ->getMessage(); echo $message->getContent(); // Hi, how can I help you today? ``` -------------------------------- ### Gemini Provider Example Source: https://docs.neuron-ai.dev Example of how to use the Gemini AI provider with Neuron. ```php namespace App\Neuron; use NeuronAI\Agent\Agent; use NeuronAI\Chat\Messages\UserMessage; use NeuronAI\Providers\AIProviderInterface; use NeuronAI\Providers\Gemini\Gemini; class MyAgent extends Agent { protected function provider(): AIProviderInterface { return new Gemini( key: 'GEMINI_API_KEY', model: 'GEMINI_MODEL', ); } } $message = MyAgent::make() ->chat(new UserMessage("Hi!")) ->getMessage(); echo $message->getContent(); // Hi, how can I help you today? ``` -------------------------------- ### AgentJudge Assertion Setup Source: https://docs.neuron-ai.dev/agent/evaluation Demonstrates setting up an AI agent as a judge for custom evaluation criteria. Requires configuring the AI provider and defining instructions for the judge. ```php use NeuronAI\Evaluation\Assertions\AgentJudge; class AgentJudgeEvaluator extends BaseEvaluator { protected AgentInterface $judge; public function setUp(): void { $this->judge = Agent::make() ->setAiProvider( new Antrhopic(...) ) ->setInstructions('You are an expert evaluator for customer support responses.'); } public function getDataset(): DatasetInterface { return new JsonDataset(...); } public function run(array $datasetItem): mixed { $response = MyAgent::make()->chat( new UserMessage($datasetItem['input']) )->getMessage(); return $response->getContent(); } public function evaluate(mixed $output, array $datasetItem): void { $this->assert(new AgentJudge( judge: $this->judge, criteria: 'Response should be helpful, polite, and address the customer\'s question directly', threshold: $datasetItem['threshold'] ), $output); } } ``` -------------------------------- ### Configuring a Specific Tool Source: https://docs.neuron-ai.dev/agent/tools Illustrates how to retrieve and configure a specific tool from a toolkit using the `with()` method. ```php class MyAgent extends Agent { ... protected function tools(): array { return [ MySQLToolkit::make() ->with( MySQLSchemaTool::class, fn (ToolInterface $tool) => $tool->setMaxTries(1) ), ]; } } ``` -------------------------------- ### Ollama Provider Example Source: https://docs.neuron-ai.dev Example of how to use the Ollama AI provider with Neuron. ```php namespace App\Neuron; use NeuronAI\Agent\Agent; use NeuronAI\Chat\Messages\UserMessage; use NeuronAI\Providers\AIProviderInterface; use NeuronAI\Providers\Ollama\Ollama; class MyAgent extends Agent { protected function provider(): AIProviderInterface { return new Ollama( url: 'OLLAMA_URL', model: 'OLLAMA_MODEL', ); } } $message = MyAgent::make() ->chat(new UserMessage("Hi!")) ->getMessage(); echo $message->getContent(); // Hi, how can I help you today? ``` -------------------------------- ### Anthropic Provider Example Source: https://docs.neuron-ai.dev Example of how to use the Anthropic AI provider with Neuron. ```php namespace App\Neuron; use NeuronAI\Agent\Agent; use NeuronAI\Chat\Messages\UserMessage; use NeuronAI\Providers\AIProviderInterface; use NeuronAI\Providers\Anthropic\Anthropic; class MyAgent extends Agent { protected function provider(): AIProviderInterface { return new Anthropic( key: 'ANTHROPIC_API_KEY', model: 'ANTHROPIC_MODEL', ); } } $message = MyAgent::make() ->chat(new UserMessage("Hi!")) ->getMessage(); echo $message->getContent(); // Hi, how can I help you today? ``` -------------------------------- ### Querying Documentation via API Source: https://docs.neuron-ai.dev/workflow/single-step-workflow Demonstrates how to query the documentation dynamically by making an HTTP GET request with an 'ask' query parameter. This is useful for retrieving specific information or clarification. ```http GET https://docs.neuron-ai.dev/workflow/single-step-workflow.md?ask= ``` -------------------------------- ### Install spatie/fork package Source: https://docs.neuron-ai.dev/agent/tools Command to install the spatie/fork package required for parallel tool execution. ```shellscript composer require spatie/fork ``` -------------------------------- ### Configure ChromaDB Vector Store Source: https://docs.neuron-ai.dev/rag/vector-store Integrate ChromaDB by specifying the collection name. The host defaults to 'http://localhost:8000'. Configure the 'topK' parameter for search results. ```php namespace App\Neuron; use NeuronAI\RAG\RAG; use NeuronAI\RAG\VectorStore\ChromaVectorStore; use NeuronAI\RAG\VectorStore\VectorStoreInterface; class MyChatBot extends RAG { ... protected function vectorStore(): VectorStoreInterface { return new ChromaVectorStore( collection: 'neuron-ai', //host: 'http://localhost:8000', <-- This is by default topK: 5 ); } } ``` -------------------------------- ### Install Neuron AI with Composer Source: https://docs.neuron-ai.dev/overview/getting-started Use this command to install the latest version of the Neuron AI package via Composer. ```bash composer require neuron-core/neuron-ai ``` -------------------------------- ### Initialize FakeVectorStore with Documents Source: https://docs.neuron-ai.dev/agent/testing Create a `FakeVectorStore` instance and pre-populate it with `Document` objects. This allows you to control the results of `similaritySearch()` in tests. ```php use NeuronAI\RAG\Document; use NeuronAI\Testing\FakeVectorStore; $vectorStore = new FakeVectorStore([ new Document('Paris is the capital of France.'), new Document('Berlin is the capital of Germany.'), ]); ``` -------------------------------- ### Running the Workflow Source: https://docs.neuron-ai.dev/workflow/single-step-workflow Instantiates, initializes, and runs the workflow, then retrieves and prints a value from the final state. This shows how to execute a workflow and access its results. ```php $finalState = MyWorkflow::make()->init()->run(); echo $finalState->get('answer'); // Print Hello World! ``` -------------------------------- ### Query Documentation with 'ask' Parameter Source: https://docs.neuron-ai.dev/agent/evaluation Perform an HTTP GET request to query documentation dynamically. Use the `ask` query parameter with a specific, natural language question. ```http GET https://docs.neuron-ai.dev/agent/evaluation.md?ask= ``` -------------------------------- ### Initialize and Run Workflow with State Source: https://docs.neuron-ai.dev/workflow/managing-the-state Provide an initial `WorkflowState` when creating a workflow and execute it to retrieve the final state. ```php // 1. Provide an initial state as workflow input to feed in some data $workflow = Workflow::make(state: new WorkflowState(['query' => 'Hi!'])) ->addNode(new InitialNode()) ->addNode(...) ->addNode(...); // 2. Execute the workflow and get the final state $finalState = $workflow->init()->run(); // 3. Use the final state data echo $finalState->get('message'); ``` -------------------------------- ### Custom GreaterThanAssertion Implementation Source: https://docs.neuron-ai.dev/agent/evaluation Example of creating a custom assertion by extending AbstractAssertion. This specific example checks if a numeric value is greater than a defined threshold. ```php use NeuronAI\Evaluation\Assertions\AbstractAssertion; use NeuronAI\Evaluation\AssertionResult; class GreaterThanAssertion extends AbstractAssertion { public function __construct( private readonly float $threshold ) {} public function evaluate(mixed $actual): AssertionResult { if (!is_numeric($actual)) { return AssertionResult::fail( 0.0, 'Expected numeric value, got ' . gettype($actual), ); } if ($actual > $this->threshold) { return AssertionResult::pass(1.0); } return AssertionResult::fail( 0.0, "Expected {$actual} to be greater than {$this->threshold}", ); } } ``` -------------------------------- ### Configure AWS Bedrock Runtime Provider Source: https://docs.neuron-ai.dev/providers/ai-provider Initialize the BedrockRuntimeClient with your AWS credentials, region, and version. Then, instantiate the BedrockRuntime provider with the client, model, and inference configuration. ```php namespace App\Neuron; use Aws\BedrockRuntime\BedrockRuntimeClient; use NeuronAI\Agent\Agent; use NeuronAI\Chat\Messages\UserMessage; use NeuronAI\Providers\AIProviderInterface; use NeuronAI\Providers\AWS\BedrockRuntime; class MyAgent extends Agent { protected function provider(): AIProviderInterface { $client = new BedrockRuntimeClient([ 'version' => 'latest', 'region' => 'us-east-1', 'credentials' => [ 'key' => 'AWS_BEDROCK_KEY', 'secret' => 'AWS_BEDROCK_SECRET', ], ]); return new BedrockRuntime( client: $client, model: 'AWS_BEDROCK_MODEL', inferenceConfig: [] ); } } $message = MyAgent::make() ->chat(new UserMessage("Hi!")) ->getMessage(); echo $message->getContent(); // Hi, how can I help you today? ``` -------------------------------- ### Query Documentation with 'ask' Parameter Source: https://docs.neuron-ai.dev/rag/embeddings-provider To get additional information not present on the page, perform an HTTP GET request with the 'ask' query parameter. The question should be specific and in natural language. ```http GET https://docs.neuron-ai.dev/rag/embeddings-provider.md?ask= ``` -------------------------------- ### DatabaseChatHistory Serialization Example Source: https://docs.neuron-ai.dev/agent/chat-history-and-memory An example of a custom chat history implementation using PDO for database interaction. It demonstrates how to use `deserializeMessages` on instantiation and `serializeMessage` when saving new messages. ```php db->select(...); // Deserialize properly initialize the correct message types with the correct data. $this->history = $this->deserializeMessages($messages); } protected function onNewMessage(Message $message): void { // Store the serialized version. $this->db->insert($message->jsonSerialize()); } ... } ``` -------------------------------- ### Configure Database Output Driver Source: https://docs.neuron-ai.dev/agent/evaluation Register a custom `DatabaseOutput` driver in the configuration file. This example shows how to pass PDO and table name as constructor arguments. ```php [ // Output results in the console ConsoleDriver::class => ['verbose' => true], // Save results in a json file //JsonDriver::class => ['path' => 'evaluation-results.json'], // Save results in the database DatabaseOutput::class => [ 'pdo' => new \PDO(...), 'table' => 'evaluations', ] ], ]; ``` -------------------------------- ### Setup Fake AI Provider Source: https://docs.neuron-ai.dev/agent/testing Instantiate `FakeAIProvider` with expected AI responses and inject it into your agent. This replaces actual AI calls with predefined outputs for testing. ```php use NeuronAI\Chat\Messages\Stream\AssistantMessage; use NeuronAI\Testing\FakeAIProvider; $provider = new FakeAIProvider( new AssistantMessage('Hello! How can I help you?') ); $agent = MyAgent::make()->setAiProvider($provider); ``` -------------------------------- ### Configure Grok (X-AI) Provider Source: https://docs.neuron-ai.dev/providers/ai-provider Set up the Grok provider by providing your API key and the desired model name. Optional parameters and `strict_response` can also be configured. ```php namespace App\Neuron; use NeuronAI\Agent\Agent; use NeuronAI\Chat\Messages\UserMessage; use NeuronAI\Providers\AIProviderInterface; use NeuronAI\Providers\XAI\Grok; class MyAgent extends Agent { protected function provider(): AIProviderInterface { return new Grok( key: 'GROK_API_KEY', model: 'grok-4', parameters: [], // Add custom params (temperature, logprobs, etc) strict_response: false, // Strict structured output ); } } $message = MyAgent::make() ->chat(new UserMessage("Hi!")) ->getMessage(); echo $message->getContent(); // Hi, how can I help you today? ``` -------------------------------- ### Configure OpenSearch Vector Store Source: https://docs.neuron-ai.dev/rag/vector-store Instantiate OpenSearchVectorStore by creating an OpenSearch client and specifying the index name. The client is configured with a base URI. ```php namespace App\Neuron; use NeuronAI\RAG\RAG; use NeuronAI\RAG\VectorStore\OpenSearchVectorStore; use NeuronAI\RAG\VectorStore\VectorStoreInterface; use OpenSearch\GuzzleClientFactory; class MyChatBot extends RAG { ... protected function vectorStore(): VectorStoreInterface { $opensearch = new GuzzleClientFactory()->create([ 'base_uri' => 'http://localhost:9200', ]); return new OpenSearchVectorStore( client: $opensearch, index: 'neuron-ai', ); } } ``` -------------------------------- ### Install Neuron AI Skills for Claude Code Source: https://docs.neuron-ai.dev/overview/agentic-development Use this npx command to add the Neuron AI skills to your local environment for use with Claude Code. The skills are installed as a symlink for automatic updates. ```bash npx skills add ./vendor/neuron-core/neuron-ai/skills ``` -------------------------------- ### Perform HTTP GET Request with 'ask' Parameter Source: https://docs.neuron-ai.dev/workflow/loops-and-branches Use this method to query the documentation dynamically. The question should be specific and in natural language. The response includes a direct answer and relevant excerpts. ```http GET https://docs.neuron-ai.dev/workflow/loops-and-branches.md?ask= ``` -------------------------------- ### Execute Workflow with Loop Source: https://docs.neuron-ai.dev/workflow/loops-and-branches This example demonstrates running a workflow that includes a node capable of looping. The output shows repeated execution of NodeOne due to the loop condition. ```php $state = Workflow::make() ->addNodes([ new InitialNode(), new NodeOne(), new NodeTwo() ]) ->init() ->run(); /* - Handling StartEvent - InitialNode complete - Running a loop on NodeOne - Running a loop on NodeOne - NodeOne complete, move forward - NodeTwo complete */ ``` -------------------------------- ### Eloquent ChatMessage Model Example Source: https://docs.neuron-ai.dev/agent/chat-history-and-memory An example Eloquent model for chat messages. It includes fillable fields, cast types for JSON columns, and a relationship to the Conversation model. Ensure your model extends Eloquent's Model and has these properties. ```php class ChatMessage extends Model { protected $fillable = [ 'thread_id', 'role', 'content', 'meta' ]; protected $casts = [ 'content' => 'array', 'meta' => 'array' ]; /** * return BelongsTo */ public function conversation(): BelongsTo { return $this->belongsTo(Conversation::class, 'thread_id'); } } ``` -------------------------------- ### Query Documentation Dynamically Source: https://docs.neuron-ai.dev/rag/pre-post-processor Perform an HTTP GET request to the current page URL with the `ask` query parameter to dynamically query documentation. Use this for clarifications or to retrieve related information. ```http GET https://docs.neuron-ai.dev/rag/pre-post-processor.md?ask= ``` -------------------------------- ### Query Documentation Dynamically Source: https://docs.neuron-ai.dev/agent/testing Perform an HTTP GET request with an 'ask' query parameter to dynamically query the documentation. This is useful for retrieving specific information or clarifications not explicitly present on the page. ```http GET https://docs.neuron-ai.dev/agent/testing.md?ask= ``` -------------------------------- ### Image Content Source: https://docs.neuron-ai.dev/agent/messages Example of adding an image to a user message using a URL. ```php use NeuronAI\Chat\Messages\UserMessage; use NeuronAI\Chat\Messages\ContentBlocks\ImageContent; $message = new UserMessage("Describe this image"); $message->addContent( new ImageContent( source: 'https://placehold.co/600x400/EEE/31343C', sourceType: SourceType::URL, mediaType: 'image/png' ) ); $response = MyAgent::make()->chat($message)->getMessage(); echo $response->getContent(); ```