Agents are the core of LarAgent. They represent an AI model that can be used to interact with users, systems, or any other source of input.
LarAgent\Agent
class. This is the parent class for building your custom AI agent with specific capabilities and behaviors.
make:agent
command is a recommended way of creating agents.App\AiAgents
directory with all the necessary boilerplate code:
$maxCompletionTokens
-> maxCompletionTokens(int $tokens)
, $topP
-> topP(float $topP)
and etc.$maxCompletionTokens
-> max_completion_tokens => 2000
and etc.How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep n as 1 to minimize costs.In case of $n > 1, the agent will return an array of responses.
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.We generally recommend altering
$topP
or $temperature
but not both.
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model’s likelihood to repeat the same line verbatim.
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model’s likelihood to talk about new topics.
for()
method to specify a chat history name and get an immediate response:
prompt
method.respond
method returns:
string
with regular requestarray
of string
if $n
is greater than 1.array
Associative array of defined structured output schema.returnMessage
method or setting $returnMessage
property to true
,
which will enforce respond
method to return MessageInterface instance.
returnMessage
is true and structured output is defined, beforeStructuredOutput
hook will not happen,
because structured output is not processed to array.format
and data
.
Supported formats by OpenAI: “wav”, “mp3”, “ogg”, “flac”, “m4a”, “webm”
message() - Set the message
withImages() - Add images
withAudios() - Add audios
withModel() - Change model
addMessage() - Add custom message
Message::system('Your message here')
Use with caution, as it is added directly to the chat history and keep in mind that history needs to keep certain structure defined by openai.clear() - Clear history
setChatHistory() - Change history
withTool() - Add tool
removeTool() - Remove tool
temperature() - Adjust creativity
getChatSessionId() - Get session ID
getProviderName() - Get provider
getTools() - Get tools
chatHistory() - Get history
currentMessage() - Get current message
lastMessage() - Get last message
getChatKeys() - Get all chat keys
getModalities() - Get modalities
getAudio() - Get audio