agentscope icon indicating copy to clipboard operation
agentscope copied to clipboard

[Feature]: 请问如何用agentscope studio以托拽的形式 实现agent通过代码调用外部接口?

Open Wjc0323 opened this issue 1 year ago • 6 comments

请问如何在agentscope studio中 添加tool。以及如何用agentscope studio以托拽的形式 实现agent通过代码调用外部接口?

Wjc0323 avatar Dec 19 '24 07:12 Wjc0323

"在agentscope studio中添加tool"指的是?是说workstation添加新的工具么

DavdGao avatar Dec 19 '24 08:12 DavdGao

Adding external tools potentially means that the workflow execution engine may run untrusted code, which is a relatively risky operation, and therefore is not currently supported on our maintained website. We will consider adding this feature in the local version ASAP.

rayrayraykk avatar Dec 19 '24 08:12 rayrayraykk

截屏2024-12-20 09 56 13 在tool中添加reactagent可用的service 我已经用代码实现了由agent访问LLM再调用注册好的service 想请问您怎么在studio中利用拖拽的形式 实现这一点呢? 谢谢🙏

Wjc0323 avatar Dec 20 '24 01:12 Wjc0323

"在agentscope studio中添加tool"指的是?是说workstation添加新的工具么 image在tool中添加reactagent可用的service 我已经用代码实现了由agent访问LLM再调用注册好的service 想请问您怎么在studio中利用拖拽的形式 实现这一点呢? 谢谢🙏

Wjc0323 avatar Dec 20 '24 01:12 Wjc0323

Adding external tools potentially means that the workflow execution engine may run untrusted code, which is a relatively risky operation, and therefore is not currently supported on our maintained website. We will consider adding this feature in the local version ASAP.

thx!!! but can I make it happen in local agentscope studio? cause I already made it on code level, my leader told me to achieve on studio.

Wjc0323 avatar Dec 20 '24 02:12 Wjc0323

@Wjc0323

⚠️Warning Invoking external code or tools through an agent may involve relatively risky operations.


Here, we take BingServiceTest as an example to show how to add a new service. You can refer to the steps below.

FrontEnd

  • Add souce html of BingServiceTest to diretory src/agentscope/studio/static/html-drag-components , here we can copy from service-bing-search.html and rename the related data class to BingSearchServiceTest.
  • add BingServiceTest to the sidebar of workstation in src/agentscope/studio/templates/workstation.html
<li class="workstation-sidebar-dragitem unselectable-text"
   data-node="BingSearchServiceTest"
   draggable="true" ondragstart="drag(event)">
   Bing Search Test
</li>
  • Add Drag-Event to workstation in src/agentscope/studio/static/js/workstation.js
// add mapping
let  nameToHtmlFile ={
...
'BingSearchServiceTest': 'service-bing-search_test.html',
}

....
// add drag event
case 'BingSearchServiceTest':
           editor.addNode('BingSearchServiceTest', 0, 0,
               pos_x, pos_y, 'BingSearchServiceTest', {
                   "args": {
                       "api_key": "",
                       "num_results": 3,
                   }
               }, htmlSourceCode);
           break;

BackEnd

  • Add BingServiceTestNode to workstation in src/agentscope/web/workstation/workflow_node.py. In the new node, you need to call your customized service function.

# add nodes mapping
NODE_NAME_MAPPING = {
....
"BingSearchServiceTest": BingSearchServiceTestNode,
}

# source code
class BingSearchServiceTestNode(WorkflowNode):
   """
   Bing Search Test Node
   """

   node_type = WorkflowNodeType.SERVICE

   def __init__(
       self,
       node_id: str,
       opt_kwargs: dict,
       source_kwargs: dict,
       dep_opts: list,
   ) -> None:
       super().__init__(node_id, opt_kwargs, source_kwargs, dep_opts)
       self.service_func = partial(bing_search, **self.opt_kwargs)

   def compile(self) -> dict:
       return {
           "imports": "from agentscope.service import ServiceToolkit\n"
           "from functools import partial\n"
           "from agentscope.service import bing_search",
           "inits": f"{self.var_name} = partial(bing_search,"
           f" {kwarg_converter(self.opt_kwargs)})",
           "execs": "",
       }

zhijianma avatar Dec 23 '24 01:12 zhijianma