diff --git a/.gitattributes b/.gitattributes
index a6344aac8c09253b3b630fb776ae94478aa0275b..218160392c0c005e4547f36aad18a3b62d93d63a 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text
+agentfabric/modelscope_agent/tools/code_interpreter_utils/AlibabaPuHuiTi-3-45-Light.ttf filter=lfs diff=lfs merge=lfs -text
diff --git a/agentfabric/.ipynb_checkpoints/Untitled-checkpoint.ipynb b/agentfabric/.ipynb_checkpoints/Untitled-checkpoint.ipynb
new file mode 100644
index 0000000000000000000000000000000000000000..363fcab7ed6e9634e198cf5555ceb88932c9a245
--- /dev/null
+++ b/agentfabric/.ipynb_checkpoints/Untitled-checkpoint.ipynb
@@ -0,0 +1,6 @@
+{
+ "cells": [],
+ "metadata": {},
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
diff --git a/agentfabric/README.md b/agentfabric/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..bbdb9715379d9709c4dfb23abdd5cba502902514
--- /dev/null
+++ b/agentfabric/README.md
@@ -0,0 +1,64 @@
+---
+# 详细文档见https://modelscope.cn/docs/%E5%88%9B%E7%A9%BA%E9%97%B4%E5%8D%A1%E7%89%87
+domain: #领域:cv/nlp/audio/multi-modal/AutoML
+- multi-modal
+tags: #自定义标签
+ - agent
+ - AgentFabric
+
+## 启动文件(若SDK为Gradio/Streamlit,默认为app.py, 若为Static HTML, 默认为index.html)
+deployspec:
+ entry_file: app.py
+
+license: Apache License 2.0
+---
+
Modelscope AgentFabric: Customizable AI-Agents For All
+
+
+
+
+
+
+
+## Introduction
+**ModelScope AgentFabric** is an interactive framework to facilitate creation of agents tailored to various real-world applications. AgentFabric is built around pluggable and customizable LLMs, and enhance capabilities of instrcution following, extra knowledge retrieval and leveraging external tools. The AgentFabric is woven with interfaces including:
+- ⚡ **Agent Builder**: an automatic instructions and tools provider for customizing user's agents through natural conversational interactions.
+- ⚡ **User Agent**: a customized agent for building real-world applications, with instructions, extra-knowledge and tools provided by builder agent and/or user inputs.
+- ⚡ **Configuration Tooling**: the interface to customize user agent configurations. Allows real-time preview of agent behavior as new confiugrations are updated.
+
+🔗 We currently leverage AgentFabric to build various agents around [Qwen2.0 LLM API](https://help.aliyun.com/zh/dashscope/developer-reference/api-details) available via DashScope. We are also actively exploring
+other options to incorporate (and compare) more LLMs via API, as well as via native ModelScope models.
+
+
+## Installation
+Simply clone the repo and install dependency.
+```bash
+git clone https://github.com/modelscope/modelscope-agent.git
+cd modelscope-agent && pip install -r requirements.txt && pip install -r demo/agentfabric/requirements.txt
+```
+
+## Prerequisites
+
+- Python 3.10
+- Accessibility to LLM API service such as [DashScope](https://help.aliyun.com/zh/dashscope/developer-reference/activate-dashscope-and-create-an-api-key) (free to start).
+
+## Usage
+
+```bash
+export PYTHONPATH=$PYTHONPATH:/path/to/your/modelscope-agent
+export DASHSCOPE_API_KEY=your_api_key
+cd modelscope-agent/demo/agentfabric
+python app.py
+```
+
+## 🚀 Roadmap
+- [x] Allow customizable agent-building via configurations.
+- [x] Agent-building through interactive conversations with LLMs.
+- [x] Support multi-user preview on ModelScope space. [link](https://modelscope.cn/studios/wenmengzhou/AgentFabric/summary) [PR #98](https://github.com/modelscope/modelscope-agent/pull/98)
+- [x] Optimize knowledge retrival. [PR #105](https://github.com/modelscope/modelscope-agent/pull/105) [PR #107](https://github.com/modelscope/modelscope-agent/pull/107) [PR #109](https://github.com/modelscope/modelscope-agent/pull/109)
+- [x] Allow publication and sharing of agent. [PR #111](https://github.com/modelscope/modelscope-agent/pull/111)
+- [ ] Support more pluggable LLMs via API or ModelScope interface.
+- [ ] Improve long context via memory.
+- [ ] Improve logging and profiling.
+- [ ] Fine-tuning for specific agent.
+- [ ] Evaluation for agents in different scenarios.
diff --git a/agentfabric/README_CN.md b/agentfabric/README_CN.md
new file mode 100644
index 0000000000000000000000000000000000000000..547e4d44b25b1ca37d1fb5064ec27a6bc9e923fb
--- /dev/null
+++ b/agentfabric/README_CN.md
@@ -0,0 +1,52 @@
+
+
Modelscope AgentFabric: 开放可定制的AI智能体构建框架
+
+
+
+
+
+
+
+## 介绍
+
+**Modelscope AgentFabric**是一个交互式智能体框架,用于方便地创建针对各种现实应用量身定制智能体。AgentFabric围绕可插拔和可定制的LLM构建,并增强了指令执行、额外知识检索和利用外部工具的能力。AgentFabric提供的交互界面包括:
+- **⚡ 智能体构建器**:一个自动指令和工具提供者,通过与用户聊天来定制用户的智能体
+- **⚡ 用户智能体**:一个为用户的实际应用定制的智能体,提供构建智能体或用户输入的指令、额外知识和工具
+- **⚡ 配置设置工具**:支持用户定制用户智能体的配置,并实时预览用户智能体的性能
+
+🔗 我们目前围绕DashScope提供的 [Qwen2.0 LLM API](https://help.aliyun.com/zh/dashscope/developer-reference/api-details) 来在AgentFabric上构建不同的智能体应用。同时我们正在积极探索,通过API或者ModelScope原生模型等方式,引入不同的举办强大基础能力的LLMs,来构建丰富多样的Agents。
+
+## 安装
+
+克隆仓库并安装依赖:
+
+```bash
+git clone https://github.com/modelscope/modelscope-agent.git
+cd modelscope-agent && pip install -r requirements.txt && pip install -r demo/agentfabric/requirements.txt
+```
+
+## 前提条件
+
+- Python 3.10
+- 获取使用Qwen 2.0模型所需的API-key,可从[DashScope](https://help.aliyun.com/zh/dashscope/developer-reference/activate-dashscope-and-create-an-api-key)免费开通和获取。
+
+## 使用方法
+
+```bash
+export PYTHONPATH=$PYTHONPATH:/path/to/your/modelscope-agent
+export DASHSCOPE_API_KEY=your_api_key
+cd modelscope-agent/demo/agentfabric
+python app.py
+```
+
+## 🚀 发展路线规划
+- [x] 支持人工配置构建智能体
+- [x] 基于LLM对话构建智能体
+- [x] 支持在ModelScope创空间上使用 [link](https://modelscope.cn/studios/wenmengzhou/AgentFabric/summary) [PR #98](https://github.com/modelscope/modelscope-agent/pull/98)
+- [x] 知识库检索效果优化 [PR #105](https://github.com/modelscope/modelscope-agent/pull/105) [PR #107](https://github.com/modelscope/modelscope-agent/pull/107) [PR #109](https://github.com/modelscope/modelscope-agent/pull/109)
+- [x] 支持智能体发布和分享
+- [ ] 支持其他多种LLM模型API和ModelScope模型
+- [ ] 处理长文本输入到内存
+- [ ] 生产级支持:日志和性能分析
+- [ ] 支持智能体微调
+- [ ] 在不同场景中智能体的效果评估
diff --git a/agentfabric/Untitled.ipynb b/agentfabric/Untitled.ipynb
new file mode 100644
index 0000000000000000000000000000000000000000..6e63092bd56947216614a3a755daf72fbc69bae6
--- /dev/null
+++ b/agentfabric/Untitled.ipynb
@@ -0,0 +1,172 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "id": "52e2928d-b216-4d5c-a198-b24b3bc6d5a6",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "/workspace/modelscope-agent/apps/agentfabric\n"
+ ]
+ }
+ ],
+ "source": [
+ "cd agentfabric"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "id": "84bdd7ce-176d-464d-b0b3-620585c22541",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Collecting huggingface_hub\n",
+ " Downloading huggingface_hub-0.19.4-py3-none-any.whl.metadata (14 kB)\n",
+ "Requirement already satisfied: filelock in /opt/conda/lib/python3.10/site-packages (from huggingface_hub) (3.9.0)\n",
+ "Requirement already satisfied: fsspec>=2023.5.0 in /opt/conda/lib/python3.10/site-packages (from huggingface_hub) (2023.10.0)\n",
+ "Requirement already satisfied: requests in /opt/conda/lib/python3.10/site-packages (from huggingface_hub) (2.31.0)\n",
+ "Requirement already satisfied: tqdm>=4.42.1 in /opt/conda/lib/python3.10/site-packages (from huggingface_hub) (4.65.0)\n",
+ "Requirement already satisfied: pyyaml>=5.1 in /opt/conda/lib/python3.10/site-packages (from huggingface_hub) (6.0.1)\n",
+ "Requirement already satisfied: typing-extensions>=3.7.4.3 in /opt/conda/lib/python3.10/site-packages (from huggingface_hub) (4.7.1)\n",
+ "Requirement already satisfied: packaging>=20.9 in /opt/conda/lib/python3.10/site-packages (from huggingface_hub) (23.1)\n",
+ "Requirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/lib/python3.10/site-packages (from requests->huggingface_hub) (2.0.4)\n",
+ "Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.10/site-packages (from requests->huggingface_hub) (3.4)\n",
+ "Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/conda/lib/python3.10/site-packages (from requests->huggingface_hub) (1.26.18)\n",
+ "Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.10/site-packages (from requests->huggingface_hub) (2023.7.22)\n",
+ "Downloading huggingface_hub-0.19.4-py3-none-any.whl (311 kB)\n",
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m311.7/311.7 kB\u001b[0m \u001b[31m4.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n",
+ "\u001b[?25hInstalling collected packages: huggingface_hub\n",
+ "Successfully installed huggingface_hub-0.19.4\n",
+ "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
+ "\u001b[0mNote: you may need to restart the kernel to use updated packages.\n"
+ ]
+ }
+ ],
+ "source": [
+ "pip install huggingface_hub"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "id": "f7ebcbea-3bb2-468f-b159-ff20693e98c8",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "application/vnd.jupyter.widget-view+json": {
+ "model_id": "58fa0d78829446c98f1facc6250b2d5b",
+ "version_major": 2,
+ "version_minor": 0
+ },
+ "text/plain": [
+ "VBox(children=(HTML(value='
270\u001b[0m \u001b[43mresponse\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mraise_for_status\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 271\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m HTTPError \u001b[38;5;28;01mas\u001b[39;00m e:\n",
+ "File \u001b[0;32m/opt/conda/lib/python3.10/site-packages/requests/models.py:1021\u001b[0m, in \u001b[0;36mResponse.raise_for_status\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1020\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m http_error_msg:\n\u001b[0;32m-> 1021\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m HTTPError(http_error_msg, response\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m)\n",
+ "\u001b[0;31mHTTPError\u001b[0m: 400 Client Error: Bad Request for url: https://huggingface.co/api/spaces/kevinwang676/AI-Agent/commit/main",
+ "\nThe above exception was the direct cause of the following exception:\n",
+ "\u001b[0;31mBadRequestError\u001b[0m Traceback (most recent call last)",
+ "Cell \u001b[0;32mIn[5], line 4\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mhuggingface_hub\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m HfApi\n\u001b[1;32m 2\u001b[0m api \u001b[38;5;241m=\u001b[39m HfApi()\n\u001b[0;32m----> 4\u001b[0m \u001b[43mapi\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mupload_folder\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 5\u001b[0m \u001b[43m \u001b[49m\u001b[43mfolder_path\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 6\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mkevinwang676/AI-Agent\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 7\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo_type\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mspace\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 8\u001b[0m \u001b[43m)\u001b[49m\n",
+ "File \u001b[0;32m/opt/conda/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py:118\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.._inner_fn\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 115\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[1;32m 116\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m smoothly_deprecate_use_auth_token(fn_name\u001b[38;5;241m=\u001b[39mfn\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m, has_token\u001b[38;5;241m=\u001b[39mhas_token, kwargs\u001b[38;5;241m=\u001b[39mkwargs)\n\u001b[0;32m--> 118\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
+ "File \u001b[0;32m/opt/conda/lib/python3.10/site-packages/huggingface_hub/hf_api.py:1045\u001b[0m, in \u001b[0;36mfuture_compatible.._inner\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1042\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrun_as_future(fn, \u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m 1044\u001b[0m \u001b[38;5;66;03m# Otherwise, call the function normally\u001b[39;00m\n\u001b[0;32m-> 1045\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
+ "File \u001b[0;32m/opt/conda/lib/python3.10/site-packages/huggingface_hub/hf_api.py:4138\u001b[0m, in \u001b[0;36mHfApi.upload_folder\u001b[0;34m(self, repo_id, folder_path, path_in_repo, commit_message, commit_description, token, repo_type, revision, create_pr, parent_commit, allow_patterns, ignore_patterns, delete_patterns, multi_commits, multi_commits_verbose, run_as_future)\u001b[0m\n\u001b[1;32m 4126\u001b[0m pr_url \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcreate_commits_on_pr(\n\u001b[1;32m 4127\u001b[0m repo_id\u001b[38;5;241m=\u001b[39mrepo_id,\n\u001b[1;32m 4128\u001b[0m repo_type\u001b[38;5;241m=\u001b[39mrepo_type,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 4135\u001b[0m verbose\u001b[38;5;241m=\u001b[39mmulti_commits_verbose,\n\u001b[1;32m 4136\u001b[0m )\n\u001b[1;32m 4137\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m-> 4138\u001b[0m commit_info \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcreate_commit\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 4139\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo_type\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrepo_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 4140\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrepo_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 4141\u001b[0m \u001b[43m \u001b[49m\u001b[43moperations\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcommit_operations\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 4142\u001b[0m \u001b[43m \u001b[49m\u001b[43mcommit_message\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcommit_message\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 4143\u001b[0m \u001b[43m \u001b[49m\u001b[43mcommit_description\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcommit_description\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 4144\u001b[0m \u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 4145\u001b[0m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrevision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 4146\u001b[0m \u001b[43m \u001b[49m\u001b[43mcreate_pr\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcreate_pr\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 4147\u001b[0m \u001b[43m \u001b[49m\u001b[43mparent_commit\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mparent_commit\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 4148\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 4149\u001b[0m pr_url \u001b[38;5;241m=\u001b[39m commit_info\u001b[38;5;241m.\u001b[39mpr_url\n\u001b[1;32m 4151\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m create_pr \u001b[38;5;129;01mand\u001b[39;00m pr_url \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n",
+ "File \u001b[0;32m/opt/conda/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py:118\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.._inner_fn\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 115\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[1;32m 116\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m smoothly_deprecate_use_auth_token(fn_name\u001b[38;5;241m=\u001b[39mfn\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m, has_token\u001b[38;5;241m=\u001b[39mhas_token, kwargs\u001b[38;5;241m=\u001b[39mkwargs)\n\u001b[0;32m--> 118\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
+ "File \u001b[0;32m/opt/conda/lib/python3.10/site-packages/huggingface_hub/hf_api.py:1045\u001b[0m, in \u001b[0;36mfuture_compatible.._inner\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1042\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrun_as_future(fn, \u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m 1044\u001b[0m \u001b[38;5;66;03m# Otherwise, call the function normally\u001b[39;00m\n\u001b[0;32m-> 1045\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
+ "File \u001b[0;32m/opt/conda/lib/python3.10/site-packages/huggingface_hub/hf_api.py:3237\u001b[0m, in \u001b[0;36mHfApi.create_commit\u001b[0;34m(self, repo_id, operations, commit_message, commit_description, token, repo_type, revision, create_pr, num_threads, parent_commit, run_as_future)\u001b[0m\n\u001b[1;32m 3235\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 3236\u001b[0m commit_resp \u001b[38;5;241m=\u001b[39m get_session()\u001b[38;5;241m.\u001b[39mpost(url\u001b[38;5;241m=\u001b[39mcommit_url, headers\u001b[38;5;241m=\u001b[39mheaders, data\u001b[38;5;241m=\u001b[39mdata, params\u001b[38;5;241m=\u001b[39mparams)\n\u001b[0;32m-> 3237\u001b[0m \u001b[43mhf_raise_for_status\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcommit_resp\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mendpoint_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcommit\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3238\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m RepositoryNotFoundError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 3239\u001b[0m e\u001b[38;5;241m.\u001b[39mappend_to_message(_CREATE_COMMIT_NO_REPO_ERROR_MESSAGE)\n",
+ "File \u001b[0;32m/opt/conda/lib/python3.10/site-packages/huggingface_hub/utils/_errors.py:326\u001b[0m, in \u001b[0;36mhf_raise_for_status\u001b[0;34m(response, endpoint_name)\u001b[0m\n\u001b[1;32m 322\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m response\u001b[38;5;241m.\u001b[39mstatus_code \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m400\u001b[39m:\n\u001b[1;32m 323\u001b[0m message \u001b[38;5;241m=\u001b[39m (\n\u001b[1;32m 324\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mBad request for \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mendpoint_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m endpoint:\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m endpoint_name \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mBad request:\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 325\u001b[0m )\n\u001b[0;32m--> 326\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m BadRequestError(message, response\u001b[38;5;241m=\u001b[39mresponse) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01me\u001b[39;00m\n\u001b[1;32m 328\u001b[0m \u001b[38;5;66;03m# Convert `HTTPError` into a `HfHubHTTPError` to display request information\u001b[39;00m\n\u001b[1;32m 329\u001b[0m \u001b[38;5;66;03m# as well (request id and/or server error message)\u001b[39;00m\n\u001b[1;32m 330\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m HfHubHTTPError(\u001b[38;5;28mstr\u001b[39m(e), response\u001b[38;5;241m=\u001b[39mresponse) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01me\u001b[39;00m\n",
+ "\u001b[0;31mBadRequestError\u001b[0m: (Request ID: Root=1-6575633c-3007e4fc53be037b5ceb5402;4cd41d1e-0094-48a4-bbe9-db4d06cbc023)\n\nBad request for commit endpoint:\n\"license\" must be one of [apache-2.0, mit, openrail, bigscience-openrail-m, creativeml-openrail-m, bigscience-bloom-rail-1.0, bigcode-openrail-m, afl-3.0, artistic-2.0, bsl-1.0, bsd, bsd-2-clause, bsd-3-clause, bsd-3-clause-clear, c-uda, cc, cc0-1.0, cc-by-2.0, cc-by-2.5, cc-by-3.0, cc-by-4.0, cc-by-sa-3.0, cc-by-sa-4.0, cc-by-nc-2.0, cc-by-nc-3.0, cc-by-nc-4.0, cc-by-nd-4.0, cc-by-nc-nd-3.0, cc-by-nc-nd-4.0, cc-by-nc-sa-2.0, cc-by-nc-sa-3.0, cc-by-nc-sa-4.0, cdla-sharing-1.0, cdla-permissive-1.0, cdla-permissive-2.0, wtfpl, ecl-2.0, epl-1.0, epl-2.0, eupl-1.1, agpl-3.0, gfdl, gpl, gpl-2.0, gpl-3.0, lgpl, lgpl-2.1, lgpl-3.0, isc, lppl-1.3c, ms-pl, mpl-2.0, odc-by, odbl, openrail++, osl-3.0, postgresql, ofl-1.1, ncsa, unlicense, zlib, pddl, lgpl-lr, deepfloyd-if-license, llama2, unknown, other, array]"
+ ]
+ }
+ ],
+ "source": [
+ "from huggingface_hub import HfApi\n",
+ "api = HfApi()\n",
+ "\n",
+ "api.upload_folder(\n",
+ " folder_path=\"\",\n",
+ " repo_id=\"kevinwang676/AI-Agent\",\n",
+ " repo_type=\"space\",\n",
+ ")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "2ee3f7dc-08f8-4675-b48a-a61095caf08b",
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.10.13"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
diff --git a/agentfabric/__init__.py b/agentfabric/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/agentfabric/app.py b/agentfabric/app.py
new file mode 100644
index 0000000000000000000000000000000000000000..b3d5e5897c0d31b5b871b2bc9f4952521a2b24a5
--- /dev/null
+++ b/agentfabric/app.py
@@ -0,0 +1,660 @@
+import os
+import random
+import re
+import shutil
+import traceback
+
+import gradio as gr
+import json
+import yaml
+from builder_core import beauty_output, init_builder_chatbot_agent
+from config_utils import (DEFAULT_AGENT_DIR, Config, get_avatar_image,
+ get_ci_dir, get_user_cfg_file, get_user_dir,
+ is_valid_plugin_configuration, parse_configuration,
+ save_avatar_image, save_builder_configuration,
+ save_plugin_configuration)
+from gradio_utils import ChatBot, format_cover_html, format_goto_publish_html
+from i18n import I18n
+from publish_util import pop_user_info_from_config, prepare_agent_zip
+from user_core import init_user_chatbot_agent
+
+
+def init_user(uuid_str, state):
+ try:
+ seed = state.get('session_seed', random.randint(0, 1000000000))
+ user_agent = init_user_chatbot_agent(uuid_str)
+ user_agent.seed = seed
+ state['user_agent'] = user_agent
+ except Exception as e:
+ error = traceback.format_exc()
+ print(f'Error:{e}, with detail: {error}')
+ return state
+
+
+def init_builder(uuid_str, state):
+
+ try:
+ builder_agent = init_builder_chatbot_agent(uuid_str)
+ state['builder_agent'] = builder_agent
+ except Exception as e:
+ error = traceback.format_exc()
+ print(f'Error:{e}, with detail: {error}')
+ return state
+
+
+def update_builder(uuid_str, state):
+ builder_agent = state['builder_agent']
+
+ try:
+ builder_cfg_file = get_user_cfg_file(uuid_str=uuid_str)
+ with open(builder_cfg_file, 'r') as f:
+ config = json.load(f)
+ builder_agent.update_config_to_history(config)
+ except Exception as e:
+ error = traceback.format_exc()
+ print(f'Error:{e}, with detail: {error}')
+ return state
+
+
+def check_uuid(uuid_str):
+ if not uuid_str or uuid_str == '':
+ if os.getenv('MODELSCOPE_ENVIRONMENT') == 'studio':
+ raise gr.Error('请登陆后使用! (Please login first)')
+ else:
+ uuid_str = 'local_user'
+ return uuid_str
+
+
+def process_configuration(uuid_str, bot_avatar, name, description,
+ instructions, model, suggestions, knowledge_files,
+ capabilities_checkboxes, openapi_schema,
+ openapi_auth, openapi_auth_apikey,
+ openapi_auth_apikey_type, openapi_privacy_policy,
+ state):
+ uuid_str = check_uuid(uuid_str)
+ tool_cfg = state['tool_cfg']
+ capabilities = state['capabilities']
+ bot_avatar, bot_avatar_path = save_avatar_image(bot_avatar, uuid_str)
+ suggestions_filtered = [row for row in suggestions if row[0]]
+ user_dir = get_user_dir(uuid_str)
+ if knowledge_files is not None:
+ new_knowledge_files = [
+ os.path.join(user_dir, os.path.basename((f.name)))
+ for f in knowledge_files
+ ]
+ for src_file, dst_file in zip(knowledge_files, new_knowledge_files):
+ if not os.path.exists(dst_file):
+ shutil.copy(src_file.name, dst_file)
+ else:
+ new_knowledge_files = []
+
+ builder_cfg = {
+ 'name': name,
+ 'avatar': bot_avatar,
+ 'description': description,
+ 'instruction': instructions,
+ 'prompt_recommend': [row[0] for row in suggestions_filtered],
+ 'knowledge': new_knowledge_files,
+ 'tools': {
+ capability: dict(
+ name=tool_cfg[capability]['name'],
+ is_active=tool_cfg[capability]['is_active'],
+ use=True if capability in capabilities_checkboxes else False)
+ for capability in map(lambda item: item[1], capabilities)
+ },
+ 'model': model,
+ }
+
+ try:
+ try:
+ schema_dict = json.loads(openapi_schema)
+ except json.decoder.JSONDecodeError:
+ schema_dict = yaml.safe_load(openapi_schema)
+ except Exception as e:
+ raise gr.Error(
+ f'OpenAPI schema format error, should be one of json and yaml: {e}'
+ )
+
+ openapi_plugin_cfg = {
+ 'schema': schema_dict,
+ 'auth': {
+ 'type': openapi_auth,
+ 'apikey': openapi_auth_apikey,
+ 'apikey_type': openapi_auth_apikey_type
+ },
+ 'privacy_policy': openapi_privacy_policy
+ }
+ if is_valid_plugin_configuration(openapi_plugin_cfg):
+ save_plugin_configuration(openapi_plugin_cfg, uuid_str)
+ except Exception as e:
+ error = traceback.format_exc()
+ print(f'Error:{e}, with detail: {error}')
+
+ save_builder_configuration(builder_cfg, uuid_str)
+ update_builder(uuid_str, state)
+ init_user(uuid_str, state)
+ return [
+ gr.HTML.update(
+ visible=True,
+ value=format_cover_html(builder_cfg, bot_avatar_path)),
+ gr.Chatbot.update(
+ visible=False,
+ avatar_images=get_avatar_image(bot_avatar, uuid_str)),
+ gr.Dataset.update(samples=suggestions_filtered),
+ gr.DataFrame.update(value=suggestions_filtered)
+ ]
+
+
+# 创建 Gradio 界面
+demo = gr.Blocks(css='assets/app.css')
+with demo:
+
+ uuid_str = gr.Textbox(label='modelscope_uuid', visible=False)
+ draw_seed = random.randint(0, 1000000000)
+ state = gr.State({'session_seed': draw_seed})
+ i18n = I18n('zh-cn')
+ with gr.Row():
+ with gr.Column(scale=5):
+ header = gr.Markdown(i18n.get('header'))
+ with gr.Column(scale=1):
+ language = gr.Dropdown(
+ choices=[('中文', 'zh-cn'), ('English', 'en')],
+ show_label=False,
+ container=False,
+ value='zh-cn',
+ interactive=True)
+ with gr.Row():
+ with gr.Column():
+ with gr.Tabs() as tabs:
+ with gr.Tab(i18n.get_whole('create'), id=0) as create_tab:
+ with gr.Column():
+ # "Create" 标签页的 Chatbot 组件
+ start_text = '欢迎使用agent创建助手。我可以帮助您创建一个定制agent。'\
+ '您希望您的agent主要用于什么领域或任务?比如,您可以说,我想做一个RPG游戏agent'
+ create_chatbot = gr.Chatbot(
+ show_label=False, value=[[None, start_text]])
+ create_chat_input = gr.Textbox(
+ label=i18n.get('message'),
+ placeholder=i18n.get('message_placeholder'))
+ create_send_button = gr.Button(
+ i18n.get('sendOnLoading'), interactive=False)
+
+ configure_tab = gr.Tab(i18n.get_whole('configure'), id=1)
+ with configure_tab:
+ with gr.Column():
+ # "Configure" 标签页的配置输入字段
+ with gr.Row():
+ bot_avatar_comp = gr.Image(
+ label=i18n.get('form_avatar'),
+ placeholder='Chatbot avatar image',
+ source='upload',
+ interactive=True,
+ type='filepath',
+ scale=1,
+ width=182,
+ height=182,
+ )
+ with gr.Column(scale=4):
+ name_input = gr.Textbox(
+ label=i18n.get('form_name'),
+ placeholder=i18n.get(
+ 'form_name_placeholder'))
+ description_input = gr.Textbox(
+ label=i18n.get('form_description'),
+ placeholder=i18n.get(
+ 'form_description_placeholder'))
+
+ instructions_input = gr.Textbox(
+ label=i18n.get('form_instructions'),
+ placeholder=i18n.get(
+ 'form_instructions_placeholder'),
+ lines=3)
+ model_selector = model_selector = gr.Dropdown(
+ label=i18n.get('form_model'))
+ suggestion_input = gr.Dataframe(
+ show_label=False,
+ value=[['']],
+ datatype=['str'],
+ headers=[i18n.get_whole('form_prompt_suggestion')],
+ type='array',
+ col_count=(1, 'fixed'),
+ interactive=True)
+ knowledge_input = gr.File(
+ label=i18n.get('form_knowledge'),
+ file_count='multiple',
+ file_types=['text', '.json', '.csv', '.pdf'])
+ capabilities_checkboxes = gr.CheckboxGroup(
+ label=i18n.get('form_capabilities'))
+
+ with gr.Accordion(
+ i18n.get('open_api_accordion'),
+ open=False) as open_api_accordion:
+ openapi_schema = gr.Textbox(
+ label='Schema',
+ placeholder=
+ 'Enter your OpenAPI schema here, JSON or YAML format only'
+ )
+
+ with gr.Group():
+ openapi_auth_type = gr.Radio(
+ label='Authentication Type',
+ choices=['None', 'API Key'],
+ value='None')
+ openapi_auth_apikey = gr.Textbox(
+ label='API Key',
+ placeholder='Enter your API Key here')
+ openapi_auth_apikey_type = gr.Radio(
+ label='API Key type', choices=['Bearer'])
+ openapi_privacy_policy = gr.Textbox(
+ label='Privacy Policy',
+ placeholder='Enter privacy policy URL')
+
+ configure_button = gr.Button(
+ i18n.get('form_update_button'))
+
+ with gr.Column():
+ # Preview
+ preview_header = gr.HTML(
+ f"""