Skip to content

Commit 9c96d1a

Browse files
committed
chore(baf): agent run signal and refactor
Signed-off-by: Tomas Pilar <[email protected]>
1 parent 3f0bf58 commit 9c96d1a

File tree

1 file changed

+23
-22
lines changed
  • agents/official/bee-agent-framework/src

1 file changed

+23
-22
lines changed

agents/official/bee-agent-framework/src/server.ts

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,30 +71,44 @@ async function registerTools(server: AcpServer) {
7171
}
7272
);
7373
}
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+
);
7488
}
7589

7690
async function registerAgents(server: AcpServer) {
77-
// Create dummy agent for metadata
7891
const agent = createBeeAgent();
79-
80-
// Register agent
8192
server.agent(
8293
"bee",
8394
agent.meta.description,
8495
messageInputSchema.extend({ config: agentConfigSchema }),
8596
messageOutputSchema,
86-
async ({
87-
params: {
88-
input: { messages, config },
89-
_meta,
97+
async (
98+
{
99+
params: {
100+
input: { messages, config },
101+
_meta,
102+
},
90103
},
91-
}) => {
104+
{ signal }
105+
) => {
92106
const memory = new UnconstrainedMemory();
93107
memory.addMany(
94108
messages.map(({ role, content }) => Message.of({ role, text: content }))
95109
);
96110
const output = await createBeeAgent(memory, config?.tools)
97-
.run({ prompt: null })
111+
.run({ prompt: null }, { signal })
98112
.observe((emitter) => {
99113
emitter.on("partialUpdate", async ({ update }) => {
100114
if (_meta?.progressToken && update.key === "final_answer") {
@@ -125,19 +139,6 @@ async function registerAgents(server: AcpServer) {
125139
ui: "chat",
126140
} as const satisfies Metadata
127141
);
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-
);
141142
}
142143

143144
// Server

0 commit comments

Comments
 (0)