1111use Cortex \Prompts \Prompt ;
1212use Illuminate \Support \Str ;
1313use Cortex \Contracts \ToolKit ;
14+ use Cortex \JsonSchema \Schema ;
1415use Cortex \Memory \ChatMemory ;
1516use UnexpectedValueException ;
1617use Cortex \Contracts \Pipeable ;
1920use Cortex \LLM \Contracts \Message ;
2021use Cortex \Memory \Contracts \Store ;
2122use Cortex \Support \Traits \CanPipe ;
22- use Cortex \JsonSchema \ SchemaFactory ;
23+ use Cortex \Pipeline \ RuntimeContext ;
2324use Cortex \Agents \Stages \AppendUsage ;
2425use Cortex \LLM \Data \ChatStreamResult ;
2526use Cortex \Exceptions \GenericException ;
26- use Cortex \JsonSchema \Contracts \Schema ;
2727use Cortex \Memory \Stores \InMemoryStore ;
2828use Cortex \Agents \Stages \HandleToolCalls ;
2929use Cortex \JsonSchema \Types \ObjectSchema ;
3030use Cortex \LLM \Enums \StructuredOutputMode ;
31+ use Cortex \JsonSchema \Contracts \JsonSchema ;
3132use Cortex \LLM \Data \Messages \SystemMessage ;
3233use Illuminate \Contracts \Support \Arrayable ;
3334use Cortex \Agents \Stages \AddMessageToMemory ;
@@ -59,7 +60,7 @@ class Agent implements Pipeable
5960 /**
6061 * @param class-string|\Cortex\JsonSchema\Types\ObjectSchema $output
6162 * @param array<int, \Cortex\LLM\Contracts\Tool|\Closure|string>|\Cortex\Contracts\ToolKit $tools
62- * @param class-string|class-string<\BackedEnum>|\Cortex\JsonSchema\Types\ObjectSchema|array<array-key, \Cortex\JsonSchema\Contracts\Schema >|null $output
63+ * @param class-string|class-string<\BackedEnum>|\Cortex\JsonSchema\Types\ObjectSchema|array<array-key, \Cortex\JsonSchema\Contracts\JsonSchema >|null $llm
6364 * @param array<string, mixed> $initialPromptVariables
6465 */
6566 public function __construct (
@@ -176,7 +177,7 @@ public function stream(array $messages = [], array $input = []): ChatStreamResul
176177 return $ result ;
177178 }
178179
179- public function handlePipeable (mixed $ payload , Closure $ next ): mixed
180+ public function handlePipeable (mixed $ payload , RuntimeContext $ context , Closure $ next ): mixed
180181 {
181182 $ messages = match (true ) {
182183 $ payload instanceof MessageCollection => $ payload ->all (),
@@ -192,7 +193,7 @@ public function handlePipeable(mixed $payload, Closure $next): mixed
192193 default => [],
193194 };
194195
195- return $ next ($ this ->invoke ($ messages , $ input ));
196+ return $ next ($ this ->invoke ($ messages , $ input ), $ context );
196197 }
197198
198199 public function getName (): string
@@ -319,20 +320,20 @@ protected static function buildLLM(
319320 /**
320321 * Build the output schema for the agent.
321322 *
322- * @param class-string|class-string<\BackedEnum>|\Cortex\JsonSchema\Types\ObjectSchema|array<array-key, \Cortex\JsonSchema\Contracts\Schema >|null $output
323+ * @param class-string|class-string<\BackedEnum>|\Cortex\JsonSchema\Types\ObjectSchema|array<array-key, \Cortex\JsonSchema\Contracts\JsonSchema >|null $output
323324 *
324325 * @throws \Cortex\Exceptions\GenericException
325326 */
326327 protected static function buildOutput (ObjectSchema |array |string |null $ output ): ObjectSchema |string |null
327328 {
328329 if (is_array ($ output )) {
329330 try {
330- collect ($ output )->ensure (Schema ::class);
331+ collect ($ output )->ensure (JsonSchema ::class);
331332 } catch (UnexpectedValueException $ e ) {
332333 throw new GenericException ('Invalid output schema: ' . $ e ->getMessage (), previous: $ e );
333334 }
334335
335- return SchemaFactory ::object ()->properties (...$ output );
336+ return Schema ::object ()->properties (...$ output );
336337 }
337338
338339 return $ output ;
0 commit comments