Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
91255d0
Run broadcast agent catch callbacks when the error broadcast throws
binaryfire Nov 20, 2026
a3a7941
Let provider options override OpenAI image moderation
binaryfire Nov 20, 2026
45ad4fb
Port sub-agent failures, stored Gemini continuations, title agent and…
binaryfire Nov 20, 2026
6d566e5
Keep rows with a null column in PostgreSQL multi-column full-text search
binaryfire Nov 20, 2026
b099967
Add native PostgreSQL full-text search to the Scout database engine
binaryfire Nov 20, 2026
99d9a49
Read the first-party schema macros in PHPStan's migration reader
binaryfire Nov 20, 2026
6651444
Quote Typesense filter values that contain special characters
binaryfire Nov 20, 2026
0c410a6
Add the SearchableAs attribute for configuring a model's index name
binaryfire Nov 20, 2026
b9e27aa
Collapse multi-line Wayfinder arguments that contain parentheses
binaryfire Nov 20, 2026
decd604
Test QUERY on Wayfinder redirect routes registered for every verb
binaryfire Nov 20, 2026
823973f
Reconcile head with upstream event, Open Graph and container changes
binaryfire Nov 20, 2026
4105829
Clarify Mailtrap Email Sandbox and Markdown escaping in mail docs
binaryfire Nov 20, 2026
6231028
Document Eloquent after query callbacks
binaryfire Nov 20, 2026
ef2a0fa
Document sequence ordering with inOrderOf()
binaryfire Nov 20, 2026
de7a8ea
Note that Fortify throttles its login route automatically
binaryfire Nov 20, 2026
eb9835c
Correct what a streamed parent response includes from its sub-agents
binaryfire Nov 20, 2026
4255d69
Link MCP security practices and document structured content assertions
binaryfire Nov 20, 2026
c7cfc1a
Point deployment requirements at the installation requirements
binaryfire Nov 20, 2026
f55693d
Document HtmlString for unescaped Blade output
binaryfire Nov 20, 2026
1818302
Document insertBefore and insertAfter middleware methods
binaryfire Nov 20, 2026
26516b4
Fix bearerToken() return value wording
binaryfire Nov 20, 2026
ee742b3
Fail tool calls when a sub-agent's validation fails
binaryfire Nov 20, 2026
999a261
Keep the Anthropic code execution container across steps
binaryfire Nov 20, 2026
88cf484
Move CREATE foreign keys after their targets instead
binaryfire Nov 20, 2026
7403637
Fix Scout searchable index names on prefixed and long tables
binaryfire Nov 20, 2026
a974167
Encode ampersands and quotes in secured Markdown mail
binaryfire Nov 20, 2026
f1dc133
Send quoted Typesense equality filters as one-member lists
binaryfire Nov 20, 2026
27d709d
Correct MCP, middleware and request docs wording
binaryfire Nov 20, 2026
00a637a
Assert the Wayfinder redirect route registers query
binaryfire Nov 20, 2026
2c6b923
Run Scout's Typesense tests against Typesense 30.1
binaryfire Nov 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/scout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:

services:
typesense:
image: typesense/typesense:27.1
image: typesense/typesense:30.1
env:
TYPESENSE_API_KEY: secret
TYPESENSE_DATA_DIR: /tmp
Expand Down
26 changes: 26 additions & 0 deletions src/ai/src/Agents/ConversationTitleAgent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Hypervel\Ai\Agents;

use Hypervel\Ai\Attributes\UseCheapestModel;
use Hypervel\Ai\Contracts\Agent;
use Hypervel\Ai\Promptable;

/**
* @phpstan-consistent-constructor
*/
#[UseCheapestModel]
class ConversationTitleAgent implements Agent
{
use Promptable;

/**
* Get the instructions that the agent should follow.
*/
public function instructions(): string
{
return 'Generate a concise 3-5 word title for a conversation that starts with the following message. Use the same language as the message. Respond with only the title, no quotes or punctuation.';
}
}
12 changes: 12 additions & 0 deletions src/ai/src/Contracts/Gateway/ReplaysFullHistory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Hypervel\Ai\Contracts\Gateway;

/**
* A step text gateway that sends the full history on every step. Its continuation token identifies a provider resource, such as a code execution container, rather than stored history, so the tool loop keeps it when middleware changes a step's history, model or instructions.
*/
interface ReplaysFullHistory
{
}
17 changes: 14 additions & 3 deletions src/ai/src/Gateway/Anthropic/AnthropicGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Generator;
use Hypervel\Ai\Contracts\Files\TranscribableAudio;
use Hypervel\Ai\Contracts\Gateway\Gateway;
use Hypervel\Ai\Contracts\Gateway\ReplaysFullHistory;
use Hypervel\Ai\Contracts\Gateway\StepTextGateway;
use Hypervel\Ai\Contracts\Providers\AudioProvider;
use Hypervel\Ai\Contracts\Providers\EmbeddingProvider;
Expand Down Expand Up @@ -34,7 +35,7 @@
use Hypervel\Support\Attributes\Unsupported;
use LogicException;

class AnthropicGateway implements Gateway, StepTextGateway
class AnthropicGateway implements Gateway, ReplaysFullHistory, StepTextGateway
{
use BuildsTextRequests;
use CreatesAnthropicClient;
Expand Down Expand Up @@ -78,6 +79,8 @@ public function generateTextStep(
$options,
);

$body = $this->withContainer($body, $stepContext);

$response = $this->withErrorHandling(
$provider->name(),
fn () => $this->client($provider, $timeout)->post('messages', $body),
Expand All @@ -87,7 +90,10 @@ public function generateTextStep(

$this->validateTextResponse($data);

return $this->parseTextResponse($data, $provider, filled($schema))->withRawResponse($response);
return $this->withRequestContainer(
$this->parseTextResponse($data, $provider, filled($schema))->withRawResponse($response),
$body,
);
}

/**
Expand Down Expand Up @@ -116,6 +122,8 @@ public function generateStreamStep(
$options,
);

$body = $this->withContainer($body, $stepContext);

$body['stream'] = true;

$response = $this->withErrorHandling(
Expand All @@ -125,13 +133,16 @@ public function generateStreamStep(
->post('messages', $body),
);

return yield from $this->processTextStream(
$step = yield from $this->processTextStream(
$invocationId,
$provider,
$model,
$response->getBody(),
$this->pausedContent($messages),
);

// A stream that ends without completing its message has no step.
return $step === null ? null : $this->withRequestContainer($step, $body);
}

/**
Expand Down
35 changes: 35 additions & 0 deletions src/ai/src/Gateway/Anthropic/Concerns/BuildsTextRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Hypervel\Ai\Attributes\CacheInstructions;
use Hypervel\Ai\Attributes\CacheToolDefinitions;
use Hypervel\Ai\Gateway\Anthropic\AnthropicSchemaSanitizer;
use Hypervel\Ai\Gateway\StepContext;
use Hypervel\Ai\Gateway\StepResponse;
use Hypervel\Ai\Gateway\TextGenerationOptions;
use Hypervel\Ai\ObjectSchema;
use Hypervel\Ai\Providers\Provider;
Expand Down Expand Up @@ -81,6 +83,39 @@ protected function buildTextRequestBody(
return $this->applyPromptCacheBreakpoints(array_merge($body, $providerOptions), $options);
}

/**
* Run the step in the code execution container the previous step used.
*/
protected function withContainer(array $body, StepContext $stepContext): array
{
if (blank($stepContext->continuationToken)) {
return $body;
}

if (is_array($body['container'] ?? null)) {
$body['container']['id'] ??= $stepContext->continuationToken;
} else {
$body['container'] ??= $stepContext->continuationToken;
}

return $body;
}

/**
* Keep the container the request ran in when the response doesn't name one.
*
* Anthropic only returns the container when the step runs code, so a step that only calls local tools would
* otherwise drop it, and the next code step would start in a new container without the earlier files.
*/
protected function withRequestContainer(StepResponse $step, array $body): StepResponse
{
$container = $body['container'] ?? null;

$step->continuationToken ??= is_array($container) ? ($container['id'] ?? null) : $container;

return $step;
}

/**
* Stamp the requested cache breakpoints onto the final request body.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ protected function processTextStream(
$messageUsage = [];
$usage = null;
$stopReason = '';
$container = null;
$citedUrls = [];

$emitTextStart = function () use (&$textStartEmitted, $messageId, $invocationId): ?StreamEvent {
Expand Down Expand Up @@ -372,6 +373,7 @@ protected function processTextStream(

if ($type === 'message_delta') {
$stopReason = $data['delta']['stop_reason'] ?? '';
$container = $data['delta']['container']['id'] ?? $container;

// Usage on message_delta is cumulative for the whole message...
$usage = $this->extractUsage(['usage' => array_merge($messageUsage, $data['usage'] ?? [])]);
Expand Down Expand Up @@ -407,6 +409,7 @@ protected function processTextStream(
usage: $usage ?? new TextUsage(0, 0),
finishReason: $this->extractFinishReason(['stop_reason' => $stopReason]),
structured: false,
container: $container,
);
}

Expand Down
3 changes: 3 additions & 0 deletions src/ai/src/Gateway/Anthropic/Concerns/ParsesTextResponses.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected function parseTextResponse(
$this->extractUsage($data),
$this->extractFinishReason($data),
$structured,
$data['container']['id'] ?? null,
);
}

Expand All @@ -66,6 +67,7 @@ protected function buildStepResponse(
TextUsage $usage,
FinishReason $finishReason,
bool $structured,
?string $container = null,
): StepResponse {
$text = $this->extractText($content);
$toolCalls = $this->extractToolCalls($content);
Expand Down Expand Up @@ -101,6 +103,7 @@ protected function buildStepResponse(
usage: $usage,
meta: new Meta($provider->name(), $model, $citations),
structured: $structuredData,
continuationToken: $container,
// The synthetic output has no tool result, so replaying its call would leave an unmatched tool-use ID.
replayBlocks: array_values(array_filter($content, fn (array $block): bool => ($block['type'] ?? '') !== 'tool_use' || ($block['name'] ?? '') !== 'output_structured_data')),
reasoning: $this->extractReasoning($content),
Expand Down
2 changes: 1 addition & 1 deletion src/ai/src/Gateway/AzureOpenAi/AzureOpenAiGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function generateImage(
...$providerOptions,
'model' => $model,
'prompt' => $prompt,
'moderation' => 'low',
'moderation' => $providerOptions['moderation'] ?? 'low',
...$provider->defaultImageOptions($size, $quality),
]),
);
Expand Down
22 changes: 13 additions & 9 deletions src/ai/src/Gateway/Concerns/InvokesTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Hypervel\Ai\Gateway\ParentInvocation;
use Hypervel\Ai\Gateway\RunContext;
use Hypervel\Ai\Providers\Tools\ToolSearch;
use Hypervel\Ai\Tools\AgentTool;
use Hypervel\Ai\Tools\Request;
use Hypervel\Ai\Tools\ToolNameResolver;
use Hypervel\Coroutine\Coroutine;
Expand Down Expand Up @@ -38,16 +39,19 @@ protected function executeTool(Tool $tool, array $arguments, ?string $toolCallId
// Only the handler itself may fail the tool call, so a listener that throws is never reported as a tool failure...
try {
$result = $tool->handle(new Request($arguments, $toolCallId, $toolInvocationId));
} catch (ValidationException $exception) {
// Validation failures are returned to the model so it can correct the arguments and retry...
$result = implode(' ', $exception->validator->errors()->all()) ?: $exception->getMessage();
} catch (Throwable $exception) {
// Keep the original exception, including cancellation, as previous if failure reporting throws.
try {
// Unlike upstream, cancellation is not wrapped, so the caller never recovers it as the tool's own failure.
throw Coroutine::causedByCancellation($exception) ? $exception : new ToolExecutionException($exception);
} finally {
$context?->toolFailed($tool, $arguments, $exception, $toolInvocationId, $this->elapsedMilliseconds($startedAt));
// Validation failures are returned to the model so it can correct the arguments and retry. Unlike upstream, a
// sub-agent's validation failure comes from its own run, so it fails the tool call, as the streamed path does...
if ($exception instanceof ValidationException && ! $tool instanceof AgentTool) {
$result = implode(' ', $exception->validator->errors()->all()) ?: $exception->getMessage();
} else {
// Keep the original exception, including cancellation, as previous if failure reporting throws.
try {
// Unlike upstream, cancellation is not wrapped, so the caller never recovers it as the tool's own failure.
throw Coroutine::causedByCancellation($exception) ? $exception : new ToolExecutionException($exception);
} finally {
$context?->toolFailed($tool, $arguments, $exception, $toolInvocationId, $this->elapsedMilliseconds($startedAt));
}
}
}

Expand Down
30 changes: 29 additions & 1 deletion src/ai/src/Gateway/Gemini/Concerns/BuildsTextRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Hypervel\Ai\Gateway\StepContext;
use Hypervel\Ai\Gateway\TextGenerationOptions;
use Hypervel\Ai\Messages\ToolResultMessage;
use Hypervel\Ai\ObjectSchema;
use Hypervel\Ai\Providers\Provider;
use Hypervel\Ai\Responses\Data\ToolResult;
Expand Down Expand Up @@ -39,7 +40,34 @@ protected function buildStepBody(
?TextGenerationOptions $options,
StepContext $stepContext,
): array {
return $this->buildTextRequestBody($provider, $model, $instructions, $messages, $tools, $schema, $options);
if (! $previousInteractionId = $stepContext->continuationToken) {
return $this->buildTextRequestBody($provider, $model, $instructions, $messages, $tools, $schema, $options);
}

return [
...$this->assembleRequestBody($model, $this->extractToolResultsInput($messages), $instructions, $tools, $schema, $options, $provider),
'previous_interaction_id' => $previousInteractionId,
];
}

/**
* Extract function result steps from the trailing tool result message for a continuation request.
*/
protected function extractToolResultsInput(array $messages): array
{
$lastMessage = end($messages);

return $lastMessage instanceof ToolResultMessage
? $this->buildFunctionResultSteps($lastMessage->toolResults->all())
: [];
}

/**
* Determine if Gemini will retain the interaction described by the given request body.
*/
protected function storesInteraction(array $body): bool
{
return $body['store'] === true;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/ai/src/Gateway/Gemini/Concerns/HandlesTextStreaming.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected function processTextStream(
Provider $provider,
string $model,
StreamInterface $streamBody,
bool $stored,
): Generator {
$messageId = $this->generateEventId();
$reasoningId = '';
Expand Down Expand Up @@ -250,6 +251,7 @@ protected function processTextStream(
finishReason: $this->extractFinishReason($final, $functionCallSteps),
usage: $this->extractUsage($final),
meta: new Meta($provider->name(), $model),
continuationToken: $this->continuationToken($final, $stored),
replayBlocks: $this->replayableSteps($steps),
reasoning: $this->extractReasoning($steps),
providerToolCalls: $this->extractProviderToolCalls($steps),
Expand Down
10 changes: 10 additions & 0 deletions src/ai/src/Gateway/Gemini/Concerns/ParsesTextResponses.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ protected function parseTextResponse(
Provider $provider,
string $model,
bool $structured,
bool $stored,
): StepResponse {
$steps = $data['steps'] ?? [];

Expand All @@ -77,12 +78,21 @@ protected function parseTextResponse(
usage: $this->extractUsage($data),
meta: new Meta($provider->name(), $model, $this->extractCitations($steps)),
structured: $structured ? $this->decodeStructuredOutput($text) : null,
continuationToken: $this->continuationToken($data, $stored),
replayBlocks: $this->replayableSteps($steps),
reasoning: $this->extractReasoning($steps),
providerToolCalls: $this->extractProviderToolCalls($steps),
);
}

/**
* Get the interaction id the next step may continue from, which only a stored interaction offers.
*/
protected function continuationToken(array $data, bool $stored): ?string
{
return $stored ? ($data['id'] ?? null) : null;
}

/**
* Get the steps that must be replayed verbatim on the next request.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/ai/src/Gateway/Gemini/GeminiGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function generateTextStep(

$this->validateTextResponse($data);

return $this->parseTextResponse($data, $provider, $model, filled($schema))->withRawResponse($response);
return $this->parseTextResponse($data, $provider, $model, filled($schema), $this->storesInteraction($body))->withRawResponse($response);
}

/**
Expand Down Expand Up @@ -109,7 +109,7 @@ public function generateStreamStep(
->post('interactions?alt=sse', array_merge($body, ['stream' => true])),
);

return yield from $this->processTextStream($invocationId, $provider, $model, $response->getBody());
return yield from $this->processTextStream($invocationId, $provider, $model, $response->getBody(), $this->storesInteraction($body));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/ai/src/Gateway/OpenAi/OpenAiGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected function sendImageGenerationRequest(
'prompt' => $prompt,
...$provider->defaultImageOptions($size, $quality),
...(str_starts_with($model, 'gpt-image')
? ['moderation' => 'low']
? ['moderation' => $providerOptions['moderation'] ?? 'low']
: ['response_format' => 'b64_json']),
]);
}
Expand Down Expand Up @@ -165,7 +165,7 @@ protected function sendImageEditRequest(
'prompt' => $prompt,
...$provider->defaultImageOptions($size, $quality),
...($isGptImage
? ['moderation' => 'low']
? ['moderation' => $providerOptions['moderation'] ?? 'low']
: ['response_format' => 'b64_json']),
]));
}
Expand Down
2 changes: 1 addition & 1 deletion src/ai/src/Gateway/ParentInvocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function current(): array
/**
* Run the given callback with the given invocation and tool invocation as the delegating parent.
*/
public static function within(?string $invocationId, string $toolInvocationId, Closure $callback): mixed
public static function within(?string $invocationId, ?string $toolInvocationId, Closure $callback): mixed
{
$previous = CoroutineContext::get(static::PARENT_INVOCATION_CONTEXT_KEY);

Expand Down
Loading