WiseAgentLLM

Bases: WiseAgentsYAMLObject

Abstract class to define the interface for a WiseAgentLLM.

Source code in wiseagents/llm/wise_agent_LLM.py
11
12
13
14
15
16
17
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
class WiseAgentLLM(WiseAgentsYAMLObject):
    """Abstract class to define the interface for a WiseAgentLLM."""
    def __init__(self, model_name, system_message: Optional[str] = None):
        '''Initialize the agent.

        Args:
            model_name (str): the model name
            system_message (Optional[str]): the optional system message
        '''
        super().__init__()
        enforce_no_abstract_class_instances(self.__class__, WiseAgentLLM)
        self._system_message = system_message
        self._model_name = model_name

    def __repr__(self):
        '''Return a string representation of the agent.'''
        return f"{self.__class__.__name__}(system_message={self.system_message}, model_name={self.model_name})"    

    @property  
    def system_message(self) -> Optional[str]:
        '''Get the system message or None if no system message has been defined.'''
        return self._system_message

    @property
    def model_name(self):
        '''Get the model name.'''
        return self._model_name


    def set_agent_name(self, agent_name: str) :
        self._agent_name = agent_name

    @abstractmethod
    def process_single_prompt(self, prompt):
        '''Process a single prompt. This method should be implemented by subclasses.
        The single prompt is processed and the result is returned, all the context and state is maintained locally in the method

        Args:
            prompt (str): the prompt to process'''

        ...

    @abstractmethod
    def process_chat_completion(self, 
                                messages: Iterable[ChatCompletionMessageParam], 
                                tools: Iterable[ChatCompletionToolParam]) -> ChatCompletion:
        '''Process a chat completion. This method should be implemented by subclasses.
        The context and state is passed in input and returned as part of the output.
        Deal with the messages and tools is responsibility of the caller.

        Args:
            messages (Iterable[ChatCompletionMessageParam]): the messages to process
            tools (Iterable[ChatCompletionToolParam]): the tools to use

        Returns:
                ChatCompletion: the chat completion result'''
        ...

model_name property

Get the model name.

system_message: Optional[str] property

Get the system message or None if no system message has been defined.

__init__(model_name, system_message=None)

Initialize the agent.

Parameters:
  • model_name (str) –

    the model name

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

    the optional system message

Source code in wiseagents/llm/wise_agent_LLM.py
13
14
15
16
17
18
19
20
21
22
23
def __init__(self, model_name, system_message: Optional[str] = None):
    '''Initialize the agent.

    Args:
        model_name (str): the model name
        system_message (Optional[str]): the optional system message
    '''
    super().__init__()
    enforce_no_abstract_class_instances(self.__class__, WiseAgentLLM)
    self._system_message = system_message
    self._model_name = model_name

__repr__()

Return a string representation of the agent.

Source code in wiseagents/llm/wise_agent_LLM.py
25
26
27
def __repr__(self):
    '''Return a string representation of the agent.'''
    return f"{self.__class__.__name__}(system_message={self.system_message}, model_name={self.model_name})"    

process_chat_completion(messages, tools) abstractmethod

Process a chat completion. This method should be implemented by subclasses. The context and state is passed in input and returned as part of the output. Deal with the messages and tools is responsibility of the caller.

Parameters:
  • messages (Iterable[ChatCompletionMessageParam]) –

    the messages to process

  • tools (Iterable[ChatCompletionToolParam]) –

    the tools to use

Returns:
  • ChatCompletion( ChatCompletion ) –

    the chat completion result

Source code in wiseagents/llm/wise_agent_LLM.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
@abstractmethod
def process_chat_completion(self, 
                            messages: Iterable[ChatCompletionMessageParam], 
                            tools: Iterable[ChatCompletionToolParam]) -> ChatCompletion:
    '''Process a chat completion. This method should be implemented by subclasses.
    The context and state is passed in input and returned as part of the output.
    Deal with the messages and tools is responsibility of the caller.

    Args:
        messages (Iterable[ChatCompletionMessageParam]): the messages to process
        tools (Iterable[ChatCompletionToolParam]): the tools to use

    Returns:
            ChatCompletion: the chat completion result'''
    ...

process_single_prompt(prompt) abstractmethod

Process a single prompt. This method should be implemented by subclasses. The single prompt is processed and the result is returned, all the context and state is maintained locally in the method

Parameters:
  • prompt (str) –

    the prompt to process

Source code in wiseagents/llm/wise_agent_LLM.py
43
44
45
46
47
48
49
50
51
@abstractmethod
def process_single_prompt(self, prompt):
    '''Process a single prompt. This method should be implemented by subclasses.
    The single prompt is processed and the result is returned, all the context and state is maintained locally in the method

    Args:
        prompt (str): the prompt to process'''

    ...