@@ -71,30 +71,44 @@ async function registerTools(server: AcpServer) {
71
71
}
72
72
) ;
73
73
}
74
+
75
+ // Register agent as a tool
76
+ const agent = createBeeAgent ( ) ;
77
+ server . tool (
78
+ "bee" ,
79
+ agent . meta . description ,
80
+ promptInputSchema . extend ( { config : agentConfigSchema } ) . shape ,
81
+ async ( { config, ...input } , { signal } ) => {
82
+ const output = await createBeeAgent ( undefined , config ?. tools ) . run ( input , {
83
+ signal,
84
+ } ) ;
85
+ return { content : [ { type : "text" , text : output . result . text } ] } ;
86
+ }
87
+ ) ;
74
88
}
75
89
76
90
async function registerAgents ( server : AcpServer ) {
77
- // Create dummy agent for metadata
78
91
const agent = createBeeAgent ( ) ;
79
-
80
- // Register agent
81
92
server . agent (
82
93
"bee" ,
83
94
agent . meta . description ,
84
95
messageInputSchema . extend ( { config : agentConfigSchema } ) ,
85
96
messageOutputSchema ,
86
- async ( {
87
- params : {
88
- input : { messages, config } ,
89
- _meta,
97
+ async (
98
+ {
99
+ params : {
100
+ input : { messages, config } ,
101
+ _meta,
102
+ } ,
90
103
} ,
91
- } ) => {
104
+ { signal }
105
+ ) => {
92
106
const memory = new UnconstrainedMemory ( ) ;
93
107
memory . addMany (
94
108
messages . map ( ( { role, content } ) => Message . of ( { role, text : content } ) )
95
109
) ;
96
110
const output = await createBeeAgent ( memory , config ?. tools )
97
- . run ( { prompt : null } )
111
+ . run ( { prompt : null } , { signal } )
98
112
. observe ( ( emitter ) => {
99
113
emitter . on ( "partialUpdate" , async ( { update } ) => {
100
114
if ( _meta ?. progressToken && update . key === "final_answer" ) {
@@ -125,19 +139,6 @@ async function registerAgents(server: AcpServer) {
125
139
ui : "chat" ,
126
140
} as const satisfies Metadata
127
141
) ;
128
-
129
- // Register agent as a tool
130
- server . tool (
131
- "bee" ,
132
- agent . meta . description ,
133
- promptInputSchema . extend ( { config : agentConfigSchema } ) . shape ,
134
- async ( { config, ...input } , { signal } ) => {
135
- const output = await createBeeAgent ( undefined , config ?. tools ) . run ( input , {
136
- signal,
137
- } ) ;
138
- return { content : [ { type : "text" , text : output . result . text } ] } ;
139
- }
140
- ) ;
141
142
}
142
143
143
144
// Server
0 commit comments