Camel多智能体框架初探

Camel介绍

CAMEL 是一个开源社区,致力于探索代理的扩展规律。我们相信,在大规模研究这些代理可以提供对其行为、能力和潜在风险的宝贵见解。为了促进该领域的研究,我们实现了并支持各种类型的代理、任务、提示、模型和模拟环境。

CAMEL :找到智能体的扩展规律。第一个也是最好的多智能体框架。

CAMEL 框架设计原则

可演化性

该框架通过生成数据并与环境交互,使多智能体系统能够持续进化。这种进化可以由可验证奖励驱动的强化学习或监督学习驱动。

规模性

该框架旨在支持百万级代理的系统,确保在大规模情况下实现高效的协调、通信和资源管理。

有状态性

代理保持状态记忆,使它们能够进行多步与环境的交互,并高效地应对复杂的任务。

代码即提示

每一行代码和注释都作为代理的提示。代码应编写得清晰易读,确保人类和代理都能有效解读。

GitHub地址:github.com/camel-ai/ca...

Camel初探

我使用从源代码中使用 uv 这种方式进行安装。

bash 复制代码
git clone https://github.com/camel-ai/camel.git
bash 复制代码
cd camel

如果没安装uv需要安装。

复制代码
pip install uv

创建一个虚拟环境。

ini 复制代码
uv venv .venv --python=3.10

激活虚拟环境。

复制代码
.venv\Scripts\activate

安装CAMEL及其依赖。

arduino 复制代码
uv pip install -e ".[all, dev, docs]"

开发者可以安装pre-commit hooks 与 mypy。

sql 复制代码
uv pip install pre-commit mypy
sql 复制代码
pre-commit install

现在先随便跑个例子看看。

我想要使用硅基流动的模型,就可以在.env文件中这样写:

ini 复制代码
Silicon_Model_ID="Qwen/Qwen2.5-72B-Instruct"
SiliconCloud_API_KEY="你的api_key"
SiliconCloud_Base_URL="https://api.siliconflow.cn/v1"

我跑的例子是这个:camel\examples\ai_society\role_playing_multi_lingual.py

将代码修改为如下的形式即可:

ini 复制代码
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
from colorama import Fore
​
from camel.societies import RolePlaying
from camel.utils import print_text_animated
​
​
def main(model=None) -> None:
    task_prompt = "Develop a trading bot for the stock market"
    role_play_session = RolePlaying(
        assistant_role_name="Python Programmer",
        assistant_agent_kwargs=dict(model=model),
        user_role_name="Stock Trader",
        user_agent_kwargs=dict(model=model),
        task_prompt=task_prompt,
        with_task_specify=True,
        task_specify_agent_kwargs=dict(model=model),
        output_language="Chinese",  # Arabic, French, Spanish, ...
    )
​
    print(
        Fore.GREEN
        + f"AI Assistant sys message:\n{role_play_session.assistant_sys_msg}\n"
    )
    print(
        Fore.BLUE + f"AI User sys message:\n{role_play_session.user_sys_msg}\n"
    )
​
    print(Fore.YELLOW + f"Original task prompt:\n{task_prompt}\n")
    print(
        Fore.CYAN
        + "Specified task prompt:"
        + f"\n{role_play_session.specified_task_prompt}\n"
    )
    print(Fore.RED + f"Final task prompt:\n{role_play_session.task_prompt}\n")
​
    chat_turn_limit, n = 50, 0
    input_msg = role_play_session.init_chat()
    while n < chat_turn_limit:
        n += 1
        assistant_response, user_response = role_play_session.step(input_msg)
​
        if assistant_response.terminated:
            print(
                Fore.GREEN
                + (
                    "AI Assistant terminated. Reason: "
                    f"{assistant_response.info['termination_reasons']}."
                )
            )
            break
        if user_response.terminated:
            print(
                Fore.GREEN
                + (
                    "AI User terminated. "
                    f"Reason: {user_response.info['termination_reasons']}."
                )
            )
            break
​
        print_text_animated(
            Fore.BLUE + f"AI User:\n\n{user_response.msg.content}\n"
        )
        print_text_animated(
            Fore.GREEN + "AI Assistant:\n\n"
            f"{assistant_response.msg.content}\n"
        )
​
        if "CAMEL_TASK_DONE" in user_response.msg.content:
            break
​
        input_msg = assistant_response.msg
​
​
if __name__ == "__main__":
    from camel.models import ModelFactory
    from camel.types import ModelPlatformType, ModelType
    import pathlib
    import os
    from dotenv import load_dotenv
​
    base_dir = pathlib.Path(__file__).parent.parent.parent
    env_path = base_dir / ".env"
    load_dotenv(dotenv_path=str(env_path))
​
    modeltype = os.getenv("Silicon_Model_ID")
    api_key = os.getenv("SiliconCloud_API_KEY")
    base_url = os.getenv("SiliconCloud_Base_URL")
    siliconcloud_model = ModelFactory.create(
        model_platform=ModelPlatformType.OPENAI_COMPATIBLE_MODEL,
                model_type=modeltype,
                api_key=api_key,
                url=base_url,
                model_config_dict={"temperature": 0.4, "max_tokens": 4096},
    )
    main(siliconcloud_model)

运行效果:

算是把环境搭建好了。

现在就可以开始学习Camel这个多智能体框架了。

相关推荐
大博士.J2 小时前
MySQL实现全量同步和增量同步到SQL Server或其他关系型库
数据仓库·人工智能·python·mysql·adb
说私域3 小时前
技术革命、需求升级与商业生态迭代——基于开源AI大模型与智能商业范式的创新研究
人工智能·微信·小程序·开源·零售
Lichenpar3 小时前
AI小白的第七天:必要的数学知识(四)
人工智能·概率论·概率分布
訾博ZiBo3 小时前
AI日报 - 2025年3月21日
人工智能
LitchiCheng5 小时前
DQN 玩 2048 实战|第二期!设计 ε 贪心策略神经网络,简单训练一下吧!
人工智能·深度学习·神经网络
tortorish5 小时前
PyTorch中Batch Normalization1d的实现与手动验证
人工智能·pytorch·batch
wwwzhouhui5 小时前
dify案例分享-儿童故事绘本语音播报视频工作流
人工智能·音视频·语音识别
南太湖小蚂蚁5 小时前
自然语言处理入门4——RNN
人工智能·rnn·深度学习·自然语言处理
Ronin-Lotus5 小时前
深度学习篇---分类任务图像预处理&模型训练
人工智能·python·深度学习·机器学习·分类·模型训练·分类任务
四口鲸鱼爱吃盐6 小时前
CVPR2025 | TAPT:用于视觉语言模型鲁棒推理的测试时对抗提示调整
网络·人工智能·深度学习·机器学习·语言模型·自然语言处理·对抗样本