MCPcopy Create free account
hub / github.com/cloudwego/eino-examples / buildMathAgent

Function buildMathAgent

adk/multiagent/supervisor/agent.go:78–161  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

76}
77
78func buildMathAgent(ctx context.Context) (adk.Agent, error) {
79 m := model.NewChatModel()
80
81 type addReq struct {
82 A float64 `json:"a"`
83 B float64 `json:"b"`
84 }
85
86 type addResp struct {
87 Result float64
88 }
89
90 add := func(ctx context.Context, req *addReq) (*addResp, error) {
91 return &addResp{
92 Result: req.A + req.B,
93 }, nil
94 }
95
96 addTool, err := tools.SafeInferTool("add", "add two numbers", add)
97 if err != nil {
98 return nil, err
99 }
100
101 type multiplyReq struct {
102 A float64 `json:"a"`
103 B float64 `json:"b"`
104 }
105
106 type multiplyResp struct {
107 Result float64
108 }
109
110 multiply := func(ctx context.Context, req *multiplyReq) (*multiplyResp, error) {
111 return &multiplyResp{
112 Result: req.A * req.B,
113 }, nil
114 }
115
116 multiplyTool, err := tools.SafeInferTool("multiply", "multiply two numbers", multiply)
117 if err != nil {
118 return nil, err
119 }
120
121 type divideReq struct {
122 A float64 `json:"a"`
123 B float64 `json:"b"`
124 }
125
126 type divideResp struct {
127 Result float64
128 }
129
130 divide := func(ctx context.Context, req *divideReq) (*divideResp, error) {
131 return &divideResp{
132 Result: req.A / req.B,
133 }, nil
134 }
135

Callers 1

buildSupervisorFunction · 0.70

Calls 2

NewChatModelFunction · 0.92
SafeInferToolFunction · 0.92

Tested by

no test coverage detected