Skip to main content

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:
The session ID creates a unique conversation thread. Use meaningful identifiers like user IDs, ticket numbers, or conversation UUIDs.

Using forUser(): User-Specific Sessions

Pass a Laravel Authenticatable object directly to create user-specific sessions:
This automatically uses the user’s identifier to create a unique session, making it easy to maintain per-user conversation history.
Learn more about session management and history storage options in Context & History.

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 a UserMessage instance with metadata and bypass prompt processing:
When using a UserMessage instance, the prompt() method is bypassed. The message is sent directly to the LLM.

Response Types

By default, respond() returns different types based on your configuration:

Getting the Raw Message Object

To get the full AssistantMessage object instead of just the content:
Use returnMessage() when you need access to message metadata or want to inspect the full response object.

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:

Accessors

Inspect agent state and retrieve information:

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.

Next Steps

Streaming

Stream responses in real-time for better UX.

Structured Output

Get type-safe, predictable responses with schemas.