modelscope / modelscope-agent

ModelScope-Agent: An agent framework connecting models in ModelScope with the world
https://modelscope-agent.readthedocs.io/en/latest/
Apache License 2.0
2.64k stars 302 forks source link

Tool Nonimplementation Error #468

Open kbzh2558 opened 3 months ago

kbzh2558 commented 3 months ago

Initial Checks

What happened + What you expected to happen

您好,

我在建立一个多agent framework,按照单agent的方法把一些本地写的tools写在了上面 (@register_tool('get-index-info') class GetIndexTool(BaseTool):)但是当运行脚本时出现报错说tools import false:

File "C:\Users\kbzh\folder\modelscope-agent\FRAMEWORK_agent\modelscope_agent\agent.py", line 120, in _register_tool raise NotImplementedError NotImplementedError

大概的framework结构和example给出的chatroom类似。我想知道这类示例下tool registration具体应该如何做。

谢谢!

Versions / Dependencies

python 3.11.0

agent

import logging import time import json import ray from modelscope_agent import create_component from modelscope_agent.agents import RolePlay from modelscope_agent.multi_agents_utils.executors.ray import RayTaskExecutor from modelscope_agent.task_center import TaskCenter

Reproduction script

其中一个implementation如下:

llm_config = { 'model': 'GLM-4', 'model_server': 'zhipu' }

input tool name

function_list = ['get-index-info','get-index-data','get-index-weight', 'get-industry-info','get-company-info','get-st-history', 'get-stock-data','get-fundamental-data','get-economic-indicator-data']

empty_func_list = []

planner_agent = create_component( RolePlay, name='计划者', remote=REMOTE_MODE, llm=llm_config, function_list=empty_func_list, instruction=PLANNER_INSTRUCTION_PROMPT)

roles = [planner_agent , ....]

def receive_input():

Function to receive input from the user

question = input("Please input your question: ")
return question

def check_completion():

Function to check if all tasks are completed

for role in roles:
    if not role.task_complete:
        return False
return True

def generate_answer(question):

Function to pass the question to the agent framework and monitor completion

planner_agent.input_text(question)
while not check_completion():
    time.sleep(1)
return expresser_agent.output_text

def main(): question = receive_input() answer = generate_answer(question) output = { 'action': 'output the plan and completion status', 'answer': answer } print(json.dumps(output))

if name == "main": ray.get(task_center.add_agents.remote(roles)) ray.get(task_center.add_agents.remote([output_agent]))

main()

Issue Severity

High: It blocks me from completing my task.

mushenL commented 3 months ago

您好,从报错上看似乎是没有正确注册,您可以参考https://github.com/modelscope/modelscope-agent/blob/master/docs/contributing/tool_contribution_guide_CN.md 这个文档的流程进行,建议您可以先检查一下modelscope_agent/tools/base.py 中的register_map和您tool文件对应的init.py文件中的_import_structure是否正确设置了您的tool,同时您的tool文件中还需要@register_tool()来修饰您的工具,可以先检查一下以上操作是否已经完成

kbzh2558 commented 3 months ago

您好,

谢谢您的帮助。问题基本解决。请问我若是想要查看每次访问消耗的token数量应该如何操作呢?谢谢。我用的是ZHIPU的模型