Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Wjc0323 opened this issue Dec 19, 2024 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@Wjc0323
Copy link

Wjc0323 commented Dec 19, 2024

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

@Wjc0323 Wjc0323 added the enhancement New feature or request label Dec 19, 2024
@DavdGao
Copy link
Collaborator

DavdGao commented Dec 19, 2024

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

@rayrayraykk
Copy link
Collaborator

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.

@Wjc0323
Copy link
Author

Wjc0323 commented Dec 20, 2024

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

@Wjc0323
Copy link
Author

Wjc0323 commented Dec 20, 2024

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

@Wjc0323
Copy link
Author

Wjc0323 commented Dec 20, 2024

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.

@zhijianma
Copy link
Collaborator

@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": "",
       }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants