-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathmultiAgents.ts
50 lines (46 loc) · 1.82 KB
/
multiAgents.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import "dotenv/config";
import { UnconstrainedMemory } from "bee-agent-framework/memory/unconstrainedMemory";
import { createConsoleReader } from "examples/helpers/io.js";
import { OpenMeteoTool } from "bee-agent-framework/tools/weather/openMeteo";
import { WikipediaTool } from "bee-agent-framework/tools/search/wikipedia";
import { AgentWorkflow } from "bee-agent-framework/experimental/workflows/agent";
import { BaseMessage, Role } from "bee-agent-framework/llms/primitives/message";
import { GroqChatLLM } from "bee-agent-framework/adapters/groq/chat";
const workflow = new AgentWorkflow();
workflow.addAgent({
name: "WeatherForecaster",
instructions: "You are a weather assistant. Respond only if you can provide a useful answer.",
tools: [new OpenMeteoTool()],
llm: new GroqChatLLM(),
execution: { maxIterations: 3 },
});
workflow.addAgent({
name: "Researcher",
instructions: "You are a researcher assistant. Respond only if you can provide a useful answer.",
tools: [new WikipediaTool()],
llm: new GroqChatLLM(),
});
workflow.addAgent({
name: "Solver",
instructions:
"Your task is to provide the most useful final answer based on the assistants' responses which all are relevant. Ignore those where assistant do not know.",
llm: new GroqChatLLM(),
});
const reader = createConsoleReader();
const memory = new UnconstrainedMemory();
for await (const { prompt } of reader) {
await memory.add(
BaseMessage.of({
role: Role.USER,
text: prompt,
meta: { createdAt: new Date() },
}),
);
const { result } = await workflow.run(memory.messages).observe((emitter) => {
emitter.on("success", (data) => {
reader.write(`-> ${data.step}`, data.response?.update?.finalAnswer ?? "-");
});
});
await memory.addMany(result.newMessages);
reader.write(`Agent 🤖`, result.finalAnswer);
}