WiseAgent

Bases: YAMLObject

A WiseAgent is an abstract class that represents an agent that can send and receive messages to and from other agents.

Source code in wiseagents/wise_agent.py
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 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
class WiseAgent(yaml.YAMLObject):
    ''' A WiseAgent is an abstract class that represents an agent that can send and receive messages to and from other agents.
    '''
    yaml_tag = u'!wiseagents.WiseAgent'

    def __new__(cls, *args, **kwargs):
        '''Create a new instance of the class, setting default values for the instance variables.'''
        obj = super().__new__(cls)
        obj._llm = None
        obj._vector_db = None
        obj._graph_db = None
        obj._collection_name = "wise-agent-collection"
        obj._system_message = None
        return obj

    def __init__(self, name: str, description: str, transport: WiseAgentTransport, llm: Optional[WiseAgentLLM] = None,
                 vector_db: Optional[WiseAgentVectorDB] = None, collection_name: Optional[str] = "wise-agent-collection",
                 graph_db: Optional[WiseAgentGraphDB] = None, system_message: Optional[str] = None):
        ''' 
        Initialize the agent with the given name, description, transport, LLM, vector DB, collection name, and graph DB.


        Args:
            name (str): the name of the agent
            description (str): a description of what the agent does
            transport (WiseAgentTransport): the transport to use for sending and receiving messages
            llm Optional(WiseAgentLLM): the LLM associated with the agent
            vector_db Optional(WiseAgentVectorDB): the vector DB associated with the agent
            collection_name Optional(str) = "wise-agent-collection": the vector DB collection name associated with the agent
            graph_db Optional (WiseAgentGraphDB): the graph DB associated with the agent
            system_message Optional(str): an optional system message that can be used by the agent when processing chat
            completions using its LLM
        '''
        self._name = name
        self._description = description
        self._llm = llm
        self._vector_db = vector_db
        self._collection_name = collection_name
        self._graph_db = graph_db
        self._transport = transport
        self._system_message = system_message
        self.startAgent()

    def startAgent(self):
        ''' Start the agent by setting the call backs and starting the transport.'''
        self.transport.set_call_backs(self.process_request, self.process_event, self.process_error, self.process_response)
        self.transport.start()
        WiseAgentRegistry.register_agent(self) 
    def stopAgent(self):
        ''' Stop the agent by stopping the transport and removing the agent from the registry.'''
        self.transport.stop()
        WiseAgentRegistry.remove_agent(self.name)

    def __repr__(self):
        '''Return a string representation of the agent.'''
        return (f"{self.__class__.__name__}(name={self.name}, description={self.description}, llm={self.llm},"
                f"vector_db={self.vector_db}, collection_name={self._collection_name}, graph_db={self.graph_db},"
                f"system_message={self.system_message})")

    @property
    def name(self) -> str:
        """Get the name of the agent."""
        return self._name

    @property
    def description(self) -> str:
        """Get a description of what the agent does."""
        return self._description

    @property
    def llm(self) -> Optional[WiseAgentLLM]:
        """Get the LLM associated with the agent."""
        return self._llm

    @property
    def vector_db(self) -> Optional[WiseAgentVectorDB]:
        """Get the vector DB associated with the agent."""
        return self._vector_db

    @property
    def collection_name(self) -> str:
        """Get the vector DB collection name associated with the agent."""
        return self._collection_name

    @property
    def graph_db(self) -> Optional[WiseAgentGraphDB]:
        """Get the graph DB associated with the agent."""
        return self._graph_db

    @property
    def transport(self) -> WiseAgentTransport:
        """Get the transport associated with the agent."""
        return self._transport

    @property
    def system_message(self) -> Optional[str]:
        """Get the system message associated with the agent."""
        return self._system_message

    def send_request(self, message: WiseAgentMessage, dest_agent_name: str):
        '''Send a request message to the destination agent with the given name.

        Args:
            message (WiseAgentMessage): the message to send
            dest_agent_name (str): the name of the destination agent'''
        message.sender = self.name
        context = WiseAgentRegistry.get_or_create_context(message.context_name)
        context.add_participant(self)
        self.transport.send_request(message, dest_agent_name)
        context.message_trace.append(message)

    def send_response(self, message: WiseAgentMessage, dest_agent_name):
        '''Send a response message to the destination agent with the given name.

        Args:
            message (WiseAgentMessage): the message to send
            dest_agent_name (str): the name of the destination agent'''
        message.sender = self.name
        context = WiseAgentRegistry.get_or_create_context(message.context_name)
        context.add_participant(self)
        self.transport.send_response(message, dest_agent_name)
        context.message_trace.append(message)  

    @abstractmethod
    def process_request(self, message: WiseAgentMessage) -> bool:
        """
        Callback method to process the given request for this agent.


        Args:
            message (WiseAgentMessage): the message to be processed

        Returns:
            True if the message was processed successfully, False otherwise
        """
        ...

    @abstractmethod
    def process_response(self, message: WiseAgentMessage) -> bool:
        """
        Callback method to process the response received from another agent which processed a request from this agent.


        Args:
            message (WiseAgentMessage): the message to be processed

        Returns:
            True if the message was processed successfully, False otherwise
        """
        ...

    @abstractmethod
    def process_event(self, event: WiseAgentEvent) -> bool:
        """
        Callback method to process the given event.


        Args:
            event (WiseAgentEvent): the event to be processed

        Returns:
           True if the event was processed successfully, False otherwise
        """
        ...

    @abstractmethod
    def process_error(self, error: Exception) -> bool:
        """
        Callback method to process the given error.


        Args:
            error (Exception): the error to be processed

        Returns:
            True if the error was processed successfully, False otherwise
        """
        ...

    @abstractmethod
    def get_recipient_agent_name(self, message: WiseAgentMessage) -> str:
        """
        Get the name of the agent to send the given message to.


        Args:
             message (WiseAgentMessage): the message to be sent

        Returns:
            str: the name of the agent to send the given message to
        """
        ...

collection_name: str property

Get the vector DB collection name associated with the agent.

description: str property

Get a description of what the agent does.

graph_db: Optional[WiseAgentGraphDB] property

Get the graph DB associated with the agent.

llm: Optional[WiseAgentLLM] property

Get the LLM associated with the agent.

name: str property

Get the name of the agent.

system_message: Optional[str] property

Get the system message associated with the agent.

transport: WiseAgentTransport property

Get the transport associated with the agent.

vector_db: Optional[WiseAgentVectorDB] property

Get the vector DB associated with the agent.

__init__(name, description, transport, llm=None, vector_db=None, collection_name='wise-agent-collection', graph_db=None, system_message=None)

Initialize the agent with the given name, description, transport, LLM, vector DB, collection name, and graph DB.

Parameters:
  • name (str) –

    the name of the agent

  • description (str) –

    a description of what the agent does

  • transport (WiseAgentTransport) –

    the transport to use for sending and receiving messages

  • llm (Optional(WiseAgentLLM, default: None ) –

    the LLM associated with the agent

  • vector_db (Optional(WiseAgentVectorDB, default: None ) –

    the vector DB associated with the agent

  • collection_name (Optional(str) = "wise-agent-collection", default: 'wise-agent-collection' ) –

    the vector DB collection name associated with the agent

  • graph_db (Optional (WiseAgentGraphDB, default: None ) –

    the graph DB associated with the agent

  • system_message (Optional(str, default: None ) –

    an optional system message that can be used by the agent when processing chat

Source code in wiseagents/wise_agent.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def __init__(self, name: str, description: str, transport: WiseAgentTransport, llm: Optional[WiseAgentLLM] = None,
             vector_db: Optional[WiseAgentVectorDB] = None, collection_name: Optional[str] = "wise-agent-collection",
             graph_db: Optional[WiseAgentGraphDB] = None, system_message: Optional[str] = None):
    ''' 
    Initialize the agent with the given name, description, transport, LLM, vector DB, collection name, and graph DB.


    Args:
        name (str): the name of the agent
        description (str): a description of what the agent does
        transport (WiseAgentTransport): the transport to use for sending and receiving messages
        llm Optional(WiseAgentLLM): the LLM associated with the agent
        vector_db Optional(WiseAgentVectorDB): the vector DB associated with the agent
        collection_name Optional(str) = "wise-agent-collection": the vector DB collection name associated with the agent
        graph_db Optional (WiseAgentGraphDB): the graph DB associated with the agent
        system_message Optional(str): an optional system message that can be used by the agent when processing chat
        completions using its LLM
    '''
    self._name = name
    self._description = description
    self._llm = llm
    self._vector_db = vector_db
    self._collection_name = collection_name
    self._graph_db = graph_db
    self._transport = transport
    self._system_message = system_message
    self.startAgent()

__new__(*args, **kwargs)

Create a new instance of the class, setting default values for the instance variables.

Source code in wiseagents/wise_agent.py
23
24
25
26
27
28
29
30
31
def __new__(cls, *args, **kwargs):
    '''Create a new instance of the class, setting default values for the instance variables.'''
    obj = super().__new__(cls)
    obj._llm = None
    obj._vector_db = None
    obj._graph_db = None
    obj._collection_name = "wise-agent-collection"
    obj._system_message = None
    return obj

__repr__()

Return a string representation of the agent.

Source code in wiseagents/wise_agent.py
71
72
73
74
75
def __repr__(self):
    '''Return a string representation of the agent.'''
    return (f"{self.__class__.__name__}(name={self.name}, description={self.description}, llm={self.llm},"
            f"vector_db={self.vector_db}, collection_name={self._collection_name}, graph_db={self.graph_db},"
            f"system_message={self.system_message})")

get_recipient_agent_name(message) abstractmethod

Get the name of the agent to send the given message to.

Parameters:
Returns:
  • str( str ) –

    the name of the agent to send the given message to

Source code in wiseagents/wise_agent.py
197
198
199
200
201
202
203
204
205
206
207
208
209
@abstractmethod
def get_recipient_agent_name(self, message: WiseAgentMessage) -> str:
    """
    Get the name of the agent to send the given message to.


    Args:
         message (WiseAgentMessage): the message to be sent

    Returns:
        str: the name of the agent to send the given message to
    """
    ...

process_error(error) abstractmethod

Callback method to process the given error.

Parameters:
  • error (Exception) –

    the error to be processed

Returns:
  • bool

    True if the error was processed successfully, False otherwise

Source code in wiseagents/wise_agent.py
183
184
185
186
187
188
189
190
191
192
193
194
195
@abstractmethod
def process_error(self, error: Exception) -> bool:
    """
    Callback method to process the given error.


    Args:
        error (Exception): the error to be processed

    Returns:
        True if the error was processed successfully, False otherwise
    """
    ...

process_event(event) abstractmethod

Callback method to process the given event.

Parameters:
Returns:
  • bool

    True if the event was processed successfully, False otherwise

Source code in wiseagents/wise_agent.py
169
170
171
172
173
174
175
176
177
178
179
180
181
@abstractmethod
def process_event(self, event: WiseAgentEvent) -> bool:
    """
    Callback method to process the given event.


    Args:
        event (WiseAgentEvent): the event to be processed

    Returns:
       True if the event was processed successfully, False otherwise
    """
    ...

process_request(message) abstractmethod

Callback method to process the given request for this agent.

Parameters:
Returns:
  • bool

    True if the message was processed successfully, False otherwise

Source code in wiseagents/wise_agent.py
141
142
143
144
145
146
147
148
149
150
151
152
153
@abstractmethod
def process_request(self, message: WiseAgentMessage) -> bool:
    """
    Callback method to process the given request for this agent.


    Args:
        message (WiseAgentMessage): the message to be processed

    Returns:
        True if the message was processed successfully, False otherwise
    """
    ...

process_response(message) abstractmethod

Callback method to process the response received from another agent which processed a request from this agent.

Parameters:
Returns:
  • bool

    True if the message was processed successfully, False otherwise

Source code in wiseagents/wise_agent.py
155
156
157
158
159
160
161
162
163
164
165
166
167
@abstractmethod
def process_response(self, message: WiseAgentMessage) -> bool:
    """
    Callback method to process the response received from another agent which processed a request from this agent.


    Args:
        message (WiseAgentMessage): the message to be processed

    Returns:
        True if the message was processed successfully, False otherwise
    """
    ...

send_request(message, dest_agent_name)

Send a request message to the destination agent with the given name.

Parameters:
  • message (WiseAgentMessage) –

    the message to send

  • dest_agent_name (str) –

    the name of the destination agent

Source code in wiseagents/wise_agent.py
117
118
119
120
121
122
123
124
125
126
127
def send_request(self, message: WiseAgentMessage, dest_agent_name: str):
    '''Send a request message to the destination agent with the given name.

    Args:
        message (WiseAgentMessage): the message to send
        dest_agent_name (str): the name of the destination agent'''
    message.sender = self.name
    context = WiseAgentRegistry.get_or_create_context(message.context_name)
    context.add_participant(self)
    self.transport.send_request(message, dest_agent_name)
    context.message_trace.append(message)

send_response(message, dest_agent_name)

Send a response message to the destination agent with the given name.

Parameters:
  • message (WiseAgentMessage) –

    the message to send

  • dest_agent_name (str) –

    the name of the destination agent

Source code in wiseagents/wise_agent.py
129
130
131
132
133
134
135
136
137
138
139
def send_response(self, message: WiseAgentMessage, dest_agent_name):
    '''Send a response message to the destination agent with the given name.

    Args:
        message (WiseAgentMessage): the message to send
        dest_agent_name (str): the name of the destination agent'''
    message.sender = self.name
    context = WiseAgentRegistry.get_or_create_context(message.context_name)
    context.add_participant(self)
    self.transport.send_response(message, dest_agent_name)
    context.message_trace.append(message)  

startAgent()

Start the agent by setting the call backs and starting the transport.

Source code in wiseagents/wise_agent.py
61
62
63
64
65
def startAgent(self):
    ''' Start the agent by setting the call backs and starting the transport.'''
    self.transport.set_call_backs(self.process_request, self.process_event, self.process_error, self.process_response)
    self.transport.start()
    WiseAgentRegistry.register_agent(self) 

stopAgent()

Stop the agent by stopping the transport and removing the agent from the registry.

Source code in wiseagents/wise_agent.py
66
67
68
69
def stopAgent(self):
    ''' Stop the agent by stopping the transport and removing the agent from the registry.'''
    self.transport.stop()
    WiseAgentRegistry.remove_agent(self.name)

WiseAgentContext

Source code in wiseagents/wise_agent.py
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
class WiseAgentContext():
    from typing import List
    ''' A WiseAgentContext is a class that represents a context in which agents can communicate with each other.
    '''

    _message_trace : List[WiseAgentMessage] = []
    _participants : List[WiseAgent] = []

    # Maps a chat uuid to a list of chat completion messages
    _llm_chat_completion : Dict[str, List[ChatCompletionMessageParam]] = {}

    # Maps a chat uuid to a list of tool names that need to be executed
    _llm_required_tool_call : Dict[str, List[str]] = {}

    # Maps a chat uuid to a list of available tools in chat
    _llm_available_tools_in_chat : Dict[str, List[ChatCompletionToolParam]] = {}

    # Maps a chat uuid to a list of agent names that need to be executed in sequence
    # Used by a sequential coordinator
    _agents_sequence : Dict[str, List[str]] = {}

    # Maps a chat uuid to the agent where the final response should be routed to
    # Used by both a sequential coordinator and a phased coordinator
    _route_response_to : Dict[str, str] = {}

    # Maps a chat uuid to a list that contains a list of agent names to be executed for each phase
    # Used by a phased coordinator
    _agent_phase_assignments : Dict[str, List[List[str]]] = {}

    # Maps a chat uuid to the current phase. Used by a phased coordinator.
    _current_phase : Dict[str, int] = {}

    # Maps a chat uuid to a list of agent names that need to be executed for the current phase
    # Used by a phased coordinator
    _required_agents_for_current_phase : Dict[str, List[str]] = {}

    # Maps a chat uuid to a list containing the queries attempted for each iteration executed by
    # the phased coordinator
    _queries : Dict[str, List[str]] = {}

    def __init__(self, name: str):
        ''' Initialize the context with the given name.

        Args:
            name (str): the name of the context'''
        self._name = name
        WiseAgentRegistry.register_context(self)

    @property   
    def name(self) -> str:
        """Get the name of the context."""
        return self._name

    @property
    def message_trace(self) -> List[WiseAgentMessage]:
        """Get the message trace of the context."""
        return self._message_trace
    @property
    def participants(self) -> List[WiseAgent]:
        """Get the participants of the context."""
        return self._participants

    @property
    def llm_chat_completion(self) -> Dict[str, List[ChatCompletionMessageParam]]:
        """Get the LLM chat completion of the context."""
        return self._llm_chat_completion

    def add_participant(self, agent: WiseAgent):
        '''Add a participant to the context.

        Args:
            agent (WiseAgent): the agent to add'''

        if agent not in self._participants:
            self._participants.append(agent)

    def append_chat_completion(self, chat_uuid: str, messages: Iterable[ChatCompletionMessageParam]):
        '''Append chat completion to the context.

        Args:
            chat_uuid (str): the chat uuid
            messages (Iterable[ChatCompletionMessageParam]): the messages to append'''

        if chat_uuid not in self._llm_chat_completion:
            self._llm_chat_completion[chat_uuid] = []
        self._llm_chat_completion[chat_uuid].append(messages)

    @property
    def llm_required_tool_call(self) -> Dict[str, List[str]]:
        """Get the LLM required tool call of the context.
        return Dict[str, List[str]]"""
        return self._llm_required_tool_call

    def append_required_tool_call(self, chat_uuid: str, tool_name: str):
        '''Append required tool call to the context.

        Args:
            chat_uuid (str): the chat uuid
            tool_name (str): the tool name to append'''
        if chat_uuid not in self._llm_required_tool_call:
            self._llm_required_tool_call[chat_uuid] = []
        self._llm_required_tool_call[chat_uuid].append(tool_name)

    def remove_required_tool_call(self, chat_uuid: str, tool_name: str):
        '''Remove required tool call from the context.

        Args:
            chat_uuid (str): the chat uuid
            tool_name (str): the tool name to remove'''
        if chat_uuid in self._llm_required_tool_call:
            self._llm_required_tool_call[chat_uuid].remove(tool_name)
            if len(self._llm_required_tool_call[chat_uuid]) == 0:
                self._llm_required_tool_call.pop(chat_uuid)

    def get_required_tool_calls(self, chat_uuid: str) -> List[str]:
        '''Get required tool calls from the context.

        Args:
            chat_uuid (str): the chat uuid
            return List[str]'''
        if chat_uuid in self._llm_required_tool_call:
            return self._llm_required_tool_call[chat_uuid]
        else:
            return []   

    @property
    def llm_available_tools_in_chat(self) -> Dict[str, List[ChatCompletionToolParam]]:
        """Get the LLM available tools in chat of the context."""
        return self._llm_available_tools_in_chat

    def append_available_tool_in_chat(self, chat_uuid: str, tools: Iterable[ChatCompletionToolParam]):
        '''Append available tool in chat to the context.

        Args:
            chat_uuid (str): the chat uuid
            tools (Iterable[ChatCompletionToolParam]): the tools to append'''
        if chat_uuid not in self._llm_available_tools_in_chat:
            self._llm_available_tools_in_chat[chat_uuid] = []
        self._llm_available_tools_in_chat[chat_uuid].append(tools)

    def get_available_tools_in_chat(self, chat_uuid: str) -> List[ChatCompletionToolParam]:
        '''Get available tools in chat from the context.

        Args:
            chat_uuid (str): the chat uuid
            return List[ChatCompletionToolParam]'''
        if chat_uuid in self._llm_available_tools_in_chat:
            return self._llm_available_tools_in_chat[chat_uuid]
        else:
            return []

    def get_agents_sequence(self, chat_uuid: str) -> List[str]:
        """
        Get the sequence of agents for the given chat uuid for this context. This is used by a sequential
        coordinator to execute its agents in a specific order, passing the output from one agent in the sequence
        to the next agent in the sequence.

        Args:
            chat_uuid (str): the chat uuid

        Returns:
            List[str]: the sequence of agents names or an empty list if no sequence has been set for this context
        """
        if chat_uuid in self._agents_sequence:
            return self._agents_sequence[chat_uuid]
        return []

    def set_agents_sequence(self, chat_uuid: str, agents_sequence: List[str]):
        """
        Set the sequence of agents for the given chat uuid for this context. This is used by
        a sequential coordinator to execute its agents in a specific order, passing the output
        from one agent in the sequence to the next agent in the sequence.

        Args:
            chat_uuid (str): the chat uuid
            agents_sequence (List[str]): the sequence of agent names
        """
        self._agents_sequence[chat_uuid] = agents_sequence

    def get_route_response_to(self, chat_uuid: str) -> Optional[str]:
        """
        Get the name of the agent where the final response should be routed to for the given chat uuid for this
        context. This is used by a sequential coordinator and a phased coordinator.

        Returns:
            Optional[str]: the name of the agent where the final response should be routed to or None if no agent is set
        """
        if chat_uuid in self._route_response_to:
            return self._route_response_to[chat_uuid]
        else:
            return None

    def set_route_response_to(self, chat_uuid: str, agent: str):
        """
        Set the name of the agent where the final response should be routed to for the given chat uuid for this
        context. This is used by a sequential coordinator and a phased coordinator.

        Args:
            chat_uuid (str): the chat uuid
            agent (str): the name of the agent where the final response should be routed to
        """
        self._route_response_to[chat_uuid] = agent

    def get_next_agent_in_sequence(self, chat_uuid: str, current_agent: str):
        """
        Get the name of the next agent in the sequence of agents for the given chat uuid for this context.
        This is used by a sequential coordinator to determine the name of the next agent to execute.

        Args:
            chat_uuid (str): the chat uuid
            current_agent (str): the name of the current agent

        Returns:
            str: the name of the next agent in the sequence after the current agent or None if there are no remaining
            agents in the sequence after the current agent
        """
        agents_sequence = self.get_agents_sequence(chat_uuid)
        if current_agent in agents_sequence:
            current_agent_index = agents_sequence.index(current_agent)
            next_agent_index = current_agent_index + 1
            if next_agent_index < len(agents_sequence):
                return agents_sequence[next_agent_index]
        return None

    def get_agent_phase_assignments(self, chat_uuid: str) -> List[List[str]]:
        """
        Get the agents to be executed in each phase for the given chat uuid for this context. This is used
        by a phased coordinator.

        Args:
            chat_uuid (str): the chat uuid

        Returns:
            List[List[str]]: The agents to be executed in each phase, represented as a list of lists, where the
            size of the outer list corresponds to the number of phases and each element in the list is a list of
            agent names for that phase. An empty list is returned if no phases have been set for the
            given chat uuid
        """
        if chat_uuid in self._agent_phase_assignments:
            return self._agent_phase_assignments.get(chat_uuid)
        return []

    def set_agent_phase_assignments(self, chat_uuid: str, agent_phase_assignments: List[List[str]]):
        """
        Set the agents to be executed in each phase for the given chat uuid for this context. This is used
        by a phased coordinator.

        Args:
            chat_uuid (str): the chat uuid
            agent_phase_assignments (List[List[str]]): The agents to be executed in each phase, represented as a
            list of lists, where the size of the outer list corresponds to the number of phases and each element
            in the list is a list of agent names for that phase.
        """
        self._agent_phase_assignments[chat_uuid] = agent_phase_assignments

    def get_current_phase(self, chat_uuid: str) -> int:
        """
        Get the current phase for the given chat uuid for this context. This is used by a phased coordinator.

        Args:
            chat_uuid (str): the chat uuid

        Returns:
            int: the current phase, represented as an integer in the zero-indexed list of phases
        """
        return self._current_phase.get(chat_uuid)

    def set_current_phase(self, chat_uuid: str, phase: int):
        """
        Set the current phase for the given chat uuid for this context. This method also
        sets the required agents for the current phase. This is used by a phased coordinator.

        Args:
            chat_uuid (str): the chat uuid
            phase (int): the current phase, represented as an integer in the zero-indexed list of phases
        """
        self._current_phase[chat_uuid] = phase
        self._required_agents_for_current_phase[chat_uuid] = copy.deepcopy(self._agent_phase_assignments[chat_uuid][phase])

    def get_agents_for_next_phase(self, chat_uuid: str) -> Optional[List]:
        """
        Get the list of agents to be executed for the next phase for the given chat uuid for this context.
        This is used by a phased coordinator.

        Args:
            chat_uuid (str): the chat uuid

        Returns:
            Optional[List[str]]: the list of agent names for the next phase or None if there are no more phases
        """
        current_phase = self.get_current_phase(chat_uuid)
        next_phase = current_phase + 1
        if next_phase < len(self._agent_phase_assignments[chat_uuid]):
            self.set_current_phase(chat_uuid, next_phase)
            return self._agent_phase_assignments[chat_uuid][next_phase]
        return None

    def get_required_agents_for_current_phase(self, chat_uuid: str) -> List[str]:
        """
        Get the list of agents that still need to be executed for the current phase for the given chat uuid for this
        context. This is used by a phased coordinator.

        Args:
            chat_uuid (str): the chat uuid

        Returns:
            List[str]: the list of agent names that still need to be executed for the current phase or an empty list
            if there are no remaining agents that need to be executed for the current phase
        """
        if chat_uuid in self._required_agents_for_current_phase:
            return self._required_agents_for_current_phase.get(chat_uuid)
        return []

    def remove_required_agent_for_current_phase(self, chat_uuid: str, agent_name: str):
        """
        Remove the given agent from the list of required agents for the current phase for the given chat uuid for this
        context. This is used by a phased coordinator.

        Args:
            chat_uuid (str): the chat uuid
            agent_name (str): the name of the agent to remove
        """
        if chat_uuid in self._required_agents_for_current_phase:
            self._required_agents_for_current_phase.get(chat_uuid).remove(agent_name)

    def get_current_query(self, chat_uuid: str) -> Optional[str]:
        """
        Get the current query for the given chat uuid for this context. This is used by a phased coordinator.

        Args:
            chat_uuid (str): the chat uuid

        Returns:
            Optional[str]: the current query or None if there is no current query
        """
        if chat_uuid in self._queries:
            if self._queries.get(chat_uuid):
                # return the last query
                return self._queries.get(chat_uuid)[-1]
        else:
            return None

    def add_query(self, chat_uuid: str, query: str):
        """
        Add the current query for the given chat uuid for this context. This is used by a phased coordinator.

        Args:
            chat_uuid (str): the chat uuid
            query (str): the current query
        """
        if chat_uuid not in self._queries:
            self._queries[chat_uuid] = []
        self._queries[chat_uuid].append(query)

    def get_queries(self, chat_uuid: str) -> List[str]:
        """
        Get the queries attempted for the given chat uuid for this context. This is used by a phased coordinator.

        Returns:
            List[str]: the queries attempted for the given chat uuid for this context
        """
        if chat_uuid in self._queries:
            return self._queries.get(chat_uuid)
        else:
            return []

llm_available_tools_in_chat: Dict[str, List[ChatCompletionToolParam]] property

Get the LLM available tools in chat of the context.

llm_chat_completion: Dict[str, List[ChatCompletionMessageParam]] property

Get the LLM chat completion of the context.

llm_required_tool_call: Dict[str, List[str]] property

Get the LLM required tool call of the context. return Dict[str, List[str]]

message_trace: List[WiseAgentMessage] property

Get the message trace of the context.

name: str property

Get the name of the context.

participants: List[WiseAgent] property

Get the participants of the context.

__init__(name)

Initialize the context with the given name.

Parameters:
  • name (str) –

    the name of the context

Source code in wiseagents/wise_agent.py
332
333
334
335
336
337
338
def __init__(self, name: str):
    ''' Initialize the context with the given name.

    Args:
        name (str): the name of the context'''
    self._name = name
    WiseAgentRegistry.register_context(self)

add_participant(agent)

Add a participant to the context.

Parameters:
Source code in wiseagents/wise_agent.py
359
360
361
362
363
364
365
366
def add_participant(self, agent: WiseAgent):
    '''Add a participant to the context.

    Args:
        agent (WiseAgent): the agent to add'''

    if agent not in self._participants:
        self._participants.append(agent)

add_query(chat_uuid, query)

Add the current query for the given chat uuid for this context. This is used by a phased coordinator.

Parameters:
  • chat_uuid (str) –

    the chat uuid

  • query (str) –

    the current query

Source code in wiseagents/wise_agent.py
634
635
636
637
638
639
640
641
642
643
644
def add_query(self, chat_uuid: str, query: str):
    """
    Add the current query for the given chat uuid for this context. This is used by a phased coordinator.

    Args:
        chat_uuid (str): the chat uuid
        query (str): the current query
    """
    if chat_uuid not in self._queries:
        self._queries[chat_uuid] = []
    self._queries[chat_uuid].append(query)

append_available_tool_in_chat(chat_uuid, tools)

Append available tool in chat to the context.

Parameters:
  • chat_uuid (str) –

    the chat uuid

  • tools (Iterable[ChatCompletionToolParam]) –

    the tools to append

Source code in wiseagents/wise_agent.py
422
423
424
425
426
427
428
429
430
def append_available_tool_in_chat(self, chat_uuid: str, tools: Iterable[ChatCompletionToolParam]):
    '''Append available tool in chat to the context.

    Args:
        chat_uuid (str): the chat uuid
        tools (Iterable[ChatCompletionToolParam]): the tools to append'''
    if chat_uuid not in self._llm_available_tools_in_chat:
        self._llm_available_tools_in_chat[chat_uuid] = []
    self._llm_available_tools_in_chat[chat_uuid].append(tools)

append_chat_completion(chat_uuid, messages)

Append chat completion to the context.

Parameters:
  • chat_uuid (str) –

    the chat uuid

  • messages (Iterable[ChatCompletionMessageParam]) –

    the messages to append

Source code in wiseagents/wise_agent.py
368
369
370
371
372
373
374
375
376
377
def append_chat_completion(self, chat_uuid: str, messages: Iterable[ChatCompletionMessageParam]):
    '''Append chat completion to the context.

    Args:
        chat_uuid (str): the chat uuid
        messages (Iterable[ChatCompletionMessageParam]): the messages to append'''

    if chat_uuid not in self._llm_chat_completion:
        self._llm_chat_completion[chat_uuid] = []
    self._llm_chat_completion[chat_uuid].append(messages)

append_required_tool_call(chat_uuid, tool_name)

Append required tool call to the context.

Parameters:
  • chat_uuid (str) –

    the chat uuid

  • tool_name (str) –

    the tool name to append

Source code in wiseagents/wise_agent.py
385
386
387
388
389
390
391
392
393
def append_required_tool_call(self, chat_uuid: str, tool_name: str):
    '''Append required tool call to the context.

    Args:
        chat_uuid (str): the chat uuid
        tool_name (str): the tool name to append'''
    if chat_uuid not in self._llm_required_tool_call:
        self._llm_required_tool_call[chat_uuid] = []
    self._llm_required_tool_call[chat_uuid].append(tool_name)

get_agent_phase_assignments(chat_uuid)

Get the agents to be executed in each phase for the given chat uuid for this context. This is used by a phased coordinator.

Parameters:
  • chat_uuid (str) –

    the chat uuid

Returns:
  • List[List[str]]

    List[List[str]]: The agents to be executed in each phase, represented as a list of lists, where the

  • List[List[str]]

    size of the outer list corresponds to the number of phases and each element in the list is a list of

  • List[List[str]]

    agent names for that phase. An empty list is returned if no phases have been set for the

  • List[List[str]]

    given chat uuid

Source code in wiseagents/wise_agent.py
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
def get_agent_phase_assignments(self, chat_uuid: str) -> List[List[str]]:
    """
    Get the agents to be executed in each phase for the given chat uuid for this context. This is used
    by a phased coordinator.

    Args:
        chat_uuid (str): the chat uuid

    Returns:
        List[List[str]]: The agents to be executed in each phase, represented as a list of lists, where the
        size of the outer list corresponds to the number of phases and each element in the list is a list of
        agent names for that phase. An empty list is returned if no phases have been set for the
        given chat uuid
    """
    if chat_uuid in self._agent_phase_assignments:
        return self._agent_phase_assignments.get(chat_uuid)
    return []

get_agents_for_next_phase(chat_uuid)

Get the list of agents to be executed for the next phase for the given chat uuid for this context. This is used by a phased coordinator.

Parameters:
  • chat_uuid (str) –

    the chat uuid

Returns:
  • Optional[List]

    Optional[List[str]]: the list of agent names for the next phase or None if there are no more phases

Source code in wiseagents/wise_agent.py
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
def get_agents_for_next_phase(self, chat_uuid: str) -> Optional[List]:
    """
    Get the list of agents to be executed for the next phase for the given chat uuid for this context.
    This is used by a phased coordinator.

    Args:
        chat_uuid (str): the chat uuid

    Returns:
        Optional[List[str]]: the list of agent names for the next phase or None if there are no more phases
    """
    current_phase = self.get_current_phase(chat_uuid)
    next_phase = current_phase + 1
    if next_phase < len(self._agent_phase_assignments[chat_uuid]):
        self.set_current_phase(chat_uuid, next_phase)
        return self._agent_phase_assignments[chat_uuid][next_phase]
    return None

get_agents_sequence(chat_uuid)

Get the sequence of agents for the given chat uuid for this context. This is used by a sequential coordinator to execute its agents in a specific order, passing the output from one agent in the sequence to the next agent in the sequence.

Parameters:
  • chat_uuid (str) –

    the chat uuid

Returns:
  • List[str]

    List[str]: the sequence of agents names or an empty list if no sequence has been set for this context

Source code in wiseagents/wise_agent.py
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
def get_agents_sequence(self, chat_uuid: str) -> List[str]:
    """
    Get the sequence of agents for the given chat uuid for this context. This is used by a sequential
    coordinator to execute its agents in a specific order, passing the output from one agent in the sequence
    to the next agent in the sequence.

    Args:
        chat_uuid (str): the chat uuid

    Returns:
        List[str]: the sequence of agents names or an empty list if no sequence has been set for this context
    """
    if chat_uuid in self._agents_sequence:
        return self._agents_sequence[chat_uuid]
    return []

get_available_tools_in_chat(chat_uuid)

Get available tools in chat from the context.

Parameters:
  • chat_uuid (str) –

    the chat uuid

Source code in wiseagents/wise_agent.py
432
433
434
435
436
437
438
439
440
441
def get_available_tools_in_chat(self, chat_uuid: str) -> List[ChatCompletionToolParam]:
    '''Get available tools in chat from the context.

    Args:
        chat_uuid (str): the chat uuid
        return List[ChatCompletionToolParam]'''
    if chat_uuid in self._llm_available_tools_in_chat:
        return self._llm_available_tools_in_chat[chat_uuid]
    else:
        return []

get_current_phase(chat_uuid)

Get the current phase for the given chat uuid for this context. This is used by a phased coordinator.

Parameters:
  • chat_uuid (str) –

    the chat uuid

Returns:
  • int( int ) –

    the current phase, represented as an integer in the zero-indexed list of phases

Source code in wiseagents/wise_agent.py
547
548
549
550
551
552
553
554
555
556
557
def get_current_phase(self, chat_uuid: str) -> int:
    """
    Get the current phase for the given chat uuid for this context. This is used by a phased coordinator.

    Args:
        chat_uuid (str): the chat uuid

    Returns:
        int: the current phase, represented as an integer in the zero-indexed list of phases
    """
    return self._current_phase.get(chat_uuid)

get_current_query(chat_uuid)

Get the current query for the given chat uuid for this context. This is used by a phased coordinator.

Parameters:
  • chat_uuid (str) –

    the chat uuid

Returns:
  • Optional[str]

    Optional[str]: the current query or None if there is no current query

Source code in wiseagents/wise_agent.py
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
def get_current_query(self, chat_uuid: str) -> Optional[str]:
    """
    Get the current query for the given chat uuid for this context. This is used by a phased coordinator.

    Args:
        chat_uuid (str): the chat uuid

    Returns:
        Optional[str]: the current query or None if there is no current query
    """
    if chat_uuid in self._queries:
        if self._queries.get(chat_uuid):
            # return the last query
            return self._queries.get(chat_uuid)[-1]
    else:
        return None

get_next_agent_in_sequence(chat_uuid, current_agent)

Get the name of the next agent in the sequence of agents for the given chat uuid for this context. This is used by a sequential coordinator to determine the name of the next agent to execute.

Parameters:
  • chat_uuid (str) –

    the chat uuid

  • current_agent (str) –

    the name of the current agent

Returns:
  • str

    the name of the next agent in the sequence after the current agent or None if there are no remaining

  • agents in the sequence after the current agent

Source code in wiseagents/wise_agent.py
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
def get_next_agent_in_sequence(self, chat_uuid: str, current_agent: str):
    """
    Get the name of the next agent in the sequence of agents for the given chat uuid for this context.
    This is used by a sequential coordinator to determine the name of the next agent to execute.

    Args:
        chat_uuid (str): the chat uuid
        current_agent (str): the name of the current agent

    Returns:
        str: the name of the next agent in the sequence after the current agent or None if there are no remaining
        agents in the sequence after the current agent
    """
    agents_sequence = self.get_agents_sequence(chat_uuid)
    if current_agent in agents_sequence:
        current_agent_index = agents_sequence.index(current_agent)
        next_agent_index = current_agent_index + 1
        if next_agent_index < len(agents_sequence):
            return agents_sequence[next_agent_index]
    return None

get_queries(chat_uuid)

Get the queries attempted for the given chat uuid for this context. This is used by a phased coordinator.

Returns:
  • List[str]

    List[str]: the queries attempted for the given chat uuid for this context

Source code in wiseagents/wise_agent.py
646
647
648
649
650
651
652
653
654
655
656
def get_queries(self, chat_uuid: str) -> List[str]:
    """
    Get the queries attempted for the given chat uuid for this context. This is used by a phased coordinator.

    Returns:
        List[str]: the queries attempted for the given chat uuid for this context
    """
    if chat_uuid in self._queries:
        return self._queries.get(chat_uuid)
    else:
        return []

get_required_agents_for_current_phase(chat_uuid)

Get the list of agents that still need to be executed for the current phase for the given chat uuid for this context. This is used by a phased coordinator.

Parameters:
  • chat_uuid (str) –

    the chat uuid

Returns:
  • List[str]

    List[str]: the list of agent names that still need to be executed for the current phase or an empty list

  • List[str]

    if there are no remaining agents that need to be executed for the current phase

Source code in wiseagents/wise_agent.py
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
def get_required_agents_for_current_phase(self, chat_uuid: str) -> List[str]:
    """
    Get the list of agents that still need to be executed for the current phase for the given chat uuid for this
    context. This is used by a phased coordinator.

    Args:
        chat_uuid (str): the chat uuid

    Returns:
        List[str]: the list of agent names that still need to be executed for the current phase or an empty list
        if there are no remaining agents that need to be executed for the current phase
    """
    if chat_uuid in self._required_agents_for_current_phase:
        return self._required_agents_for_current_phase.get(chat_uuid)
    return []

get_required_tool_calls(chat_uuid)

Get required tool calls from the context.

Parameters:
  • chat_uuid (str) –

    the chat uuid

Source code in wiseagents/wise_agent.py
406
407
408
409
410
411
412
413
414
415
def get_required_tool_calls(self, chat_uuid: str) -> List[str]:
    '''Get required tool calls from the context.

    Args:
        chat_uuid (str): the chat uuid
        return List[str]'''
    if chat_uuid in self._llm_required_tool_call:
        return self._llm_required_tool_call[chat_uuid]
    else:
        return []   

get_route_response_to(chat_uuid)

Get the name of the agent where the final response should be routed to for the given chat uuid for this context. This is used by a sequential coordinator and a phased coordinator.

Returns:
  • Optional[str]

    Optional[str]: the name of the agent where the final response should be routed to or None if no agent is set

Source code in wiseagents/wise_agent.py
471
472
473
474
475
476
477
478
479
480
481
482
def get_route_response_to(self, chat_uuid: str) -> Optional[str]:
    """
    Get the name of the agent where the final response should be routed to for the given chat uuid for this
    context. This is used by a sequential coordinator and a phased coordinator.

    Returns:
        Optional[str]: the name of the agent where the final response should be routed to or None if no agent is set
    """
    if chat_uuid in self._route_response_to:
        return self._route_response_to[chat_uuid]
    else:
        return None

remove_required_agent_for_current_phase(chat_uuid, agent_name)

Remove the given agent from the list of required agents for the current phase for the given chat uuid for this context. This is used by a phased coordinator.

Parameters:
  • chat_uuid (str) –

    the chat uuid

  • agent_name (str) –

    the name of the agent to remove

Source code in wiseagents/wise_agent.py
605
606
607
608
609
610
611
612
613
614
615
def remove_required_agent_for_current_phase(self, chat_uuid: str, agent_name: str):
    """
    Remove the given agent from the list of required agents for the current phase for the given chat uuid for this
    context. This is used by a phased coordinator.

    Args:
        chat_uuid (str): the chat uuid
        agent_name (str): the name of the agent to remove
    """
    if chat_uuid in self._required_agents_for_current_phase:
        self._required_agents_for_current_phase.get(chat_uuid).remove(agent_name)

remove_required_tool_call(chat_uuid, tool_name)

Remove required tool call from the context.

Parameters:
  • chat_uuid (str) –

    the chat uuid

  • tool_name (str) –

    the tool name to remove

Source code in wiseagents/wise_agent.py
395
396
397
398
399
400
401
402
403
404
def remove_required_tool_call(self, chat_uuid: str, tool_name: str):
    '''Remove required tool call from the context.

    Args:
        chat_uuid (str): the chat uuid
        tool_name (str): the tool name to remove'''
    if chat_uuid in self._llm_required_tool_call:
        self._llm_required_tool_call[chat_uuid].remove(tool_name)
        if len(self._llm_required_tool_call[chat_uuid]) == 0:
            self._llm_required_tool_call.pop(chat_uuid)

set_agent_phase_assignments(chat_uuid, agent_phase_assignments)

Set the agents to be executed in each phase for the given chat uuid for this context. This is used by a phased coordinator.

Parameters:
  • chat_uuid (str) –

    the chat uuid

  • agent_phase_assignments (List[List[str]]) –

    The agents to be executed in each phase, represented as a

Source code in wiseagents/wise_agent.py
534
535
536
537
538
539
540
541
542
543
544
545
def set_agent_phase_assignments(self, chat_uuid: str, agent_phase_assignments: List[List[str]]):
    """
    Set the agents to be executed in each phase for the given chat uuid for this context. This is used
    by a phased coordinator.

    Args:
        chat_uuid (str): the chat uuid
        agent_phase_assignments (List[List[str]]): The agents to be executed in each phase, represented as a
        list of lists, where the size of the outer list corresponds to the number of phases and each element
        in the list is a list of agent names for that phase.
    """
    self._agent_phase_assignments[chat_uuid] = agent_phase_assignments

set_agents_sequence(chat_uuid, agents_sequence)

Set the sequence of agents for the given chat uuid for this context. This is used by a sequential coordinator to execute its agents in a specific order, passing the output from one agent in the sequence to the next agent in the sequence.

Parameters:
  • chat_uuid (str) –

    the chat uuid

  • agents_sequence (List[str]) –

    the sequence of agent names

Source code in wiseagents/wise_agent.py
459
460
461
462
463
464
465
466
467
468
469
def set_agents_sequence(self, chat_uuid: str, agents_sequence: List[str]):
    """
    Set the sequence of agents for the given chat uuid for this context. This is used by
    a sequential coordinator to execute its agents in a specific order, passing the output
    from one agent in the sequence to the next agent in the sequence.

    Args:
        chat_uuid (str): the chat uuid
        agents_sequence (List[str]): the sequence of agent names
    """
    self._agents_sequence[chat_uuid] = agents_sequence

set_current_phase(chat_uuid, phase)

Set the current phase for the given chat uuid for this context. This method also sets the required agents for the current phase. This is used by a phased coordinator.

Parameters:
  • chat_uuid (str) –

    the chat uuid

  • phase (int) –

    the current phase, represented as an integer in the zero-indexed list of phases

Source code in wiseagents/wise_agent.py
559
560
561
562
563
564
565
566
567
568
569
def set_current_phase(self, chat_uuid: str, phase: int):
    """
    Set the current phase for the given chat uuid for this context. This method also
    sets the required agents for the current phase. This is used by a phased coordinator.

    Args:
        chat_uuid (str): the chat uuid
        phase (int): the current phase, represented as an integer in the zero-indexed list of phases
    """
    self._current_phase[chat_uuid] = phase
    self._required_agents_for_current_phase[chat_uuid] = copy.deepcopy(self._agent_phase_assignments[chat_uuid][phase])

set_route_response_to(chat_uuid, agent)

Set the name of the agent where the final response should be routed to for the given chat uuid for this context. This is used by a sequential coordinator and a phased coordinator.

Parameters:
  • chat_uuid (str) –

    the chat uuid

  • agent (str) –

    the name of the agent where the final response should be routed to

Source code in wiseagents/wise_agent.py
484
485
486
487
488
489
490
491
492
493
def set_route_response_to(self, chat_uuid: str, agent: str):
    """
    Set the name of the agent where the final response should be routed to for the given chat uuid for this
    context. This is used by a sequential coordinator and a phased coordinator.

    Args:
        chat_uuid (str): the chat uuid
        agent (str): the name of the agent where the final response should be routed to
    """
    self._route_response_to[chat_uuid] = agent

WiseAgentRegistry

A Registry to get available agents and running contexts

Source code in wiseagents/wise_agent.py
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
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
class WiseAgentRegistry:

    """
    A Registry to get available agents and running contexts
    """
    agents : dict[str, WiseAgent] = {}
    contexts : dict[str, WiseAgentContext] = {}
    tools: dict[str, WiseAgentTool] = {}

    @classmethod
    def register_agent(cls,agent : WiseAgent):
        """
        Register an agent with the registry
        """
        cls.agents[agent.name] = agent
    @classmethod    
    def register_context(cls, context : WiseAgentContext):
        """
        Register a context with the registry
        """
        cls.contexts[context.name] = context
    @classmethod    
    def get_agents(cls) -> dict [str, WiseAgent]:
        """
        Get the list of agents
        """
        return cls.agents

    @classmethod
    def get_contexts(cls) -> dict [str, WiseAgentContext]:
        """
        Get the list of contexts
        """
        return cls.contexts

    @classmethod
    def get_agent(cls, agent_name: str) -> WiseAgent:
        """
        Get the agent with the given name
        """
        return cls.agents.get(agent_name) 

    @classmethod
    def get_or_create_context(cls, context_name: str) -> WiseAgentContext:
        """ Get the context with the given name """
        context = cls.contexts.get(context_name)
        if context is None:
            return WiseAgentContext(context_name)
        else:
            return context

    @classmethod
    def does_context_exist(cls, context_name: str) -> bool:
        """
        Get the context with the given name
        """
        if  cls.contexts.get(context_name) is None:
            return False
        else:
            return True

    @classmethod
    def remove_agent(cls, agent_name: str):
        """
        Remove the agent from the registry
        """
        cls.agents.pop(agent_name)

    @classmethod
    def remove_context(cls, context_name: str):
        """
        Remove the context from the registry
        """
        cls.contexts.pop(context_name)

    @classmethod
    def clear_agents(cls):
        """
        Clear all agents from the registry
        """
        cls.agents.clear()

    @classmethod
    def clear_contexts(cls):
        """
        Clear all contexts from the registry
        """
        cls.contexts.clear()

    @classmethod
    def register_tool(cls, tool : WiseAgentTool):
        """
        Register a tool with the registry
        """
        cls.tools[tool.name] = tool

    @classmethod
    def get_tools(cls) -> dict[str, WiseAgentTool]:
        """
        Get the list of tools
        """
        return cls.tools

    @classmethod
    def get_tool(cls, tool_name: str) -> WiseAgentTool:
        """
        Get the tool with the given name
        """
        return cls.tools.get(tool_name)

    @classmethod
    def get_agent_names_and_descriptions(cls) -> List[str]:
        """
        Get the list of agent names and descriptions.

        Returns:
            List[str]: the list of agent descriptions
        """
        agent_descriptions = []
        for agent_name, agent in cls.agents.items():
            agent_descriptions.append("Agent Name: " + agent_name + " Agent Description: " + agent.description)

        return agent_descriptions

clear_agents() classmethod

Clear all agents from the registry

Source code in wiseagents/wise_agent.py
734
735
736
737
738
739
@classmethod
def clear_agents(cls):
    """
    Clear all agents from the registry
    """
    cls.agents.clear()

clear_contexts() classmethod

Clear all contexts from the registry

Source code in wiseagents/wise_agent.py
741
742
743
744
745
746
@classmethod
def clear_contexts(cls):
    """
    Clear all contexts from the registry
    """
    cls.contexts.clear()

does_context_exist(context_name) classmethod

Get the context with the given name

Source code in wiseagents/wise_agent.py
710
711
712
713
714
715
716
717
718
@classmethod
def does_context_exist(cls, context_name: str) -> bool:
    """
    Get the context with the given name
    """
    if  cls.contexts.get(context_name) is None:
        return False
    else:
        return True

get_agent(agent_name) classmethod

Get the agent with the given name

Source code in wiseagents/wise_agent.py
694
695
696
697
698
699
@classmethod
def get_agent(cls, agent_name: str) -> WiseAgent:
    """
    Get the agent with the given name
    """
    return cls.agents.get(agent_name) 

get_agent_names_and_descriptions() classmethod

Get the list of agent names and descriptions.

Returns:
  • List[str]

    List[str]: the list of agent descriptions

Source code in wiseagents/wise_agent.py
769
770
771
772
773
774
775
776
777
778
779
780
781
@classmethod
def get_agent_names_and_descriptions(cls) -> List[str]:
    """
    Get the list of agent names and descriptions.

    Returns:
        List[str]: the list of agent descriptions
    """
    agent_descriptions = []
    for agent_name, agent in cls.agents.items():
        agent_descriptions.append("Agent Name: " + agent_name + " Agent Description: " + agent.description)

    return agent_descriptions

get_agents() classmethod

Get the list of agents

Source code in wiseagents/wise_agent.py
680
681
682
683
684
685
@classmethod    
def get_agents(cls) -> dict [str, WiseAgent]:
    """
    Get the list of agents
    """
    return cls.agents

get_contexts() classmethod

Get the list of contexts

Source code in wiseagents/wise_agent.py
687
688
689
690
691
692
@classmethod
def get_contexts(cls) -> dict [str, WiseAgentContext]:
    """
    Get the list of contexts
    """
    return cls.contexts

get_or_create_context(context_name) classmethod

Get the context with the given name

Source code in wiseagents/wise_agent.py
701
702
703
704
705
706
707
708
@classmethod
def get_or_create_context(cls, context_name: str) -> WiseAgentContext:
    """ Get the context with the given name """
    context = cls.contexts.get(context_name)
    if context is None:
        return WiseAgentContext(context_name)
    else:
        return context

get_tool(tool_name) classmethod

Get the tool with the given name

Source code in wiseagents/wise_agent.py
762
763
764
765
766
767
@classmethod
def get_tool(cls, tool_name: str) -> WiseAgentTool:
    """
    Get the tool with the given name
    """
    return cls.tools.get(tool_name)

get_tools() classmethod

Get the list of tools

Source code in wiseagents/wise_agent.py
755
756
757
758
759
760
@classmethod
def get_tools(cls) -> dict[str, WiseAgentTool]:
    """
    Get the list of tools
    """
    return cls.tools

register_agent(agent) classmethod

Register an agent with the registry

Source code in wiseagents/wise_agent.py
668
669
670
671
672
673
@classmethod
def register_agent(cls,agent : WiseAgent):
    """
    Register an agent with the registry
    """
    cls.agents[agent.name] = agent

register_context(context) classmethod

Register a context with the registry

Source code in wiseagents/wise_agent.py
674
675
676
677
678
679
@classmethod    
def register_context(cls, context : WiseAgentContext):
    """
    Register a context with the registry
    """
    cls.contexts[context.name] = context

register_tool(tool) classmethod

Register a tool with the registry

Source code in wiseagents/wise_agent.py
748
749
750
751
752
753
@classmethod
def register_tool(cls, tool : WiseAgentTool):
    """
    Register a tool with the registry
    """
    cls.tools[tool.name] = tool

remove_agent(agent_name) classmethod

Remove the agent from the registry

Source code in wiseagents/wise_agent.py
720
721
722
723
724
725
@classmethod
def remove_agent(cls, agent_name: str):
    """
    Remove the agent from the registry
    """
    cls.agents.pop(agent_name)

remove_context(context_name) classmethod

Remove the context from the registry

Source code in wiseagents/wise_agent.py
727
728
729
730
731
732
@classmethod
def remove_context(cls, context_name: str):
    """
    Remove the context from the registry
    """
    cls.contexts.pop(context_name)

WiseAgentTool

Bases: YAMLObject

A WiseAgentTool is an abstract class that represents a tool that can be used by an agent to perform a specific task.

Source code in wiseagents/wise_agent.py
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
class WiseAgentTool(yaml.YAMLObject):
    ''' A WiseAgentTool is an abstract class that represents a tool that can be used by an agent to perform a specific task.'''
    yaml_tag = u'!wiseagents.WiseAgentTool'
    def __init__(self, name: str, description: str, agent_tool: bool, parameters_json_schema: dict = {}, 
                 call_back : Optional[Callable[...,str]] = None):
       ''' Initialize the tool with the given name, description, agent tool, parameters json schema, and call back.

       Args:
           name (str): the name of the tool
           description (str): a description of what the tool does
           agent_tool (bool): whether the tool is an agent tool
           parameters_json_schema (dict): the json schema for the parameters of the tool
           call_back Optional(Callable[...,str]): the callback function to execute the tool'''     
       self._name = name
       self._description = description
       self._parameters_json_schema = parameters_json_schema
       self._agent_tool = agent_tool
       self._call_back = call_back
       WiseAgentRegistry.register_tool(self)

    @classmethod
    def from_yaml(cls, loader, node):
        '''Load the tool from a YAML node.

        Args:
            loader (yaml.Loader): the YAML loader
            node (yaml.Node): the YAML node'''
        data = loader.construct_mapping(node, deep=True)
        return cls(name=data.get('_name'), description=data.get('_description'), 
                   parameters_json_schema=data.get('_parameters_json_schema'),
                   call_back=data.get('_call_back'))

    @property
    def name(self) -> str:
        """Get the name of the tool."""
        return self._name

    @property
    def description(self) -> str:
        """Get the description of the tool."""
        return self._description

    @property
    def call_back(self) -> Callable[...,str]:
        """Get the callback function of the tool."""
        return self._call_back
    @property
    def json_schema(self) -> dict:
        """Get the json schema of the tool."""
        return self._parameters_json_schema

    @property
    def is_agent_tool(self) -> bool:
        """Get the agent tool of the tool."""
        return self._agent_tool

    def get_tool_OpenAI_format(self) -> ChatCompletionToolParam:
        '''The tool should be able to return itself in the form of a ChatCompletionToolParam

        Returns:
            ChatCompletionToolParam'''
        return {"type": "function",
                "function": {
                "name": self.name,
                "description": self.description,
                "parameters": self.json_schema
                } 
        }

    def default_call_back(self, **kwargs) -> str:
        '''The tool should be able to execute the function with the given parameters'''
        return json.dumps(kwargs)

    def exec(self, **kwargs) -> str:
        '''The tool should be able to execute the function with the given parameters'''
        if self.call_back is None:
            return self.default_call_back(**kwargs)
        return self.call_back(**kwargs)

call_back: Callable[..., str] property

Get the callback function of the tool.

description: str property

Get the description of the tool.

is_agent_tool: bool property

Get the agent tool of the tool.

json_schema: dict property

Get the json schema of the tool.

name: str property

Get the name of the tool.

__init__(name, description, agent_tool, parameters_json_schema={}, call_back=None)

Initialize the tool with the given name, description, agent tool, parameters json schema, and call back.

Parameters:
  • name (str) –

    the name of the tool

  • description (str) –

    a description of what the tool does

  • agent_tool (bool) –

    whether the tool is an agent tool

  • parameters_json_schema (dict, default: {} ) –

    the json schema for the parameters of the tool

  • call_back (Optional(Callable[...,str], default: None ) –

    the callback function to execute the tool

Source code in wiseagents/wise_agent.py
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
def __init__(self, name: str, description: str, agent_tool: bool, parameters_json_schema: dict = {}, 
             call_back : Optional[Callable[...,str]] = None):
   ''' Initialize the tool with the given name, description, agent tool, parameters json schema, and call back.

   Args:
       name (str): the name of the tool
       description (str): a description of what the tool does
       agent_tool (bool): whether the tool is an agent tool
       parameters_json_schema (dict): the json schema for the parameters of the tool
       call_back Optional(Callable[...,str]): the callback function to execute the tool'''     
   self._name = name
   self._description = description
   self._parameters_json_schema = parameters_json_schema
   self._agent_tool = agent_tool
   self._call_back = call_back
   WiseAgentRegistry.register_tool(self)

default_call_back(**kwargs)

The tool should be able to execute the function with the given parameters

Source code in wiseagents/wise_agent.py
280
281
282
def default_call_back(self, **kwargs) -> str:
    '''The tool should be able to execute the function with the given parameters'''
    return json.dumps(kwargs)

exec(**kwargs)

The tool should be able to execute the function with the given parameters

Source code in wiseagents/wise_agent.py
284
285
286
287
288
def exec(self, **kwargs) -> str:
    '''The tool should be able to execute the function with the given parameters'''
    if self.call_back is None:
        return self.default_call_back(**kwargs)
    return self.call_back(**kwargs)

from_yaml(loader, node) classmethod

Load the tool from a YAML node.

Parameters:
  • loader (Loader) –

    the YAML loader

  • node (Node) –

    the YAML node

Source code in wiseagents/wise_agent.py
231
232
233
234
235
236
237
238
239
240
241
@classmethod
def from_yaml(cls, loader, node):
    '''Load the tool from a YAML node.

    Args:
        loader (yaml.Loader): the YAML loader
        node (yaml.Node): the YAML node'''
    data = loader.construct_mapping(node, deep=True)
    return cls(name=data.get('_name'), description=data.get('_description'), 
               parameters_json_schema=data.get('_parameters_json_schema'),
               call_back=data.get('_call_back'))

get_tool_OpenAI_format()

The tool should be able to return itself in the form of a ChatCompletionToolParam

Returns:
  • ChatCompletionToolParam

    ChatCompletionToolParam

Source code in wiseagents/wise_agent.py
267
268
269
270
271
272
273
274
275
276
277
278
def get_tool_OpenAI_format(self) -> ChatCompletionToolParam:
    '''The tool should be able to return itself in the form of a ChatCompletionToolParam

    Returns:
        ChatCompletionToolParam'''
    return {"type": "function",
            "function": {
            "name": self.name,
            "description": self.description,
            "parameters": self.json_schema
            } 
    }