Multi-step tool runs against Gemini have so far replayed the entire conversation on every step of the loop — user messages, attachments, prior assistant turns and tool calls included. This change closes that gap. When you opt in with the store provider option, the Gemini gateway now chains each step of a tool run to the previous one via previous_interaction_id and sends only the new tool results. Without that option, nothing changes: requests stay fully stateless and Google retains nothing.
From full replay to chained interactions
Gemini already runs on the Interactions API, so most of the machinery existed — the gateway simply never used it. buildStepBody() ignored the step context entirely, and neither the text parser nor the streaming parser ever set a continuationToken, leaving the loop with nothing to chain to.
Both parsers now record the interaction's id as the continuation token, but only when the request was sent with store: true. The request builder checks for that token and, when present, assembles a follow-up request containing previous_interaction_id plus only the trailing function_result steps. Tools, the system instruction, the response format and the generation config are re-sent on every step, because Gemini scopes them to each interaction instead of carrying them over.
The result matches the pattern the xAI and OpenAI gateways already follow, so all three providers now behave consistently for stored, multi-step tool runs.
Why it matters
Replaying the full history is wasteful: payloads grow with every step, long conversations and attachments get shipped to Google repeatedly, and each step pays for input it does not need. Chained continuations shrink follow-up requests to a single function_result block plus a reference to the stored interaction, which cuts bandwidth and latency on both sides.
Just as important is what did not change. Storage is strictly opt-in. Any request sent without store: true behaves exactly as before, so callers who require that Google retain nothing keep that guarantee by default.
Opting in
Turn on storage through the agent's provider options:
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Contracts\HasProviderOptions;
use Laravel\Ai\Contracts\HasTools;
use Laravel\Ai\Enums\Lab;
use Laravel\Ai\Promptable;
class NumberAgent implements Agent, HasProviderOptions, HasTools
{
use Promptable;
public function instructions(): string
{
return 'Generate a random number when asked.';
}
public function tools(): iterable
{
return [new RandomNumberGenerator];
}
public function maxSteps(): int
{
return 5;
}
public function providerOptions(Lab|string $provider): array
{
return ['store' => true];
}
}
Streaming works the same way: a stored stream reports its interaction id just like a non-streaming response, so a streaming tool loop chains its steps identically. If you kept an interaction id from an earlier run, you can seed the chain by adding previous_interaction_id to the provider options — it applies to the first request only; from the second step on, the loop continues from the interaction it just stored.
What a follow-up request contains
For the agent above, the first request carries the full conversation with store: true. Once the tool runs, the second request is reduced to:
{
"previous_interaction_id": "int_123",
"input": [
{"type": "function_result", "call_id": "call_1", "name": "RandomNumberGenerator"}
],
"system_instruction": "Generate a random number when asked.",
"tools": [{"name": "RandomNumberGenerator"}],
"generation_config": {"thinking_level": "high"}
}
Only the new tool results ride along; everything the model needs to reason about prior turns is referenced by id. The structured output schema and generation config are re-sent and match the first request, so a tool loop that finishes with structured output keeps working.
Guard rails
The change is deliberate about when chaining applies:
- No
store: true, no token: the full history is replayed exactly as before. - A stream that never reports an interaction id also falls back to a full replay.
- The loop drops the continuation token whenever the messages, model or instructions change, so failover to another provider and edited histories still work.
- A caller-supplied
previous_interaction_idis honored on the first request; later steps chain from freshly stored interactions.
Upgrading from v1.4.0
This release is non-breaking. Request bodies without store are unchanged, stored response data keeps its shape, and there is no UPGRADE.md entry — nothing to migrate. The only decision is whether to switch your Gemini tool agents to store: true to benefit from slimmer multi-step requests.
Key takeaways:
- Gemini tool loops can now continue stored interactions via
previous_interaction_idinstead of replaying the whole conversation on every step. - Enable it with the
store: trueprovider option; the default remains fully stateless. - Follow-up requests send only new
function_resultsteps, while tools, system instruction, response format and generation config are re-sent per interaction. - Missing interaction ids, unstored requests, provider failover and edited histories all fall back to the previous full-replay behavior.