Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions camel/agents/chat_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4468,17 +4468,6 @@ def _clone_tools(
# Toolkit doesn't support cloning, use original
cloned_toolkits[toolkit_id] = toolkit_instance

if getattr(
tool.func, "__message_integration_enhanced__", False
):
cloned_tools.append(
FunctionTool(
func=tool.func,
openai_tool_schema=tool.get_openai_tool_schema(),
)
)
continue

# Get the method from the cloned (or original) toolkit
toolkit = cloned_toolkits[toolkit_id]
method_name = tool.func.__name__
Expand Down
28 changes: 26 additions & 2 deletions camel/toolkits/message_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,26 @@ def register_functions(

# Check if this function should be enhanced
if function_names is None or func.__name__ in function_names:
enhanced_func = self._add_messaging_to_tool(func)
enhanced_tools.append(FunctionTool(enhanced_func))
# If func is a bound toolkit method, route to register_toolkits
if hasattr(func, '__self__') and isinstance(
func.__self__, BaseToolkit
):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems we didn't consider the case that the toolkit already been enhanced

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

toolkit_instance = func.__self__
method_name = func.__name__

# Enhance the specific method on the toolkit instance
enhanced_toolkit = self.register_toolkits(
toolkit_instance, tool_names=[method_name]
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will lead to the whole toolkit be registered

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Wendong-Fan after our discussion,i re-check the code,finding i just pass in tool_names=[method_name] when use register_toolkits,so the whole toolkit will not be registered, only one function
image
so i think the current way is ok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.register_toolkits would register the whole toolkit, i will fix this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean it should be?


# Fetch the enhanced method back
enhanced_method = getattr(enhanced_toolkit, method_name)

enhanced_tools.append(FunctionTool(enhanced_method))
else:
# Standalone function: add messaging wrapper directly
enhanced_func = self._add_messaging_to_tool(func)
enhanced_tools.append(FunctionTool(enhanced_func))
else:
# Return as FunctionTool regardless of input type
if isinstance(item, FunctionTool):
Expand All @@ -300,6 +318,12 @@ def _add_messaging_to_tool(self, func: Callable) -> Callable:
This internal method modifies the function signature and docstring
to include optional messaging parameters that trigger status updates.
"""
if getattr(func, "__message_integration_enhanced__", False):
logger.debug(
f"Function {func.__name__} already enhanced, skipping"
)
return func

# Get the original signature
original_sig = inspect.signature(func)

Expand Down