class RememberConversation

Methods

__construct(ConversationStore $store, TextProvider $provider)

Create a new middleware instance.

static bool
appliesTo(Agent $agent)

Determine whether the given agent remembers its conversations.

handle(AgentPrompt $prompt, Closure $next)

Handle the incoming prompt.

void
rememberFailedTurn(AgentPrompt $prompt, Throwable $exception, string|null $pendingConversationId, bool $retryable = true)

Record the steps a run completed before it died, so the tools it already ran are not lost with it.

rememberTurn(AgentPrompt $prompt, AgentResponse $response, string|null $pendingConversationId, Throwable|null $exception = null)

Store the complete turn and apply its conversation ID after persistence succeeds.

array
participantKeys(object|null $participant)

Split a participant into the type and key it is stored under.

bool
shouldRemember(Agent $agent, AgentPrompt $prompt, AgentResponse $response)

Determine whether this turn should be persisted.

bool
shouldRememberTurn(Agent $agent, AgentPrompt $prompt)

Determine whether this turn belongs to a conversation, however it ended.

bool
startsConversation(AgentPrompt $prompt)

Determine whether this attempt needs to create a conversation.

startConcurrentTitle(AgentPrompt $prompt)

Start an eligible title request alongside the main generation.

string
generateTitle(AgentPrompt $prompt)

Generate a title for the conversation.

Details

at line 39
__construct(ConversationStore $store, TextProvider $provider)

Create a new middleware instance.

Parameters

ConversationStore $store
TextProvider $provider

at line 48
static bool appliesTo(Agent $agent)

Determine whether the given agent remembers its conversations.

Parameters

Agent $agent

Return Value

bool

at line 57
AgentResponse|StreamableAgentResponse handle(AgentPrompt $prompt, Closure $next)

Handle the incoming prompt.

Parameters

AgentPrompt $prompt
Closure $next

Return Value

AgentResponse|StreamableAgentResponse

at line 168
protected void rememberFailedTurn(AgentPrompt $prompt, Throwable $exception, string|null $pendingConversationId, bool $retryable = true)

Record the steps a run completed before it died, so the tools it already ran are not lost with it.

Parameters

AgentPrompt $prompt
Throwable $exception
string|null $pendingConversationId
bool $retryable

Return Value

void

at line 204
protected StoredTurn rememberTurn(AgentPrompt $prompt, AgentResponse $response, string|null $pendingConversationId, Throwable|null $exception = null)

Store the complete turn and apply its conversation ID after persistence succeeds.

Parameters

AgentPrompt $prompt
AgentResponse $response
string|null $pendingConversationId
Throwable|null $exception

Return Value

StoredTurn

at line 299
protected array participantKeys(object|null $participant)

Split a participant into the type and key it is stored under.

Parameters

object|null $participant

Return Value

array

at line 311
protected bool shouldRemember(Agent $agent, AgentPrompt $prompt, AgentResponse $response)

Determine whether this turn should be persisted.

Parameters

Agent $agent
AgentPrompt $prompt
AgentResponse $response

Return Value

bool

at line 322
protected bool shouldRememberTurn(Agent $agent, AgentPrompt $prompt)

Determine whether this turn belongs to a conversation, however it ended.

Parameters

Agent $agent
AgentPrompt $prompt

Return Value

bool

at line 335
protected bool startsConversation(AgentPrompt $prompt)

Determine whether this attempt needs to create a conversation.

Parameters

AgentPrompt $prompt

Return Value

bool

at line 346
protected PendingConversationTitle|null startConcurrentTitle(AgentPrompt $prompt)

Start an eligible title request alongside the main generation.

Parameters

AgentPrompt $prompt

Return Value

PendingConversationTitle|null

at line 372
protected string generateTitle(AgentPrompt $prompt)

Generate a title for the conversation.

Parameters

AgentPrompt $prompt

Return Value

string