Skip to content

Commit 1dae7a7

Browse files
committed
Merge branch 'main' into 2.x
2 parents 187965e + 8c16474 commit 1dae7a7

File tree

11 files changed

+45
-12
lines changed

11 files changed

+45
-12
lines changed

examples/workflow/workflow-interrupt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
}
3535

3636
// Resume the workflow providing external data
37-
$finalState = $workflow->start(true, 'approved')->getResult();
37+
$finalState = $workflow->wakeup('approved')->getResult();
3838

3939
// It should print "approved"
4040
echo $finalState->get('received_feedback').\PHP_EOL;

src/Console/Make/Stubs/node.stub

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ use NeuronAI\Workflow\WorkflowState;
1111

1212
class [classname] extends Node
1313
{
14+
/**
15+
* Implement the Node's logic
16+
*/
1417
public function __invoke(StartEvent $event, WorkflowState $state): StopEvent
1518
{
19+
// ...
20+
1621
return new StopEvent();
1722
}
1823
}

src/Console/Make/Stubs/tool.stub

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ declare(strict_types=1);
44

55
namespace [namespace];
66

7+
use NeuronAI\Tools\PropertyType;
78
use NeuronAI\Tools\Tool;
9+
use NeuronAI\Tools\ToolProperty;
810

911
class [classname] extends Tool
1012
{
@@ -18,20 +20,27 @@ class [classname] extends Tool
1820
}
1921

2022
/**
21-
* Return the list of properties.
23+
* Properties are the input arguments of the __invoke method.
2224
*/
2325
protected function properties(): array
2426
{
2527
return [
26-
// ...
28+
new ToolProperty(
29+
name: 'input',
30+
type: PropertyType::STRING,
31+
description: 'The input to the tool',
32+
required: true,
33+
),
2734
];
2835
}
2936

3037
/**
3138
* Implementing the tool logic
3239
*/
33-
public function __invoke(): string
40+
public function __invoke(string $input): string
3441
{
3542
// ...
43+
44+
return $input;
3645
}
3746
}

src/HandleStructured.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public function structured(Message|array $messages, ?string $class = null, int $
8585
return self::structured($toolCallResult, $class, $maxRetries);
8686
}
8787

88+
$this->fillChatHistory($response);
89+
8890
$output = $this->processResponse($response, $schema, $class);
8991
$this->notify('structured-stop');
9092
return $output;

src/Providers/OpenAI/AzureOpenAI.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ public function __construct(
1515
protected string $endpoint,
1616
protected string $model,
1717
protected string $version,
18+
protected bool $strict_response = false,
1819
protected array $parameters = [],
1920
) {
21+
parent::__construct($key, $model, $parameters, $strict_response);
22+
2023
$this->setBaseUrl();
2124

2225
$this->client = new Client([

src/Tools/Toolkits/Supadata/SupadataVideoMetadataTool.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use NeuronAI\Tools\Tool;
99
use NeuronAI\Tools\ToolProperty;
1010

11+
/**
12+
* @method static static make(string $key)
13+
*/
1114
class SupadataVideoMetadataTool extends Tool
1215
{
1316
use HttpClient;

src/Tools/Toolkits/Supadata/SupadataYoutubeChannelTool.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use NeuronAI\Tools\Tool;
99
use NeuronAI\Tools\ToolProperty;
1010

11+
/**
12+
* @method static static make(string $key)
13+
*/
1114
class SupadataYoutubeChannelTool extends Tool
1215
{
1316
use HttpClient;

src/Tools/Toolkits/Supadata/SupadataYoutubePlaylistTool.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use NeuronAI\Tools\Tool;
99
use NeuronAI\Tools\ToolProperty;
1010

11+
/**
12+
* @method static static make(string $key)
13+
*/
1114
class SupadataYoutubePlaylistTool extends Tool
1215
{
1316
use HttpClient;

src/Workflow/Node.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ abstract class Node implements NodeInterface
1111
protected WorkflowState $currentState;
1212
protected Event $currentEvent;
1313
protected bool $isResuming = false;
14-
protected array $feedback = [];
14+
protected mixed $feedback = null;
1515

1616
public function run(Event $event, WorkflowState $state): \Generator|Event
1717
{
@@ -23,7 +23,7 @@ public function setWorkflowContext(
2323
WorkflowState $currentState,
2424
Event $currentEvent,
2525
bool $isResuming = false,
26-
array $feedback = []
26+
mixed $feedback = null
2727
): void {
2828
$this->currentState = $currentState;
2929
$this->currentEvent = $currentEvent;
@@ -37,10 +37,10 @@ public function setWorkflowContext(
3737
*/
3838
protected function interrupt(array $data): mixed
3939
{
40-
if ($this->isResuming && isset($this->feedback[static::class])) {
41-
$feedback = $this->feedback[static::class];
40+
if ($this->isResuming && !\is_null($this->feedback)) {
41+
$feedback = $this->feedback;
4242
// Clear both feedback and resuming state after use to allow subsequent interrupts
43-
unset($this->feedback[static::class]);
43+
$this->feedback = null;
4444
$this->isResuming = false;
4545
return $feedback;
4646
}

src/Workflow/Workflow.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public function start(
7272
return new WorkflowHandler($this, $resume, $externalFeedback);
7373
}
7474

75+
public function wakeup(mixed $feedback = null): WorkflowHandler
76+
{
77+
return new WorkflowHandler($this, true, $feedback);
78+
}
79+
7580
/**
7681
* @throws WorkflowInterrupt|WorkflowException|\Throwable
7782
*/
@@ -134,15 +139,13 @@ protected function execute(
134139
bool $resuming = false,
135140
mixed $externalFeedback = null
136141
): \Generator {
137-
$feedback = $resuming ? [$currentNode::class => $externalFeedback] : [];
138-
139142
try {
140143
while (!($currentEvent instanceof StopEvent)) {
141144
$currentNode->setWorkflowContext(
142145
$this->state,
143146
$currentEvent,
144147
$resuming,
145-
$feedback
148+
$externalFeedback
146149
);
147150

148151
$this->notify('workflow-node-start', new WorkflowNodeStart($currentNode::class, $this->state));

0 commit comments

Comments
 (0)