Documentation

Transition uses Tracable

Represents a single transition step within a LaravelNeuro Corporation's state machine.

A Transition encapsulates the logic for processing input from a TuringHead (the state machine tape), invoking the appropriate agent, and handling prompt pre-/post-processing as well as output validation. It ties together the current project, corporation, unit, agent, and models, and records history of execution.

Table of Contents

Properties

$debug  : bool
Flag indicating whether debugging output is enabled (posts history to console among other information).
$saveHistory  : bool
Flag indicating whether history entries should be saved to the database.
$agent  : stdClass
The agent handling this transition, stored as a stdClass object containing agent details.
$corporation  : NetworkCorporation
The corporation to which the project belongs.
$head  : TuringHead
The TuringHead representing the state machine's tape (including the current head).
$models  : Collection
A collection of additional model configurations used during the transition.
$project  : NetworkProject
The current project associated with this transition.
$state  : NetworkState
The active state from the network state machine.
$unit  : NetworkUnit
The unit associated with this transition.

Methods

__construct()  : mixed
Transition constructor.
applyData()  : string
Applies dynamic data to a mutable string.
callAgent()  : void
Calls the agent to process the current transition.
debug()  : void
Outputs debug information if debugging is enabled.
handle()  : TuringHead
Handles the transition process.
history()  : void
Saves history entries to the database.
setAgentById()  : self
Sets the agent for the transition based on the agent ID.
setAgentByName()  : self
Sets the agent for the transition based on the agent name.
setUnitById()  : self
Sets the unit for the transition based on the given unit ID.
setUnitByName()  : self
Sets the unit for the transition based on the unit name.
modifyPipeline()  : Pipeline
Allows for modifications to the pipeline before it is executed.
postProcessOutput()  : string
Postprocesses the output data from the head.
postProcessPrompt()  : mixed
Postprocesses the prompt after initial processing.
preProcessInput()  : string
Preprocesses input data from the head.
preProcessPrompt()  : mixed
Preprocesses the prompt before it is used in the transition.

Properties

$debug

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

public bool $debug = false

$saveHistory

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

public bool $saveHistory = true

$agent

The agent handling this transition, stored as a stdClass object containing agent details.

protected stdClass $agent

$head

The TuringHead representing the state machine's tape (including the current head).

protected TuringHead $head

$models

A collection of additional model configurations used during the transition.

protected Collection $models

Methods

__construct()

Transition constructor.

public __construct(int $projectId, TuringHead $head, Collection $models[, bool $debug = false ][, bool $saveHistory = true ]) : mixed

Initializes the Transition instance using a project ID, the TuringHead (state machine tape), and a collection of models. Loads the associated project and corporation, and verifies that there is an active state.

Parameters
$projectId : int

The ID of the project.

$head : TuringHead

The TuringHead instance representing the state tape.

$models : Collection

A collection of model configurations.

$debug : bool = false
$saveHistory : bool = true
Tags
throws
Exception

if the project does not exist or if no active state is found.

applyData()

Applies dynamic data to a mutable string.

public applyData(string $mutable) : string

This method searches for placeholders in the mutable string (using a {{type:...}} format) and replaces them with corresponding data extracted from the corporation, project, or head. Supported types include "FromDataSet", "Corporation", and "Head".

Parameters
$mutable : string

The string containing placeholders.

Return values
string

The string with placeholders replaced by actual data.

callAgent()

Calls the agent to process the current transition.

public callAgent() : void

Preprocesses input data from the head and prompt data from the agent, applies dynamic data replacement, decodes the prompt using the agent's prompt class, records prompt history, and then invokes the agent's pipeline to get a response. Also handles output validation and updates the TuringHead's data and mode accordingly.

Tags
throws
Exception

if errors occur during preprocessing, postprocessing, or agent execution.

debug()

Outputs debug information if debugging is enabled.

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

The debug message.

handle()

Handles the transition process.

public handle() : TuringHead

Determines the appropriate agent (if not already set), applies the transition by invoking callAgent(), post-processes the output from the TuringHead, updates the head's data, and returns the updated head.

Tags
throws
Exception

if no valid agent is found or if errors occur during processing.

Return values
TuringHead

The updated TuringHead after processing the transition.

setAgentById()

Sets the agent for the transition based on the agent ID.

public setAgentById(int $id) : self

Searches across all units in the corporation for an agent with the specified ID, and initializes that agent.

Parameters
$id : int

The agent ID.

Tags
throws
Exception

If the agent is not found.

Return values
self

Returns the current Transition instance.

setAgentByName()

Sets the agent for the transition based on the agent name.

public setAgentByName(string $name) : self

Searches across all units in the corporation for an agent with the specified name, and initializes that agent.

Parameters
$name : string

The agent's name.

Tags
throws
Exception

If the agent is not found.

Return values
self

Returns the current Transition instance.

setUnitById()

Sets the unit for the transition based on the given unit ID.

public setUnitById(int $id) : self

Retrieves the corporation's units and finds the one with the specified ID. Also initializes the default agent for that unit if not already set.

Parameters
$id : int

The unit ID.

Tags
throws
Exception

If the unit is not found.

Return values
self

Returns the current Transition instance.

setUnitByName()

Sets the unit for the transition based on the unit name.

public setUnitByName(string $name) : self

Searches for a unit with the specified name in the corporation.

Parameters
$name : string

The unit name.

Tags
throws
Exception

If the unit is not found.

Return values
self

Returns the current Transition instance.

modifyPipeline()

Allows for modifications to the pipeline before it is executed.

protected modifyPipeline(Pipeline $pipeline) : Pipeline

This method can be overridden to apply custom changes to the pipeline instance.

Parameters
$pipeline : Pipeline

The pipeline to modify.

Return values
Pipeline

The modified pipeline.

postProcessOutput()

Postprocesses the output data from the head.

protected postProcessOutput(string $data) : string

This method can be overridden to modify the output data after the agent's execution.

Parameters
$data : string

The raw output data.

Return values
string

The postprocessed output data.

postProcessPrompt()

Postprocesses the prompt after initial processing.

protected postProcessPrompt(mixed $prompt) : mixed

This method can be overridden to apply custom transformations to the prompt after processing.

Parameters
$prompt : mixed

The prompt data.

Return values
mixed

The postprocessed prompt.

preProcessInput()

Preprocesses input data from the head.

protected preProcessInput(string $data) : string

This method can be overridden to modify the head's data before processing.

Parameters
$data : string

The raw input data.

Return values
string

The preprocessed input data.

preProcessPrompt()

Preprocesses the prompt before it is used in the transition.

protected preProcessPrompt(mixed $prompt) : mixed

This method can be overridden to apply custom transformations to the prompt.

Parameters
$prompt : mixed

The prompt data.

Return values
mixed

The preprocessed prompt.


        
On this page

Search results