Skip to content

Commit d3af3af

Browse files
committed
wip
1 parent aa0fc00 commit d3af3af

33 files changed

+285
-301
lines changed

config/cortex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@
308308

309309
/**
310310
* Whether to check a models features before attempting to use it.
311-
* Set to false by default, to ensure a given model feature is available.
311+
* Set to true to ensure a given model feature is available.
312312
*/
313313
'ignore_features' => env('CORTEX_MODEL_INFO_IGNORE_FEATURES', false),
314314

scratchpad.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
use Cortex\Agents\Agent;
77
use Cortex\Prompts\Prompt;
88
use Cortex\JsonSchema\Schema;
9-
use Cortex\Tools\Prebuilt\WeatherTool;
109
use Cortex\Agents\Prebuilt\WeatherAgent;
1110
use Cortex\LLM\Data\Messages\UserMessage;
1211
use Cortex\LLM\Data\Messages\SystemMessage;
12+
use Cortex\Tools\Prebuilt\OpenMeteoWeatherTool;
1313

1414
$prompt = Cortex::prompt([
1515
new SystemMessage('You are an expert at geography.'),
@@ -109,7 +109,7 @@
109109
->withPrompt('You are a weather agent. You tell the weather in {location}.')
110110
->withLLM('ollama:gpt-oss:20b')
111111
->withTools([
112-
WeatherTool::class,
112+
OpenMeteoWeatherTool::class,
113113
])
114114
->withOutput(Schema::object()->properties(
115115
Schema::string('location')->required(),

src/Agents/Agent.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
use Cortex\LLM\Enums\ToolChoice;
2020
use Cortex\LLM\Contracts\Message;
2121
use Cortex\Memory\Contracts\Store;
22+
use Cortex\Pipeline\RuntimeConfig;
2223
use Cortex\Support\Traits\CanPipe;
23-
use Cortex\Pipeline\RuntimeContext;
2424
use Cortex\Agents\Stages\AppendUsage;
2525
use Cortex\LLM\Data\ChatStreamResult;
2626
use Cortex\Exceptions\GenericException;
@@ -58,9 +58,8 @@ class Agent implements Pipeable
5858
protected Pipeline $pipeline;
5959

6060
/**
61-
* @param class-string|\Cortex\JsonSchema\Types\ObjectSchema $output
61+
* @param class-string|\Cortex\JsonSchema\Types\ObjectSchema|array<array-key, \Cortex\JsonSchema\Contracts\JsonSchema>|null $output
6262
* @param array<int, \Cortex\LLM\Contracts\Tool|\Closure|string>|\Cortex\Contracts\ToolKit $tools
63-
* @param class-string|class-string<\BackedEnum>|\Cortex\JsonSchema\Types\ObjectSchema|array<array-key, \Cortex\JsonSchema\Contracts\JsonSchema>|null $llm
6463
* @param array<string, mixed> $initialPromptVariables
6564
*/
6665
public function __construct(
@@ -177,7 +176,7 @@ public function stream(array $messages = [], array $input = []): ChatStreamResul
177176
return $result;
178177
}
179178

180-
public function handlePipeable(mixed $payload, RuntimeContext $context, Closure $next): mixed
179+
public function handlePipeable(mixed $payload, RuntimeConfig $config, Closure $next): mixed
181180
{
182181
$messages = match (true) {
183182
$payload instanceof MessageCollection => $payload->all(),
@@ -193,7 +192,7 @@ public function handlePipeable(mixed $payload, RuntimeContext $context, Closure
193192
default => [],
194193
};
195194

196-
return $next($this->invoke($messages, $input), $context);
195+
return $next($this->invoke($messages, $input), $config);
197196
}
198197

199198
public function getName(): string

src/Agents/Prebuilt/WeatherAgent.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
use Cortex\Contracts\ToolKit;
1010
use Cortex\JsonSchema\Schema;
1111
use Cortex\LLM\Contracts\LLM;
12-
use Cortex\Tools\Prebuilt\WeatherTool;
1312
use Cortex\Agents\AbstractAgentBuilder;
1413
use Cortex\JsonSchema\Types\ObjectSchema;
1514
use Cortex\LLM\Data\Messages\UserMessage;
1615
use Cortex\LLM\Data\Messages\SystemMessage;
1716
use Cortex\Prompts\Builders\ChatPromptBuilder;
17+
use Cortex\Tools\Prebuilt\OpenMeteoWeatherTool;
1818
use Cortex\Prompts\Templates\ChatPromptTemplate;
1919

2020
class WeatherAgent extends AbstractAgentBuilder
@@ -29,7 +29,7 @@ public function prompt(): ChatPromptTemplate|ChatPromptBuilder|string
2929
return Cortex::prompt([
3030
new SystemMessage('You are a weather agent. Output in sentences.'),
3131
new UserMessage('What is the weather in {location}?'),
32-
])->strict(false);
32+
]);
3333
}
3434

3535
public function llm(): LLM|string|null
@@ -41,7 +41,7 @@ public function llm(): LLM|string|null
4141
public function tools(): array|ToolKit
4242
{
4343
return [
44-
WeatherTool::class,
44+
OpenMeteoWeatherTool::class,
4545
];
4646
}
4747

src/Agents/Stages/AddMessageToMemory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
use Cortex\Contracts\Pipeable;
99
use Cortex\LLM\Data\ChatResult;
1010
use Cortex\Contracts\ChatMemory;
11+
use Cortex\Pipeline\RuntimeConfig;
1112
use Cortex\Support\Traits\CanPipe;
1213
use Cortex\LLM\Data\ChatGeneration;
13-
use Cortex\Pipeline\RuntimeContext;
1414
use Cortex\LLM\Data\ChatGenerationChunk;
1515

1616
class AddMessageToMemory implements Pipeable
@@ -21,7 +21,7 @@ public function __construct(
2121
protected ChatMemory $memory,
2222
) {}
2323

24-
public function handlePipeable(mixed $payload, RuntimeContext $context, Closure $next): mixed
24+
public function handlePipeable(mixed $payload, RuntimeConfig $config, Closure $next): mixed
2525
{
2626
$message = match (true) {
2727
$payload instanceof ChatGeneration => $payload->message,
@@ -34,6 +34,6 @@ public function handlePipeable(mixed $payload, RuntimeContext $context, Closure
3434
$this->memory->addMessage($message);
3535
}
3636

37-
return $next($payload, $context);
37+
return $next($payload, $config);
3838
}
3939
}

src/Agents/Stages/AppendUsage.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use Cortex\LLM\Data\Usage;
99
use Cortex\Contracts\Pipeable;
1010
use Cortex\LLM\Data\ChatResult;
11+
use Cortex\Pipeline\RuntimeConfig;
1112
use Cortex\Support\Traits\CanPipe;
12-
use Cortex\Pipeline\RuntimeContext;
1313
use Cortex\LLM\Data\ChatGenerationChunk;
1414

1515
class AppendUsage implements Pipeable
@@ -20,7 +20,7 @@ public function __construct(
2020
protected Usage $usage,
2121
) {}
2222

23-
public function handlePipeable(mixed $payload, RuntimeContext $context, Closure $next): mixed
23+
public function handlePipeable(mixed $payload, RuntimeConfig $config, Closure $next): mixed
2424
{
2525
$usage = match (true) {
2626
$payload instanceof ChatResult, $payload instanceof ChatGenerationChunk && $payload->isFinal => $payload->usage,
@@ -31,6 +31,6 @@ public function handlePipeable(mixed $payload, RuntimeContext $context, Closure
3131
$this->usage->add($usage);
3232
}
3333

34-
return $next($payload, $context);
34+
return $next($payload, $config);
3535
}
3636
}

src/Agents/Stages/HandleToolCalls.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
use Cortex\Contracts\Pipeable;
1010
use Cortex\LLM\Data\ChatResult;
1111
use Cortex\Contracts\ChatMemory;
12+
use Cortex\Pipeline\RuntimeConfig;
1213
use Cortex\Support\Traits\CanPipe;
1314
use Illuminate\Support\Collection;
1415
use Cortex\LLM\Data\ChatGeneration;
15-
use Cortex\Pipeline\RuntimeContext;
1616
use Cortex\LLM\Data\ChatGenerationChunk;
1717
use Cortex\LLM\Data\Messages\ToolMessage;
1818

@@ -32,7 +32,7 @@ public function __construct(
3232
protected int $maxSteps,
3333
) {}
3434

35-
public function handlePipeable(mixed $payload, RuntimeContext $context, Closure $next): mixed
35+
public function handlePipeable(mixed $payload, RuntimeConfig $config, Closure $next): mixed
3636
{
3737
$generation = $this->getGeneration($payload);
3838

@@ -50,14 +50,14 @@ public function handlePipeable(mixed $payload, RuntimeContext $context, Closure
5050
$payload = $this->executionPipeline->invoke([
5151
'messages' => $this->memory->getMessages(),
5252
...$this->memory->getVariables(),
53-
], $context);
53+
], $config);
5454

5555
// Update the generation so that the loop can check the new generation for tool calls.
5656
$generation = $this->getGeneration($payload);
5757
}
5858
}
5959

60-
return $next($payload, $context);
60+
return $next($payload, $config);
6161
}
6262

6363
/**

src/Contracts/Pipeable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66

77
use Closure;
88
use Cortex\Pipeline;
9-
use Cortex\Pipeline\RuntimeContext;
9+
use Cortex\Pipeline\RuntimeConfig;
1010

1111
interface Pipeable
1212
{
1313
/**
1414
* Handle the pipeline processing.
1515
*
1616
* @param mixed $payload The input to process
17-
* @param RuntimeContext $context The runtime context containing settings
17+
* @param RuntimeConfig $config The runtime context containing settings
1818
* @param Closure $next The next stage in the pipeline
1919
*
2020
* @return mixed The processed result
2121
*/
22-
public function handlePipeable(mixed $payload, RuntimeContext $context, Closure $next): mixed;
22+
public function handlePipeable(mixed $payload, RuntimeConfig $config, Closure $next): mixed;
2323

2424
/**
2525
* Pipe the pipeable into another pipeable.

src/Events/PipelineEnd.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
namespace Cortex\Events;
66

77
use Cortex\Pipeline;
8-
use Cortex\Pipeline\RuntimeContext;
8+
use Cortex\Pipeline\RuntimeConfig;
99

1010
readonly class PipelineEnd
1111
{
1212
public function __construct(
1313
public Pipeline $pipeline,
1414
public mixed $payload,
15-
public RuntimeContext $context,
15+
public RuntimeConfig $config,
1616
public mixed $result,
1717
) {}
1818
}

src/Events/PipelineError.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
use Throwable;
88
use Cortex\Pipeline;
9-
use Cortex\Pipeline\RuntimeContext;
9+
use Cortex\Pipeline\RuntimeConfig;
1010

1111
readonly class PipelineError
1212
{
1313
public function __construct(
1414
public Pipeline $pipeline,
1515
public mixed $payload,
16-
public RuntimeContext $context,
16+
public RuntimeConfig $config,
1717
public Throwable $exception,
1818
) {}
1919
}

0 commit comments

Comments
 (0)