Skip to content

Plan

AgenticPlan

Bases: Plan

Agentic Plan class for defining and managing agentic plans comprised of agents, inputs, outputs, and streams.

Source code in blue/agents/plan.py
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
class AgenticPlan(dag_utils.Plan):
    """Agentic Plan class for defining and managing agentic plans comprised of agents, inputs, outputs, and streams."""

    def __init__(self, scope=None, id=None, label=None, type="AGENTIC_PLAN", properties=None, path=None, synchronizer=None, auto_sync=False, sync=None):
        """Initializes an AgenticPlan instance.

        Parameters:
            scope: The scope of the plan (Session or str).
            id: Unique identifier for the plan.
            label: Human-readable label for the plan.
            type: Type of the plan (default is "AGENTIC_PLAN").
            properties: Additional properties for the plan.
        """
        self.leaves = None
        super().__init__(id=id, label=label, type=type, properties=properties, path=path, synchronizer=synchronizer, auto_sync=auto_sync, sync=sync)

        s = scope
        if isinstance(s, Session):
            s = scope.cid

        self._set_scope(s, sync=sync)

    def _init_data(self, sync=None):
        """Initializes the data for the plan, setting up context and status.

        Parameters:
            sync: Whether to synchronize the data immediately.
        """
        super()._init_data(sync=sync)

        self.set_data("context", {"scope": None}, sync=sync)
        self.set_status(Status.INACTIVE, sync=sync)

    # properties
    def _initialize_properties(self, sync=None):
        """Initializes the properties for the plan, including database connectivity.

        Parameters:
            sync: Whether to synchronize the properties immediately.
        """
        super()._initialize_properties(sync=sync)

        # db connectivity
        self.set_property('db.host', 'localhost', sync=sync)
        self.set_property('db.port', 6379, sync=sync)

    # context, scope
    def get_context(self):
        """Retrieves the context of the plan.

        Returns:
            The context dictionary of the plan.
        """
        return self.get_data("context")

    def get_scope(self):
        """Retrieves the scope of the plan.

        Returns:
            The scope of the plan.
        """
        context = self.get_context()
        if 'scope' in context:
            return context['scope']
        else:
            return None

    def _set_scope(self, scope, sync=None):
        """Sets the scope of the plan.

        Parameters:
            scope: The scope of the plan (Session or str).
            sync: Whether to synchronize the scope immediately.
        """
        context = self.get_context()
        context['scope'] = scope

        self.synchronize(key="context.scope", value=scope)

    # status
    def set_status(self, status, sync=None):
        """Sets the status of the plan.

        Parameters:
            status: The status to set for the plan.
            sync: Whether to synchronize the status immediately.
        """
        self.set_data("status", str(status), sync=sync)

    def get_status(self):
        """Retrieves the status of the plan.
        Returns:
            The status of the plan.
        """
        return self.get_data('status')

    #### plan specific nodes, agents
    # inputs, outputs, agents, w/input and output parameters
    def _get_default_label(self, agent, input=None, output=None):
        """Generates a default label for an agent input or output node.

        Parameters:
            agent: The canonical name of the agent.
            input: The name of the input parameter (if applicable).
            output: The name of the output parameter (if applicable).

        Returns:
            A string representing the default label.
        """
        label = agent

        if input:
            label = label + ".INPUT:" + input
        elif output:
            label = label + ".OUTPUT:" + output

        return label

    def define_input(self, label=None, value=None, stream=None, properties={}, sync=None):
        """Defines an input node for the plan.

        Parameters:
            label: The label for the input node.
            value: The value for the input node.
            stream: The stream associated with the input node (if any).
            properties: Additional properties for the input node.
            sync: Whether to synchronize the input node immediately.
        """
        input_node = self.create_node(label=label, type=str(NodeType.INPUT), properties=properties, sync=sync)

        # input value/stream
        input_node.set_data('value', value, sync=sync)

        # add stream, if assigned
        if stream:
            self.set_node_stream(label, stream, sync=sync)

        return input_node

    def define_output(self, label=None, value=None, stream=None, properties={}, sync=None):
        """Defines an output node for the plan.

        Parameters:
            label: The label for the output node.
            value: The value for the output node.
            stream: The stream associated with the output node (if any).
            properties: Additional properties for the output node.
            sync: Whether to synchronize the output node immediately.
        """
        output_node = self.create_node(label=label, type=str(NodeType.OUTPUT), properties=properties, sync=sync)

        # output value/stream
        output_node.set_data('value', value, sync=sync)

        # add stream, if assigned
        if stream:
            self.set_node_stream(label, stream, sync=sync)

        return output_node

    def define_agent(self, name=None, label=None, properties={}, sync=None):
        """Defines an agent entity in the plan.

        Parameters:
            name: The name of the agent.
            label: The label for the agent (if different from name).
            properties: Additional properties for the agent to pass on to execution.
            sync: Whether to synchronize the agent immediately.
        """

        # checks
        if name is None:
            raise Exception("Name is not specified")
        if label and Separator.AGENT in label:
            raise Exception("Label cannot contain: " + Separator.AGENT)

        if label is None:
            label = name

        agent = self.create_agent(label=label, properties=properties, sync=sync)

        agent.set_data("name", name)
        canonical_name = name if label == name else name + Separator.AGENT + label
        agent.set_data("canonical_name", canonical_name)

        # add canonical_name to map
        self.map(canonical_name, agent.get_id(), sync=sync)

        return agent

    def define_agent_input(self, name=None, agent=None, stream=None, properties={}, sync=None):
        """Defines an agent input node in the plan.

        Parameters:
            name: The name of the input parameter.
            agent: The agent associated with the input parameter (name, id, or canonical name).
            stream: The stream associated with the input node (if any).
            properties: Additional properties for the input node.
            sync: Whether to synchronize the input node immediately.
        """
        # checks
        if name is None:
            raise Exception("Name is not specified")
        if agent is None:
            raise Exception("Agent is not specified")

        # get agent agent
        agent = self.get_agent(agent)

        if agent:
            agent_id = agent.get_id()
            agent_canonical_name = agent.get_data("canonical_name")
        else:
            raise Exception("Agent is not in defined")

        label = self._get_default_label(agent_canonical_name, input=name)

        # agent input node
        agent_input_node = self.create_node(label=label, type=str(NodeType.AGENT_INPUT), properties=properties, sync=sync)
        agent_input_node.set_data("name", name, sync=sync)
        agent_input_node.set_data("canonical_name", label, sync=sync)
        agent_input_node.set_data("value", None, sync=sync)

        self.set_node_entity(agent_input_node.get_id(), agent_id, sync=sync)

        # add stream, if assigned
        if stream:
            self.set_node_stream(label, stream, sync=sync)

        return agent_input_node

    def define_agent_output(self, name, agent, properties={}, sync=None):
        """Defines an agent output node in the plan.

        Parameters:
            name: The name of the output parameter.
            agent: The agent associated with the output parameter (name, id, or canonical name).
            properties: Additional properties for the output node.
            sync: Whether to synchronize the output node immediately.
        """
        # checks
        if name is None:
            raise Exception("Name is not specified")
        if agent is None:
            raise Exception("Agent is not specified")

        # get agent agent
        agent = self.get_agent(agent)

        if agent:
            agent_id = agent.get_id()
            agent_canonical_name = agent.get_data("canonical_name")
        else:
            raise Exception("Agent is not in defined")

        label = self._get_default_label(agent_canonical_name, output=name)

        # agent output node
        agent_output_node = self.create_node(label=label, type=str(NodeType.AGENT_OUTPUT), properties=properties, sync=sync)
        agent_output_node.set_data("name", name, sync=sync)
        agent_output_node.set_data("canonical_name", label, sync=sync)
        agent_output_node.set_data("value", None, sync=sync)

        self.set_node_entity(agent_output_node.get_id(), agent_id, sync=sync)

        return agent_output_node

    ### agent
    def create_agent(self, label=None, properties=None, sync=None):
        """Creates an agent entity in the plan.

        Parameters:
            label: The label for the agent. Defaults to None.
            properties: Additional properties for the agent. Defaults to None.
            sync: Whether to synchronize immediately. Defaults to None.

        Returns:
            The created agent entity.
        """
        return self.create_entity(label=label, type=str(EntityType.AGENT), properties=properties, sync=sync)

    def get_agents(self):
        """
        Returns a list of all agent entities in the plan.

        Returns:
            List of agent entities.
        """
        return self.get_entities(type=str(EntityType.AGENT))

    def get_agent(self, a, cls=None):
        """Retrieves an agent entity by its identifier, label, or canonical name.

        Parameters:
            a: The identifier, label, or canonical name of the agent.
            cls: Optional class type for the agent entity. Defaults to None.

        Returns:
            The agent entity if found, else None.
        """
        return self.get_entity(a, type=str(EntityType.AGENT))

    def get_agent_by_id(self, agent_id, cls=None):
        return self.get_entity_by_id(agent_id, type=str(EntityType.AGENT), cls=cls)

    def get_agent_by_label(self, agent_label, cls=None):
        return self.get_entity_by_label(agent_label, type=str(EntityType.AGENT), cls=cls)

    def get_agent_properties(self, a):
        agent = self.get_agent(a)
        if agent:
            return agent.get_properties()
        return {}

    ### stream
    def create_stream(self, label=None, properties=None, sync=None):
        return self.create_entity(label=label, type=str(EntityType.STREAM), properties=properties, sync=sync)

    def get_streams(self):
        return self.get_entities(type=str(EntityType.STREAM))

    def get_stream(self, a, cls=None):
        return self.get_entity(a, type=str(EntityType.STREAM))

    def get_stream_by_id(self, stream_id, cls=None):
        return self.get_entity_by_id(stream_id, type=str(EntityType.STREAM), cls=cls)

    def get_stream_by_label(self, stream_label, cls=None):
        return self.get_entity_by_label(stream_label, type=str(EntityType.STREAM), cls=cls)

    def get_nodes_by_stream(self, s, node_type=None):
        return self.get_nodes_by_entity(s, type=str(EntityType.STREAM), node_type=node_type)

    def count_streams(self, filter_status=None):
        count = 0
        streams = self.get_streams()
        for stream_id in streams:
            stream = self.get_stream(stream_id)
            status = stream.get_data("status")

            if filter_status:
                if status not in filter_status:
                    continue

            count = count + 1

        return count

    # node
    def get_node_value(self, n):
        node = self.get_node(n)
        if node is None:
            raise Exception("Value for non-existing node cannot be get")

        value = node.get_data("value")

        if value is None:
            return self.fetch_node_value_from_stream(n)

    def set_node_value_from_stream(self, n, sync=None):
        node = self.get_node(n)
        if node is None:
            raise Exception("Value for non-existing node cannot be get")

        node.set_data("value", self.fetch_node_value_from_stream(n), sync=sync)

    def fetch_node_value_from_stream(self, n):
        node = self.get_node(n)
        if node is None:
            raise Exception("Value for non-existing node cannot be get")

        # get from stream
        stream = self.get_node_entity(n, type=str(EntityType.STREAM))

        stream_status = stream.get_data("status")
        if stream_status == Status.FINISHED:
            return self.get_stream_value(stream)

        return None

    def set_node_stream(self, n, stream, sync=None):
        stream_node = self.get_stream(stream)
        if stream_node is None:
            stream_node = self.create_stream(label=stream, sync=sync)
            stream_node.set_data("status", str(Status.INITED), sync=sync)
            stream_node.set_data("value", None, sync=sync)

        self.set_node_entity(n, stream, sync=sync)

    def get_node_stream(self, n):
        return self.get_node_entity(n, type=str(EntityType.STREAM))

    # status, value
    def set_stream_status(self, s, status, sync=None):
        stream = self.get_stream(s)
        if stream:
            stream.set_data("status", str(status), sync=sync)

    def get_stream_status(self, s):
        stream = self.get_stream(s)
        if stream:
            return stream.get_data("status")
        return None

    def set_stream_value(self, s, value, sync=None):
        stream = self.get_stream(s)
        if stream:
            stream.set_data("value", value, sync=sync)

    def append_stream_value(self, s, value, sync=None):
        stream = self.get_stream(s)
        if stream:
            stream.append_data("value", value, sync=sync)

    def get_stream_value(self, s):
        stream = self.get_stream(s)
        if stream:
            return stream.get_data("value")
        return None

    # discovery
    def match_stream(self, stream):
        node = None
        stream_prefix = self.get_scope() + ":" + "PLAN" + ":" + self.get_id()
        # TODO: REVISE THIS LOGIC!
        if stream.find(stream_prefix) == 0:
            s = stream[len(stream_prefix) + 1 :]
            ss = s.split(":")

            agent = ss[0]
            param = ss[3]

            default_label = self._get_default_label(agent, output=param)

            node = self.get_node(default_label)

        return node

    # node functions
    def set_node_value(self, n, value, sync=None):
        node = self.get_node(n)
        if node is None:
            raise Exception("Value for non-existing node cannot be set")

        node.set_data("value", value, sync=sync)

    def get_node_properties(self, n):
        node = self.get_node(n)
        if node is None:
            raise Exception("Properties for non-existing node cannot be get")

        return node.get_properties()

    def get_node_property(self, n, property):
        node = self.get_node(n)
        if node is None:
            raise Exception("Properties for non-existing node cannot be get")

        return node.get_property(property)

    def set_node_properties(self, n, properties, sync=None):
        node = self.get_node(n)
        if node is None:
            raise Exception("Properties for non-existing node cannot be set")

        for property in properties:
            node.set_property(property, properties[property], sync=sync)

    def set_node_property(self, n, property, value, sync=None):
        node = self.get_node(n)
        if node is None:
            raise Exception("Properties for non-existing node cannot be set")

        node.set_property(property, value, sync=sync)

    def get_node_type(self, n):
        node = self.get_node(n)

        if node is None:
            raise Exception("Type for non-existing node cannot be get")

        return node.get_type()

    def get_node_agent(self, n):
        return self.get_node_entity(n, type=str(EntityType.AGENT))

    ## connections
    def _resolve_input_output_node_id(self, input=None, output=None, sync=None):
        n = None
        if input:
            n = input
        elif output:
            n = output
        else:
            raise Exception("Input/Output should be specified")

        node = self.get_node(n)

        if node is None:
            # create node
            if input:
                node = self.define_input(label=input, sync=sync)
            elif output:
                node = self.define_output(label=output, sync=sync)

        return node.get_id()

    def _resolve_agent_param_node_id(self, agent=None, agent_param=None, node_type=None, sync=None):
        node_id = None
        if agent:
            if agent_param is None:
                agent_param = "DEFAULT"

            agent_node = self.get_agent(agent)
            if agent_node is None:
                agent_node = self.define_agent(name=agent, sync=sync)

            agent_canonical_name = agent_node.get_data("canonical_name")
            label = None
            if node_type == NodeType.AGENT_INPUT:
                label = self._get_default_label(agent_canonical_name, input=agent_param)
            elif node_type == NodeType.AGENT_OUTPUT:
                label = self._get_default_label(agent_canonical_name, output=agent_param)

            agent_param_node = self.get_node(label)
            if agent_param_node is None:
                if node_type == NodeType.AGENT_INPUT:
                    agent_param_node = self.define_agent_input(name=agent_param, agent=agent, sync=sync)
                elif node_type == NodeType.AGENT_OUTPUT:
                    agent_param_node = self.define_agent_output(name=agent_param, agent=agent, sync=sync)

            node_id = agent_param_node.get_id()

        elif agent_param:
            agent_param_node = self.get_node(agent_param)
            node_id = agent_param_node.get_id()
        else:
            raise Exception("Non-existing agent input/output cannot be connected")

        return node_id

    def connect_input_to_agent(self, from_input=None, to_agent=None, to_agent_input=None, sync=None):

        from_id = self._resolve_input_output_node_id(input=from_input, sync=sync)
        to_id = self._resolve_agent_param_node_id(agent=to_agent, agent_param=to_agent_input, node_type=NodeType.AGENT_INPUT, sync=sync)
        self.connect_nodes(from_id, to_id, sync=sync)

    def connect_agent_to_agent(self, from_agent=None, from_agent_output=None, to_agent=None, to_agent_input=None, sync=None):

        from_id = self._resolve_agent_param_node_id(agent=from_agent, agent_param=from_agent_output, node_type=NodeType.AGENT_OUTPUT, sync=sync)
        to_id = self._resolve_agent_param_node_id(agent=to_agent, agent_param=to_agent_input, node_type=NodeType.AGENT_INPUT, sync=sync)
        self.connect_nodes(from_id, to_id, sync=sync)

    def connect_agent_to_output(self, from_agent=None, from_agent_output=None, to_output=None, sync=None):

        from_id = self._resolve_agent_param_node_id(agent=from_agent, agent_param=from_agent_output, node_type=NodeType.AGENT_OUTPUT, sync=sync)
        to_id = self._resolve_input_output_node_id(output=to_output, sync=sync)
        self.connect_nodes(from_id, to_id, sync=sync)

    def connect_input_to_output(self, from_input=None, to_output=None, sync=None):

        from_id = self._resolve_input_output_node_id(input=from_input, sync=sync)
        to_id = self._resolve_input_output_node_id(output=to_output, sync=sync)
        self.connect_nodes(from_id, to_id, sync=sync)

    # plan execution i/o
    def _write_to_stream(self, worker, data, output, tags=None, eos=True):
        # tags
        if tags is None:
            tags = []
        # auto-add HIDDEN
        tags.append("HIDDEN")

        # data
        output_stream = worker.write_data(data, output=output, id=self.get_id(), tags=tags, scope="worker")

        # eos
        if eos:
            worker.write_eos(output=output, id=self.get_id(), scope="worker")

        return output_stream

    def _write_data(self, worker, data, output, eos=True):
        return self._write_to_stream(worker, data, output, eos=eos)

    def _write_plan(self, worker, eos=True):
        return self._write_to_stream(worker, self.get_data(), "PLAN", tags=["PLAN"], eos=eos)

    # plan execution status/checks
    def _detect_leaves(self):
        self.leaves = []

        nodes = self.get_nodes()
        for node_id in nodes:
            if self.is_node_leaf(node_id):
                self.leaves.append(node_id)

    def check_status(self, sync=None):
        if self.leaves is None:
            self._detect_leaves()

        status = Status.FINISHED

        for leaf_id in self.leaves:
            leaf_stream = self.get_node_stream(leaf_id)
            if leaf_stream is None:
                status = Status.RUNNING
                break
            leaf_stream_status = self.get_stream_status(leaf_stream)
            if leaf_stream_status != Status.FINISHED:
                status = Status.RUNNING
                break

        self.set_status(status, sync=sync)
        return status

    # plan submit
    def submit(self, worker, sync=None):
        # process inputs with initialized values, if any
        nodes = self.get_nodes()
        for node_id in nodes:
            node = self.get_node(node_id)

            # inputs
            if node.get_type() == NodeType.INPUT:
                node_value = node.get_data("value")
                if node_value:
                    node_label = node.get_label()
                    # write data for input
                    stream = self._write_data(worker, node_value, node_label)
                    # set stream for node
                    self.set_node_stream(node_id, stream, sync=sync)
            # outputs
            if node.get_type() == NodeType.OUTPUT:
                node_value = node.get_data("value")
                if node_value:
                    node_label = node.get_label()
                    # write data for output
                    stream = self._write_data(worker, node_value, node_label)
                    # set stream for node
                    self.set_node_stream(node_id, stream, sync=sync)

        # set status
        self.set_status(Status.SUBMITTED, sync=sync)

        # write plan
        self._write_plan(worker)

    @classmethod
    def _validate(cls, d):
        dv = super(AgenticPlan, cls)._validate(d)
        if dv is None:
            return None
        if 'context' not in dv:
            return None
        else:
            context = dv['context']
            if 'scope' not in context:
                return None

        return dv

__init__(scope=None, id=None, label=None, type='AGENTIC_PLAN', properties=None, path=None, synchronizer=None, auto_sync=False, sync=None)

Initializes an AgenticPlan instance.

Parameters:

Name Type Description Default
scope

The scope of the plan (Session or str).

None
id

Unique identifier for the plan.

None
label

Human-readable label for the plan.

None
type

Type of the plan (default is "AGENTIC_PLAN").

'AGENTIC_PLAN'
properties

Additional properties for the plan.

None
Source code in blue/agents/plan.py
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
def __init__(self, scope=None, id=None, label=None, type="AGENTIC_PLAN", properties=None, path=None, synchronizer=None, auto_sync=False, sync=None):
    """Initializes an AgenticPlan instance.

    Parameters:
        scope: The scope of the plan (Session or str).
        id: Unique identifier for the plan.
        label: Human-readable label for the plan.
        type: Type of the plan (default is "AGENTIC_PLAN").
        properties: Additional properties for the plan.
    """
    self.leaves = None
    super().__init__(id=id, label=label, type=type, properties=properties, path=path, synchronizer=synchronizer, auto_sync=auto_sync, sync=sync)

    s = scope
    if isinstance(s, Session):
        s = scope.cid

    self._set_scope(s, sync=sync)

create_agent(label=None, properties=None, sync=None)

Creates an agent entity in the plan.

Parameters:

Name Type Description Default
label

The label for the agent. Defaults to None.

None
properties

Additional properties for the agent. Defaults to None.

None
sync

Whether to synchronize immediately. Defaults to None.

None

Returns:

Type Description

The created agent entity.

Source code in blue/agents/plan.py
348
349
350
351
352
353
354
355
356
357
358
359
def create_agent(self, label=None, properties=None, sync=None):
    """Creates an agent entity in the plan.

    Parameters:
        label: The label for the agent. Defaults to None.
        properties: Additional properties for the agent. Defaults to None.
        sync: Whether to synchronize immediately. Defaults to None.

    Returns:
        The created agent entity.
    """
    return self.create_entity(label=label, type=str(EntityType.AGENT), properties=properties, sync=sync)

define_agent(name=None, label=None, properties={}, sync=None)

Defines an agent entity in the plan.

Parameters:

Name Type Description Default
name

The name of the agent.

None
label

The label for the agent (if different from name).

None
properties

Additional properties for the agent to pass on to execution.

{}
sync

Whether to synchronize the agent immediately.

None
Source code in blue/agents/plan.py
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
def define_agent(self, name=None, label=None, properties={}, sync=None):
    """Defines an agent entity in the plan.

    Parameters:
        name: The name of the agent.
        label: The label for the agent (if different from name).
        properties: Additional properties for the agent to pass on to execution.
        sync: Whether to synchronize the agent immediately.
    """

    # checks
    if name is None:
        raise Exception("Name is not specified")
    if label and Separator.AGENT in label:
        raise Exception("Label cannot contain: " + Separator.AGENT)

    if label is None:
        label = name

    agent = self.create_agent(label=label, properties=properties, sync=sync)

    agent.set_data("name", name)
    canonical_name = name if label == name else name + Separator.AGENT + label
    agent.set_data("canonical_name", canonical_name)

    # add canonical_name to map
    self.map(canonical_name, agent.get_id(), sync=sync)

    return agent

define_agent_input(name=None, agent=None, stream=None, properties={}, sync=None)

Defines an agent input node in the plan.

Parameters:

Name Type Description Default
name

The name of the input parameter.

None
agent

The agent associated with the input parameter (name, id, or canonical name).

None
stream

The stream associated with the input node (if any).

None
properties

Additional properties for the input node.

{}
sync

Whether to synchronize the input node immediately.

None
Source code in blue/agents/plan.py
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
def define_agent_input(self, name=None, agent=None, stream=None, properties={}, sync=None):
    """Defines an agent input node in the plan.

    Parameters:
        name: The name of the input parameter.
        agent: The agent associated with the input parameter (name, id, or canonical name).
        stream: The stream associated with the input node (if any).
        properties: Additional properties for the input node.
        sync: Whether to synchronize the input node immediately.
    """
    # checks
    if name is None:
        raise Exception("Name is not specified")
    if agent is None:
        raise Exception("Agent is not specified")

    # get agent agent
    agent = self.get_agent(agent)

    if agent:
        agent_id = agent.get_id()
        agent_canonical_name = agent.get_data("canonical_name")
    else:
        raise Exception("Agent is not in defined")

    label = self._get_default_label(agent_canonical_name, input=name)

    # agent input node
    agent_input_node = self.create_node(label=label, type=str(NodeType.AGENT_INPUT), properties=properties, sync=sync)
    agent_input_node.set_data("name", name, sync=sync)
    agent_input_node.set_data("canonical_name", label, sync=sync)
    agent_input_node.set_data("value", None, sync=sync)

    self.set_node_entity(agent_input_node.get_id(), agent_id, sync=sync)

    # add stream, if assigned
    if stream:
        self.set_node_stream(label, stream, sync=sync)

    return agent_input_node

define_agent_output(name, agent, properties={}, sync=None)

Defines an agent output node in the plan.

Parameters:

Name Type Description Default
name

The name of the output parameter.

required
agent

The agent associated with the output parameter (name, id, or canonical name).

required
properties

Additional properties for the output node.

{}
sync

Whether to synchronize the output node immediately.

None
Source code in blue/agents/plan.py
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
def define_agent_output(self, name, agent, properties={}, sync=None):
    """Defines an agent output node in the plan.

    Parameters:
        name: The name of the output parameter.
        agent: The agent associated with the output parameter (name, id, or canonical name).
        properties: Additional properties for the output node.
        sync: Whether to synchronize the output node immediately.
    """
    # checks
    if name is None:
        raise Exception("Name is not specified")
    if agent is None:
        raise Exception("Agent is not specified")

    # get agent agent
    agent = self.get_agent(agent)

    if agent:
        agent_id = agent.get_id()
        agent_canonical_name = agent.get_data("canonical_name")
    else:
        raise Exception("Agent is not in defined")

    label = self._get_default_label(agent_canonical_name, output=name)

    # agent output node
    agent_output_node = self.create_node(label=label, type=str(NodeType.AGENT_OUTPUT), properties=properties, sync=sync)
    agent_output_node.set_data("name", name, sync=sync)
    agent_output_node.set_data("canonical_name", label, sync=sync)
    agent_output_node.set_data("value", None, sync=sync)

    self.set_node_entity(agent_output_node.get_id(), agent_id, sync=sync)

    return agent_output_node

define_input(label=None, value=None, stream=None, properties={}, sync=None)

Defines an input node for the plan.

Parameters:

Name Type Description Default
label

The label for the input node.

None
value

The value for the input node.

None
stream

The stream associated with the input node (if any).

None
properties

Additional properties for the input node.

{}
sync

Whether to synchronize the input node immediately.

None
Source code in blue/agents/plan.py
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
def define_input(self, label=None, value=None, stream=None, properties={}, sync=None):
    """Defines an input node for the plan.

    Parameters:
        label: The label for the input node.
        value: The value for the input node.
        stream: The stream associated with the input node (if any).
        properties: Additional properties for the input node.
        sync: Whether to synchronize the input node immediately.
    """
    input_node = self.create_node(label=label, type=str(NodeType.INPUT), properties=properties, sync=sync)

    # input value/stream
    input_node.set_data('value', value, sync=sync)

    # add stream, if assigned
    if stream:
        self.set_node_stream(label, stream, sync=sync)

    return input_node

define_output(label=None, value=None, stream=None, properties={}, sync=None)

Defines an output node for the plan.

Parameters:

Name Type Description Default
label

The label for the output node.

None
value

The value for the output node.

None
stream

The stream associated with the output node (if any).

None
properties

Additional properties for the output node.

{}
sync

Whether to synchronize the output node immediately.

None
Source code in blue/agents/plan.py
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def define_output(self, label=None, value=None, stream=None, properties={}, sync=None):
    """Defines an output node for the plan.

    Parameters:
        label: The label for the output node.
        value: The value for the output node.
        stream: The stream associated with the output node (if any).
        properties: Additional properties for the output node.
        sync: Whether to synchronize the output node immediately.
    """
    output_node = self.create_node(label=label, type=str(NodeType.OUTPUT), properties=properties, sync=sync)

    # output value/stream
    output_node.set_data('value', value, sync=sync)

    # add stream, if assigned
    if stream:
        self.set_node_stream(label, stream, sync=sync)

    return output_node

get_agent(a, cls=None)

Retrieves an agent entity by its identifier, label, or canonical name.

Parameters:

Name Type Description Default
a

The identifier, label, or canonical name of the agent.

required
cls

Optional class type for the agent entity. Defaults to None.

None

Returns:

Type Description

The agent entity if found, else None.

Source code in blue/agents/plan.py
370
371
372
373
374
375
376
377
378
379
380
def get_agent(self, a, cls=None):
    """Retrieves an agent entity by its identifier, label, or canonical name.

    Parameters:
        a: The identifier, label, or canonical name of the agent.
        cls: Optional class type for the agent entity. Defaults to None.

    Returns:
        The agent entity if found, else None.
    """
    return self.get_entity(a, type=str(EntityType.AGENT))

get_agents()

Returns a list of all agent entities in the plan.

Returns:

Type Description

List of agent entities.

Source code in blue/agents/plan.py
361
362
363
364
365
366
367
368
def get_agents(self):
    """
    Returns a list of all agent entities in the plan.

    Returns:
        List of agent entities.
    """
    return self.get_entities(type=str(EntityType.AGENT))

get_context()

Retrieves the context of the plan.

Returns:

Type Description

The context dictionary of the plan.

Source code in blue/agents/plan.py
127
128
129
130
131
132
133
def get_context(self):
    """Retrieves the context of the plan.

    Returns:
        The context dictionary of the plan.
    """
    return self.get_data("context")

get_scope()

Retrieves the scope of the plan.

Returns:

Type Description

The scope of the plan.

Source code in blue/agents/plan.py
135
136
137
138
139
140
141
142
143
144
145
def get_scope(self):
    """Retrieves the scope of the plan.

    Returns:
        The scope of the plan.
    """
    context = self.get_context()
    if 'scope' in context:
        return context['scope']
    else:
        return None

get_status()

Retrieves the status of the plan. Returns: The status of the plan.

Source code in blue/agents/plan.py
169
170
171
172
173
174
def get_status(self):
    """Retrieves the status of the plan.
    Returns:
        The status of the plan.
    """
    return self.get_data('status')

set_status(status, sync=None)

Sets the status of the plan.

Parameters:

Name Type Description Default
status

The status to set for the plan.

required
sync

Whether to synchronize the status immediately.

None
Source code in blue/agents/plan.py
160
161
162
163
164
165
166
167
def set_status(self, status, sync=None):
    """Sets the status of the plan.

    Parameters:
        status: The status to set for the plan.
        sync: Whether to synchronize the status immediately.
    """
    self.set_data("status", str(status), sync=sync)

EntityType

Bases: Constant

Type of entity in the plan:

  • AGENT: An agent entity.
  • STREAM: A data stream entity.
Source code in blue/agents/plan.py
61
62
63
64
65
66
67
68
69
70
class EntityType(Constant):
    """
    Type of entity in the plan:

    - AGENT: An agent entity.
    - STREAM: A data stream entity.
    """

    def __init__(self, c):
        super().__init__(c)

NodeType

Bases: Constant

Type of node in the plan:

  • INPUT: Input node.
  • OUTPUT: Output node.
  • AGENT_INPUT: Input node for an agent.
  • AGENT_OUTPUT: Output node for an agent.
Source code in blue/agents/plan.py
41
42
43
44
45
46
47
48
49
50
51
52
class NodeType(Constant):
    """
    Type of node in the plan:

    - INPUT: Input node.
    - OUTPUT: Output node.
    - AGENT_INPUT: Input node for an agent.
    - AGENT_OUTPUT: Output node for an agent.
    """

    def __init__(self, c):
        super().__init__(c)

Status

Bases: Constant

Status of the plan or stream:

  • INACTIVE: Initial state, not yet started.
  • SUBMITTED: Submitted for execution.
  • INITED: Initialized and ready to run.
  • PLANNED: Planned for execution.
  • RUNNING: Currently executing.
  • FINISHED: Execution completed.
Source code in blue/agents/plan.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Status(Constant):
    """
    Status of the plan or stream:

    - INACTIVE: Initial state, not yet started.
    - SUBMITTED: Submitted for execution.
    - INITED: Initialized and ready to run.
    - PLANNED: Planned for execution.
    - RUNNING: Currently executing.
    - FINISHED: Execution completed.
    """

    def __init__(self, c):
        super().__init__(c)
Last update: 2025-10-09