Getting Responses
There are multiple ways to interact with your agent and get responses.Using for(): Named Sessions
Use for() to specify a chat session identifier. This enables conversation persistence based on your configured history storage:
Using forUser(): User-Specific Sessions
Pass a Laravel Authenticatable object directly to create user-specific sessions:
Using ask(): Quick One-Off
For simple, stateless interactions where you don’t need conversation history:
ask() uses in-memory history that’s discarded after the response. Perfect for single-turn interactions.Using make(): Instance Without Session
Create an agent instance without a named session:
Chainable Methods
Build complex requests using the fluent API:Setting the Message
Using UserMessage Objects
For more control, create aUserMessage instance with metadata and bypass prompt processing:
Response Types
By default,respond() returns different types based on your configuration:
| Configuration | Return Type |
|---|---|
| Standard request | string |
$n > 1 | array of strings |
| Structured output (array schema) | Associative array |
| Structured output (DataModel) | DataModel instance |
Getting the Raw Message Object
To get the fullAssistantMessage object instead of just the content:
Multimodal Input
Images
Pass image URLs or base64-encoded images for vision-capable models:Audio
Pass base64-encoded audio for audio-capable models:Runtime Mutators
Override agent configuration for specific requests:withModel() — Change model
withModel() — Change model
temperature() — Adjust creativity
temperature() — Adjust creativity
maxCompletionTokens() — Limit response length
maxCompletionTokens() — Limit response length
withTool() — Add tool at runtime
withTool() — Add tool at runtime
removeTool() — Remove tool for this request
removeTool() — Remove tool for this request
addMessage() — Inject message into history
addMessage() — Inject message into history
clear() — Reset conversation history
clear() — Reset conversation history
Accessors
Inspect agent state and retrieve information:getChatSessionId() — Get session identifier
getChatSessionId() — Get session identifier
chatHistory() — Access chat history
chatHistory() — Access chat history
lastMessage() — Get last message
lastMessage() — Get last message
currentMessage() — Get message being processed
currentMessage() — Get message being processed
getTools() — List registered tools
getTools() — List registered tools
getChatKeys() — Get all session keys
getChatKeys() — Get all session keys
getProviderName() — Get provider name
getProviderName() — Get provider name
Structured Output
For predictable, type-safe responses, you can define a response schema. The agent will return data matching your defined structure instead of free-form text.Structured Output
Learn how to define schemas and work with DataModels for type-safe responses.

