-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.go
More file actions
166 lines (150 loc) · 3.87 KB
/
main.go
File metadata and controls
166 lines (150 loc) · 3.87 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package main
import (
"context"
"fmt"
"log"
"os"
"strings"
"github.com/antgroup/aievo/agent"
"github.com/antgroup/aievo/aievo"
"github.com/antgroup/aievo/environment"
"github.com/antgroup/aievo/llm"
"github.com/antgroup/aievo/llm/openai"
"github.com/antgroup/aievo/memory"
"github.com/antgroup/aievo/schema"
"github.com/antgroup/aievo/tool"
"github.com/antgroup/aievo/tool/arxiv"
"github.com/antgroup/aievo/tool/search"
)
const searchApiKey = "xxx"
func main() {
// 大模型实例化
client, err := openai.New(
openai.WithToken(os.Getenv("OPENAI_API_KEY")),
openai.WithModel(os.Getenv("OPENAI_MODEL")),
openai.WithBaseURL(os.Getenv("OPENAI_BASE_URL")))
if err != nil {
log.Fatal(err)
}
// 实例化所需要的Tools
// 搜索引擎
search, _ := search.New(
search.WithEngine("google"),
search.WithApiKey(searchApiKey),
search.WithTopK(3),
)
// 论文检索
arxiv, _ := arxiv.New(
arxiv.WithTopk(10),
arxiv.WithUserAgent("aievo/1.0"),
)
callbackHandler := &CallbackHandler{}
// 实例化Agents
// RTA
RTA, _ := agent.NewBaseAgent(
agent.WithName("RTA"),
agent.WithDesc(RTADescription),
agent.WithPrompt(RTAPrompt),
agent.WithInstruction(defaultBaseInstructions),
agent.WithLLM(client),
agent.WithCallback(callbackHandler),
)
// LROA
LROA, _ := agent.NewBaseAgent(
agent.WithName("LROA"),
agent.WithDesc(LROADescription),
agent.WithPrompt(LROAPrompt),
agent.WithInstruction(defaultBaseInstructions),
agent.WithLLM(client),
agent.WithTools([]tool.Tool{search, arxiv}),
agent.WithCallback(callbackHandler),
)
// OGA
OGA, _ := agent.NewBaseAgent(
agent.WithName("OGA"),
agent.WithDesc(OGADescription),
agent.WithPrompt(OGAPrompt),
agent.WithInstruction(defaultBaseInstructions),
agent.WithLLM(client),
agent.WithCallback(callbackHandler),
agent.WithFilterMemoryFunc(func(msgs []schema.Message) []schema.Message {
haveCGA := false
for _, msg := range msgs {
if msg.Receiver == "CGA" {
haveCGA = true
break
}
}
if haveCGA {
// 如果和CGA交互过了, 删除所有和LROA的交互记忆
filterMsgs := make([]schema.Message, 0)
for _, msg := range msgs {
if msg.Sender == "LROA" || msg.Receiver == "LROA" {
continue
}
filterMsgs = append(filterMsgs, msg)
}
msgs = filterMsgs
}
filterMsgs := make([]schema.Message, 0)
for _, msg := range msgs {
if msg.Sender == "CGA" && msg.Receiver == "OGA" {
// 去除换行符
strings.ReplaceAll(msg.Content, "\n", " ")
}
filterMsgs = append(filterMsgs, msg)
}
msgs = filterMsgs
return msgs
}),
)
// CGA
CGA, _ := agent.NewBaseAgent(
agent.WithName("CGA"),
agent.WithDesc(CGADescription),
agent.WithPrompt(CGAPrompt),
agent.WithInstruction(defaultBaseInstructions),
agent.WithLLM(client),
agent.WithCallback(callbackHandler),
agent.WithFilterMemoryFunc(func(msgs []schema.Message) []schema.Message {
// 仅保留最后一个msg
return msgs[len(msgs)-1:]
}),
)
// PPA
PPA, _ := agent.NewBaseAgent(
agent.WithName("PPA"),
agent.WithDesc(PPADescription),
agent.WithPrompt(PPAPrompt),
agent.WithInstruction(defaultEndBaseInstructions),
agent.WithLLM(client),
agent.WithCallback(callbackHandler),
)
env := environment.NewEnv()
env.Memory = memory.NewBufferMemory()
team := make([]schema.Agent, 0)
team = append(team, RTA, LROA, OGA, CGA, PPA)
opts := make([]aievo.Option, 0)
opts = append(opts,
aievo.WithTeam(team),
aievo.WithMaxTurn(50),
aievo.WithCallback(callbackHandler),
aievo.WithLLM(client),
aievo.WithEnvironment(env),
aievo.WithTeamLeader(RTA),
aievo.WithSOP(workflow),
aievo.WithUserProxy(nil),
)
evo, err := aievo.NewAIEvo(opts...)
if err != nil {
panic(err)
}
run, err := evo.Run(context.Background(),
"MultiAIAgent/MultiAgent 高效协作",
llm.WithTemperature(0.1),
)
if err != nil {
panic(err)
}
fmt.Println(run)
}