-
Notifications
You must be signed in to change notification settings - Fork 690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: ChatAgent
refactoring
#1142
base: master
Are you sure you want to change the base?
Conversation
ChatAgent
refactoringChatAgent
refactoring (Draft)
ChatAgent
refactoring (Draft)ChatAgent
refactoring
@@ -172,6 +176,8 @@ def __init__( | |||
self.role_type: RoleType = ( | |||
getattr(system_message, 'role_type', None) or RoleType.ASSISTANT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Assistant' or 'assistant' all of them is ok?
def add_tool( | ||
self, tool: Union[FunctionTool, Callable], is_external: bool = False | ||
) -> None: | ||
r"""Add a tool to the agent, specifying if it's an external tool.""" | ||
initialized_tool = self._initialize_tools([tool]) | ||
|
||
if is_external: | ||
self.external_tools = ( | ||
self.external_tools or [] | ||
) + initialized_tool | ||
self.external_tool_names.extend( | ||
tool.get_function_name() for tool in initialized_tool | ||
) | ||
else: | ||
self.tools = (self.tools or []) + initialized_tool | ||
|
||
# Reinitialize func_dict to include all tools | ||
self.all_tools = (self.tools or []) + (self.external_tools or []) | ||
self.func_dict = { | ||
tool.get_function_name(): tool.func for tool in self.all_tools | ||
} | ||
self.tool_dict = { | ||
tool.get_function_name(): tool for tool in self.all_tools | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def add_tool(
self, tool: Union[FunctionTool, Callable], is_external: bool = False
) -> None:
"""
Add a tool to the agent, specifying if it's an external tool.
Args:
tool: The tool to be added, either a FunctionTool instance or a callable.
is_external: Flag indicating if the tool is external.
"""
# Initialize the tool
initialized_tool = self._initialize_tools([tool])
# Helper function to merge tools
def merge_tools(existing_tools: List, new_tools: List) -> List:
return (existing_tools or []) + new_tools
# Update tools or external tools based on is_external flag
if is_external:
self.external_tools = merge_tools(self.external_tools, initialized_tool)
self.external_tool_names.extend(
tool.get_function_name() for tool in initialized_tool
)
else:
self.tools = merge_tools(self.tools, initialized_tool)
# Rebuild all_tools, func_dict, and tool_dict
self.all_tools = merge_tools(self.tools, self.external_tools)
self.func_dict = {tool.get_function_name(): tool.func for tool in self.all_tools}
self.tool_dict = {tool.get_function_name(): tool for tool in self.all_tools}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code is ok, but it's not easy to read
Description
Refactor
ChatAgent
step
method to make it more modularMotivation and Context
Types of changes
What types of changes does your code introduce? Put an
x
in all the boxes that apply:Implemented Tasks
Checklist
Go over all the following points, and put an
x
in all the boxes that apply.If you are unsure about any of these, don't hesitate to ask. We are here to help!