ai-courseware/eino-project/internal/domain/agent/product.go

49 lines
1.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package agent
import (
"context"
"eino-project/internal/domain/llm"
"eino-project/internal/domain/tools"
"github.com/cloudwego/eino/adk"
"github.com/cloudwego/eino/components/tool"
"github.com/cloudwego/eino/compose"
)
// NewProductChatAgent 使用 ADK ChatModelAgent 构造一个具备工具选择能力的商品查询 Agent
func NewProductChatAgent(ctx context.Context, models llm.LLM) adk.Agent {
chatModel, err := models.Chat()
if err != nil {
return nil
}
toolsCfg := adk.ToolsConfig{
ToolsNodeConfig: compose.ToolsNodeConfig{
Tools: []tool.BaseTool{
tools.NewProductByIDTool(),
tools.NewProductSearchByNameTool(),
},
ExecuteSequentially: false,
},
// ReturnDirectly: map[string]bool{
// "get_product_by_id": true,
// "search_product_by_name": true,
// },
}
agent, _ := adk.NewChatModelAgent(ctx, &adk.ChatModelAgentConfig{
Name: "商品查询智能体",
Description: "根据用户输入查询商品信息支持按ID或名称检索",
Model: chatModel,
ToolsConfig: toolsCfg,
Instruction: `
# 你是一个商品查询智能体,根据用户输入查询商品信息。
- 当用户输入商品ID时优先使用"get_product_by_id"工具查询商品详情。
- 当用户输入商品名称时,使用"search_product_by_name"工具搜索相关商品。
- 当用户需要查询多个结果时,合并所有结果返回。
- 输出结构为: {"items": [...], "source": "id|name", "count": int} 无需解释文本
`,
})
return agent
}