@@ -3,6 +3,7 @@ import { AgentMCPProps, AgentProps, AgentToolProps } from "@/agent/types/agent";
33import {
44 AGENT_TOOL_NAME_PREFIX ,
55 KNOWLEDGE_TOOL_NAME_PREFIX ,
6+ SKILL_TOOL_NAME_PREFIX ,
67 TOOL_NAME_SPLIT ,
78 WORKFLOW_BODY_DATABASE ,
89 WORKFLOW_TOOL_NAME_PREFIX ,
@@ -22,6 +23,8 @@ import {
2223 ToolRequestBody ,
2324} from "../types/chatModel" ;
2425import { VisionModel } from "../vision/VisionModel" ;
26+ import { SkillManager } from "@/skills/SkillManager" ;
27+ import { ChatModel } from "./ChatModel" ;
2528
2629export class ToolsHandler {
2730 static async transformAgentToolToModelFormat (
@@ -235,9 +238,35 @@ export class ToolsHandler {
235238 return toolRequestBody ;
236239 }
237240
241+ static async transformSkillToModelFormat (
242+ skills : string [ ] ,
243+ ) : Promise < ToolRequestBody > {
244+ const toolRequestBody : ToolRequestBody = [ ] ;
245+ if ( skills . length ) {
246+ /* 获取代理 */
247+ const list = SkillManager . getSkills ( ) ;
248+
249+ /* 将知识库变成工具 */
250+ skills . forEach ( ( skill ) => {
251+ const skillDoc = list [ skill ] ;
252+ if ( ! skillDoc ) return ;
253+ toolRequestBody . push ( {
254+ type : "function" ,
255+ function : {
256+ name : `${ SKILL_TOOL_NAME_PREFIX } ${ TOOL_NAME_SPLIT } ${ skill } ` ,
257+ description : skillDoc . description ,
258+ parameters : skillDoc . params ,
259+ } ,
260+ } ) ;
261+ } ) ;
262+ }
263+ return toolRequestBody ;
264+ }
265+
238266 static async call (
239267 tool_call : ToolCallReply ,
240268 otherModels : AgentProps [ "models" ] ,
269+ chatModel : ChatModel ,
241270 ) : Promise < FunctionCallResult | undefined > {
242271 if ( ! tool_call ) return ;
243272
@@ -343,7 +372,14 @@ export class ToolsHandler {
343372 result,
344373 } ;
345374 }
346-
375+ if ( firstName === SKILL_TOOL_NAME_PREFIX ) {
376+ const result = await SkillManager . execute ( secondName , query , chatModel ) ;
377+ return {
378+ name : tool_call . function . name ,
379+ arguments : tool_call . function . arguments ,
380+ result,
381+ } ;
382+ }
347383 if ( firstName === KNOWLEDGE_TOOL_NAME_PREFIX ) {
348384 if ( ! query . query ) {
349385 return {
@@ -402,6 +438,13 @@ export class ToolsHandler {
402438 name : `calling agent: ${ list [ secondName ] . name } ` ,
403439 } ;
404440 }
441+ if ( firstName === SKILL_TOOL_NAME_PREFIX ) {
442+ const list = SkillManager . getSkills ( ) ;
443+ return {
444+ type : "skill" ,
445+ name : `calling skill: ${ list [ secondName ] . name } ` ,
446+ } ;
447+ }
405448
406449 if ( firstName === WORKFLOW_TOOL_NAME_PREFIX ) {
407450 const list = await WorkflowsStore . getCurrent ( ) ;
0 commit comments