Skip to content

Commit 2ba606f

Browse files
Update nextpy/ai/agent/assistant_agent.py
fix doc string Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 8f2063f commit 2ba606f

File tree

1 file changed

+2
-111
lines changed

1 file changed

+2
-111
lines changed

nextpy/ai/agent/assistant_agent.py

Lines changed: 2 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -32,117 +32,8 @@ async def _a_call_functions(functions):
3232
function(*arguments, **keyword_args)
3333

3434

35-
class AssistantAgent(BaseAgent):
36-
"""
37-
AssistantAgent class represents an assistant agent that interacts with users in a conversational manner.
38-
39-
:param name: The name of the assistant agent.
40-
:type name: str
41-
:param llm: The language model used by the assistant agent.
42-
:type llm: LanguageModel
43-
:param memory: The memory used by the assistant agent.
44-
:type memory: Memory
45-
:param async_mode: Whether the assistant agent should run in asynchronous mode or not. Default is True.
46-
:type async_mode: bool, optional
47-
:param system_message: The system message included in the prompt. Default is None.
48-
:type system_message: str, optional
49-
:param functions_before_call: List of functions to be called before the main function call. Default is None.
50-
:type functions_before_call: List[Callable], optional
51-
:param functions_after_call: List of functions to be called after the main function call. Default is None.
52-
:type functions_after_call: List[Callable], optional
53-
54-
The assistant agent is built on top of the existing BaseAgent and serves as a simple interface for creating an AI assistant agent.
55-
It provides a convenient way to define an AI assistant agent that can interact with users in a conversational manner.
56-
The assistant agent can be customized with a name, language model, memory, and other parameters.
57-
It also supports asynchronous mode, allowing it to handle multiple conversations simultaneously.
58-
59-
MultiagentManager can be used to manage multiple assistant agents and coordinate their interactions with users.
60-
61-
62-
Example:
63-
64-
65-
tailwind_agent = AssistantAgent(name='Tailwind Class Generator', llm=llm, memory=None, async_mode=False,
66-
system_message='''automates the creation of Tailwind CSS classes, streamlining the process of building stylish and responsive user interfaces. By leveraging advanced algorithms and design principles, the Tailwind Class Generator analyzes your design elements and dynamically generates the optimal set of Tailwind utility classes.
67-
This tool is designed to enhance efficiency in web development, allowing developers to focus more on high-level design decisions and less on manually crafting individual CSS rules. With the Tailwind Class Generator, achieving a visually appealing and consistent design becomes a seamless experience.
68-
'''
69-
)
70-
"""
71-
72-
DEFAULT_PROMPT = '''
73-
{{#system~}} {{name}}, you are working in the following team :{{agents}}
74-
{{~/system}}
75-
76-
{{#user~}}
77-
Read the following CONVERSATION :
78-
{{messages}}
79-
Respond as {{name}}. Do not thank any team member or show appreciation."
80-
{{~/user}}
81-
82-
{{#assistant~}}
83-
{{gen 'answer' temperature=0 max_tokens=500}}
84-
{{~/assistant}}
85-
'''
86-
87-
def __init__(self,
88-
name,
89-
llm=None,
90-
memory=None,
91-
async_mode: bool = False,
92-
system_message: str | None = None,
93-
custom_engine=None,
94-
functions_before_call: Tuple[Callable,
95-
Tuple[Any], Tuple[Any]] | None = None,
96-
functions_after_call: Tuple[Callable,
97-
Tuple[Any], Tuple[Any]] | None = None,
98-
description: str = "Helpful AI Assistant Agent",
99-
**kwargs):
100-
"""
101-
Initializes an instance of the AssistantAgent class.
102-
103-
:param name: The name of the assistant agent.
104-
:type name: str
105-
:param llm: The language model used by the assistant agent.
106-
:type llm: LanguageModel
107-
:param memory: The memory used by the assistant agent.
108-
:type memory: Memory
109-
:param async_mode: Whether the assistant agent should run in asynchronous mode or not. Default is True.
110-
:type async_mode: bool, optional
111-
:param system_message: The system message to be displayed to the user. Default is None.
112-
:type system_message: str, optional
113-
:param engine: The engine used by the assistant agent. Either llm or engine must be provided.
114-
:type engine: Engine, optional
115-
:param functions_before_call: List of functions, args and kwargs, to be called before the main function call. Default is None.
116-
:type functions_before_call: List[Callable], optional
117-
:param functions_after_call: List of functions, args and kwargs to be called after the main function call. Default is None.
118-
:type functions_after_call: List[Callable], optional
119-
:param kwargs: Additional keyword arguments.
120-
"""
121-
super().__init__(llm=llm, **kwargs)
122-
self.name = name
123-
self.prompt = self.DEFAULT_PROMPT
124-
self.system_message = system_message
125-
# This is used by multiagent manager to determine whether to use receive or a_receive
126-
self.async_mode = async_mode
127-
128-
if system_message is not None:
129-
try:
130-
system_message = Path(system_message).read_text()
131-
except Exception:
132-
pass
133-
self.prompt = self.prompt[:self.prompt.find(
134-
'{{~/system}}')] + system_message + self.prompt[self.prompt.find('{{~/system}}'):]
135-
136-
# Either llm or engine must be provided
137-
if llm is not None or engine is not None:
138-
logging.debug("Warning! Either llm or engine must be provided.")
139-
140-
self.engine = custom_engine if custom_engine is not None else engine(
141-
template=self.prompt, llm=llm, memory=memory, async_mode=async_mode, **kwargs)
142-
self.output_key = 'answer'
143-
self.functions_before_call = functions_before_call
144-
self.functions_after_call = functions_after_call
145-
self.description = description
35+
:param async_mode: Whether the assistant agent should run in asynchronous mode or not. Default is False.
36+
logging.debug("Warning! At least one of llm or engine must be provided.")
14637

14738
@staticmethod
14839
def function_call_decorator(func):

0 commit comments

Comments
 (0)