Documentation

Corporation uses Tracable

Manages a Laravel Neuro Corporation's state machine.

A Corporation represents a complete AI project execution environment, responsible for initializing the project, creating the initial, intermediary, and final states, and managing the Turing machine's head.

The class:

  • Initializes a TuringHead with the provided task.
  • Loads or creates a NetworkCorporation record based on configuration.
  • Creates a new project and wipes any previous state or dataset entries.
  • Sets up an initial state using the task, followed by intermediary states and a final state.
  • Maintains a state map and logs history entries.

Table of Contents

Properties

$corporation  : NetworkCorporation
The NetworkCorporation model instance representing the corporation.
$corporationId  : int
The corporation ID (if pre-existing).
$corporationNameSpace  : string|bool
The namespace for the corporation. False if not set.
$debug  : bool
Flag indicating whether debugging output is enabled (posts history to console among other information).
$history  : int
The ID of the initial history entry.
$models  : Collection
A collection of additional model configurations.
$project  : NetworkProject
The active project for this corporation.
$saveHistory  : bool
Flag indicating whether history entries should be saved to the database.
$stateMachine  : NetworkState
The state machine (NetworkState model) for the corporation.
$stateMap  : Collection
A collection representing the state map (ordered states) for the project.
$states  : int
The total number of states in the state machine.
$stuckSetting  : StuckHandler
The stuck handler setting, determining how to handle a stuck state.
$task  : string
The task or prompt assigned to this corporation.
$units  : Collection
A collection of units associated with the corporation.
$head  : TuringHead
The TuringHead instance that acts as the "head" of the state machine.

Methods

__construct()  : mixed
Corporation constructor.
debug()  : void
Outputs debug information if debugging is enabled.
getHeadPosition()  : int
Retrieves the current position of the head.
history()  : void
Saves history entries to the database.
run()  : NetworkProject
Runs the corporation's state machine.
scrubDataSet()  : mixed
Recursively transforms dataset data by replacing non-array/object values with their types.
setHeadPosition()  : void
Sets the head position, ensuring it is within valid bounds.
continue()  : TuringHead
Processes an intermediary transition.
final()  : TuringHead
Processes the final transition.
initial()  : TuringHead
Processes the initial transition.
goTo()  : NetworkState
Moves the head to a target state based on a directive.

Properties

$corporationId

The corporation ID (if pre-existing).

public int $corporationId

$corporationNameSpace

The namespace for the corporation. False if not set.

public string|bool $corporationNameSpace = false

$debug

Flag indicating whether debugging output is enabled (posts history to console among other information).

public bool $debug = false

$history

The ID of the initial history entry.

public int $history

$models

A collection of additional model configurations.

public Collection $models

$saveHistory

Flag indicating whether history entries should be saved to the database.

public bool $saveHistory = true

$stateMap

A collection representing the state map (ordered states) for the project.

public Collection $stateMap

$states

The total number of states in the state machine.

public int $states = 0

$stuckSetting

The stuck handler setting, determining how to handle a stuck state.

public StuckHandler $stuckSetting = \LaravelNeuro\Enums\StuckHandler::REPEAT

$task

The task or prompt assigned to this corporation.

public string $task

$units

A collection of units associated with the corporation.

public Collection $units

Methods

__construct()

Corporation constructor.

public __construct(string $task[, bool $debug = false ][, bool $integrityCheck = false ][, array<string|int, mixed> $new = ["name" => "DummyCorp", "description" => "DummyDesc"] ][, bool $saveHistory = true ]) : mixed

Initializes the corporation with a given task, debug flag, and optional integrity check. Sets up the TuringHead with the task, loads or creates a NetworkCorporation record, initializes a new project, cleans any pre-existing state or dataset entries, creates initial, intermediary, and final states, and logs the initiation in history.

Parameters
$task : string

The task to be processed by the corporation.

$debug : bool = false

Whether debugging output should be enabled.

$integrityCheck : bool = false

If true, performs only an integrity check and returns immediately.

$new : array<string|int, mixed> = ["name" => "DummyCorp", "description" => "DummyDesc"]

Default values for creating a new corporation (name and description).

$saveHistory : bool = true

Whether history entries should be saved to the database. Defaults to true.

debug()

Outputs debug information if debugging is enabled.

public debug(string $info) : void
Parameters
$info : string

The debug message.

getHeadPosition()

Retrieves the current position of the head.

public getHeadPosition() : int
Return values
int —

The current head position.

run()

Runs the corporation's state machine.

public run() : NetworkProject

Enters an iterative loop to process state transitions until a termination condition is met. At each iteration, it:

  • Retrieves the current active state.
  • Processes the state based on its type (INITIAL, INTERMEDIARY, FINAL).
  • Applies transition logic based on the head's mode (CONTINUE, STUCK, COMPLETE).
  • Logs new history entries.
  • Updates the corporation data.

Once the state machine terminates, it records the final output as the project's resolution.

Return values
NetworkProject —

The NetworkProject instance of the completed project.

scrubDataSet()

Recursively transforms dataset data by replacing non-array/object values with their types.

public scrubDataSet(mixed $data) : mixed
Parameters
$data : mixed

The dataset data to scrub.

Return values
mixed —

The scrubbed dataset.

setHeadPosition()

Sets the head position, ensuring it is within valid bounds.

public setHeadPosition(int $headPosition) : void
Parameters
$headPosition : int

The desired head position.

continue()

Processes an intermediary transition.

protected continue(TuringHead $head) : TuringHead

Creates a new Transition instance and returns the updated head after processing.

Parameters
$head : TuringHead

The current TuringHead instance.

Return values
TuringHead —

The updated head.

final()

Processes the final transition.

protected final(TuringHead $head) : TuringHead

Creates a new Transition instance, processes the final transition, and returns the updated head.

Parameters
$head : TuringHead

The current TuringHead instance.

Return values
TuringHead —

The updated head.

initial()

Processes the initial transition.

protected initial(TuringHead $head) : TuringHead

Records the initial prompt in history and creates the first transition.

Parameters
$head : TuringHead

The current TuringHead instance.

Return values
TuringHead —

The updated head after processing the initial transition.

goTo()

Moves the head to a target state based on a directive.

private goTo(mixed $line, NetworkState $active) : NetworkState

Handles different move directives:

  • TuringMove::NEXT: Move to the next state (unless at FINAL).
  • TuringMove::OUTPUT: Move to the FINAL state.
  • TuringMove::REPEAT: Remain on the current state, updating its data.
  • Otherwise, move to a specific state ID.

Updates the state map and head position accordingly.

Parameters
$line : mixed

The move directive or state ID.

$active : NetworkState

The current active state.

Tags
throws
Exception

if attempting to move past the FINAL state.

Return values
NetworkState —

The new active state.


        
On this page

Search results