camel-ai / camel

šŸ« CAMEL: Finding the Scaling Law of Agents. The first and the best multi-agent framework. https://www.camel-ai.org
https://docs.camel-ai.org/
Apache License 2.0
5.58k stars 678 forks source link

[Feature Request] Toolkits Refactoring #940

Open WHALEEYE opened 1 month ago

WHALEEYE commented 1 month ago

Required prerequisites

Motivation

The current style of toolkits is quite chaotic, we need to make it more standardized to ensure the code quality and also for the ease of adding future tools.

Solution

No response

Alternatives

No response

Additional context

No response

lightaime commented 1 month ago

Part of the refactoring:

ZackYule commented 3 weeks ago

I have a couple of detail questions regarding the Toolkits refactoring that might be worth consideringļ¼š

Q1: Would it make sense to replace BaseToolkit classes that donā€™t require any configuration with functional tools instead? This way, we could avoid exposing classes without actual tool methods in the ToolManager, streamlining the structure.

Q2: I think it might be better if the tool list returned by ToolManager is List[str] when intended for user interaction, and list[OpenAIFunction] when used by the agent. Since list_toolkits is primarily for users, it seems reasonable for it to return List[str]. As for search_toolkits, should it be designed for user use or for the agent?

ZackYule commented 3 weeks ago

Below are the current ways we use tools, and I believe it would be helpful to consider unifying these approaches while also supporting developers in customizing their own tools.

Thereā€™s also one more point to consider: the OpenAPIToolkit doesnā€™t currently support the management approach used by toolkits_manager.

Perhaps it would be a good idea to revisit and discuss these details again. @lightaime @yiyiyi0817 @zhiyu-01

1. Without toolkit_manager

No configuration needed

tools_list = [
  *SEARCH_FUNCS,
  *MathToolkit().get_tools(),
]

Configuration needed

toolkit = GithubToolkit(repo_name=repo_name)

tools_list = [
  *SEARCH_FUNCS,
  *WEATHER_FUNCS,
  *toolkit.get_tools(),
]

2. With toolkits_manager

No configuration needed

tools_list = manager.get_toolkits(names=manager.search_toolkits('weather'))

Configuration needed

camel_github_toolkit = GithubToolkit(repo_name='camel-ai/camel')

tools_list = manager.register_tool([camel_github_toolkit, ])

Custom tools

def div(a: int, b: int) -> float:
    r"""Divides two numbers.
    Args:
        a (int): The dividend in the division.
        b (int): The divisor in the division.
    Returns:
        float: The quotient of the division.
    Raises:
        ValueError: If the divisor is zero.
    """
    if b == 0:
        raise ValueError("Division by zero is not allowed.")
    return a / b

tools_list = manager.register_tool([div, ])