一、进入腾讯元器平台
访问腾讯元器官网。

二、登录并选择智能体模板
登录后在智能体模板中选择所需类型,例如博物馆导览文案生成智能体。


点击左上角复制智能体,即可在'我的智能体'页面查看。或者点击新建智能体来创建。


进入编辑页面,可在应用设置中自定义模型设置、工作流、欢迎语等。

点击工作流管理进入核心流程配置界面。


三、主要构建工作流的工具
(1)参数提取器
当用户配置好智能体调用的 APIKEY 和 URL 后,通过与用户进行单轮或多轮对话收集参数,缺失或模糊时可自动反问澄清。


(2)选项卡
提供可点击的选项,适合选项明确且数量少的情况。支持手动输入固定选项(如售前、售后咨询)或动态拉取变量值。


(3)文件收集
设置引导语和要求,收集用户上传的文件(文档、音频等)。



(4)文本收集
在问答场景中向用户提问,原样输出用户回答。适用场景:收集信息后传递给后续节点处理、沉淀意见反馈原文、合规留存等。特点:不做判断、不追问,一次性收集。



(5)大模型
使用大模型处理自然语言要求,如回答问题。


(6)大模型意图识别
大模型根据待识别内容识别意图,如是、否。




(7)大模型知识问答
从限定范围的知识库中检索内容,并通过大模型润色回复。



(8)工具
调用自定义 HTTP 接口,集成外部数据和服务。多个工作流重复调用时,建议创建插件。



更多工具使用方法可参考官方文档。

四、使用工作流创建简单聊天工具
(1)新建智能体
新建一个智能体并点击对话智能体。

(2)填写基本信息
填写智能体的名称和简介,可点击 AI 生成头像。

(3)应用设置
进入智能体内部的应用设置并根据需求填写。

(4)创建工作流
点击顶部菜单的工作流管理并点击新建,选择手动录入。

(5)配置工作流描述
填写工作流名称及描述,可使用模板一键优化,确认进入编辑页面。


(6)配置参数提取
编辑工作流,第一步使用参数提取工具将工具拖拉进画布。注意:不允许在节点开始后与其他信息收集类节点并行。用于提取用户发来的聊天内容。

点击编辑,填写参数名称、参数类型及参数描述。

(7)连接大模型知识问答
第二步选择大模型知识问答工具,连接到参数提取器后面。变量名称需与代码使用的变量名一致,数据源引用参数提取器的输出内容赋值给 message。提示词用于让 AI 知道任务目标,使用 {{message}} 格式引用输入变量。


(8)连接工具节点
在大模型知识问答后面连接工具,接受第三方发起的工作流调用并启动工作流。接口连接必须是公网 IP(本地电脑可使用内网穿透)。

API 参数需与第三方平台接口设定保持一致。

第三方平台的接口如果有输出变量可写在下方。

调试通过后发布,在应用发布中找到体验链接内的 appid 和 appkey 填入第三方平台即可使用。

五、编写第三方平台的聊天 AI 实现代码
(1)Controller 类
@RestController
@RequestMapping("/Ai")
public class AiController {
@Resource
private RedisTemplate redisTemplate;
@Resource
private AiServerImpl aiServer;
@GetMapping("/AiChat")
private String AiChat(@RequestParam("message") String Message) {
return aiServer.GetAiChat(Message);
}
@GetMapping("/GetMessage")
public String getMessage(String message) {
if (message != null) aiServer.getMessage(message);
else {
System.out.println((String) redisTemplate.opsForValue().get("ms1"));
}
return (String) redisTemplate.opsForValue().get("ms1");
}
}
(2)Service 接口
public interface AiServer {
String GetAiChat(String Message);
void getMessage(String message);
}
(3)ServiceImpl 类
@Slf4j
@Service
public class AiServerImpl implements AiServer {
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private RestTemplate restTemplate;
@Autowired
private AiMapper aiMapper;
private static final String DEEPSEEK_BASE_URL = "https://yuanqi.tencent.com/openapi/v1/agent/chat/completions";
private static final String DEEPSEEK_API_KEY = "智能体密钥";
private static final String DEFAULT_MODEL = "智能体 id";
public String GetAiChat(String Message) {
List<AiModel> aiModels = aiMapper.getAiModel();
if (aiModels == null || aiModels.isEmpty()) {
return "(模型配置为空,请检查 AI 模型表)";
}
String modelName = aiModels.get(0).getAgent_name();
System.out.println(modelName);
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
httpHeaders.set("Authorization", "Bearer " + DEEPSEEK_API_KEY);
OpenAiMessage userMessage = new OpenAiMessage();
userMessage.setRole("user");
userMessage.setContent(Message);
HttpEntity<Map<String, Object>> entity = new HttpEntity<>(buildRequestBody(DEFAULT_MODEL, "1", Message), httpHeaders);
try {
ResponseEntity<String> response = restTemplate.exchange(DEEPSEEK_BASE_URL, HttpMethod.POST, entity, String.class);
if (response.getStatusCode() == HttpStatus.OK) {
String resp = response.getBody();
if (resp != null) {
log.info(resp);
return resp;
}
}
return "(无返回内容)";
} catch (HttpClientErrorException ex) {
String respBody = ex.getResponseBodyAsString();
String errorMsg = String.format("(模型调用失败) %s: %s", ex.getStatusCode(), respBody != null ? respBody : "[no body]");
System.err.println("API 调用 4xx 错误:" + errorMsg);
return errorMsg;
} catch (Exception ex) {
String errorMsg = String.format("(模型调用异常) %s: %s", ex.getClass().getSimpleName(), ex.getMessage());
System.err.println("API 调用通用异常:" + errorMsg);
return errorMsg;
}
}
@Override
public void getMessage(String message) {
redisTemplate.opsForValue().set("ms1", message);
}
private Map<String, Object> buildRequestBody(String agentId, String userId, String message) {
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("assistant_id", agentId);
requestBody.put("user_id", userId);
requestBody.put("stream", false);
List<Map<String, Object>> messages = new ArrayList<>();
Map<String, Object> userMsg = new HashMap<>();
userMsg.put("role", "user");
List<Map<String, Object>> contentList = new ArrayList<>();
Map<String, Object> textContent = new HashMap<>();
textContent.put("type", "text");
String jsonMessage = buildJsonMessage(message);
textContent.put("text", jsonMessage);
contentList.add(textContent);
userMsg.put("content", contentList);
messages.add(userMsg);
requestBody.put("messages", messages);
Map<String, Object> parameters = new HashMap<>();
parameters.put("temperature", 0.7);
parameters.put("max_tokens", 2000);
requestBody.put("parameters", parameters);
return requestBody;
}
private String buildJsonMessage(String message) {
try {
Map<String, Object> params = new HashMap<>();
params.put("content", message);
return new ObjectMapper().writeValueAsString(params);
} catch (Exception e) {
log.error("构建 JSON 消息失败", e);
String escapedContent = message.replace("\"", "\\\"").replace("\n", "\\n");
return String.format("{\"content\":\"%s\"}", escapedContent);
}
}
@Data
static class OpenAiMessage {
private String role;
private String content;
}
@Data
static class OpenAiChatRequest {
private String model;
private List<OpenAiMessage> messages;
@JsonProperty("temperature")
private Double temperature = 0.7;
}
@Data
static class OpenAiChatResponse {
private List<Choice> choices;
private OpenAiError error;
@Data
static class Choice {
private OpenAiMessage message;
@JsonProperty("finish_reason")
private String finishReason;
}
@Data
static class OpenAiError {
private Integer code;
private String message;
private String type;
}
}
}
(4)实体类
public class AiModel implements Serializable {
private long id;
private long user_id;
private String agent_id;
private String agent_name;
private String api_key;
private String api_endpoint;
public long getId() { return id; }
public void setId(long id) { this.id = id; }
public long getUser_id() { return user_id; }
public void setUser_id(long user_id) { this.user_id = user_id; }
public String getAgent_id() { return agent_id; }
public void setAgent_id(String agent_id) { this.agent_id = agent_id; }
public String getAgent_name() { return agent_name; }
public void setAgent_name(String agent_name) { this.agent_name = agent_name; }
public String getApi_key() { return api_key; }
public void setApi_key(String api_key) { this.api_key = api_key; }
public String getApi_endpoint() { return api_endpoint; }
public void setApi_endpoint(String api_endpoint) { this.api_endpoint = api_endpoint; }
}
(5)Mapper 类
@Mapper
public interface AiMapper {
@Select("select id,user_id,agent_id,agent_name,api_key,api_endpoint from yuanqi_agent where id=1")
public List<AiModel> getAiModel();
}
(6)RestTemplate 配置
@Configuration
public class Config {
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
(7)Redis 配置
@Configuration
public class RedisAutoConfiguration {
@Bean
@ConditionalOnMissingBean(name = {"redisTemplate"})
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(factory);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(om, Object.class);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(jackson2JsonRedisSerializer);
template.setHashKeySerializer(new StringRedisSerializer());
template.setHashValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
template.setDefaultSerializer(jackson2JsonRedisSerializer);
return template;
}
@Bean
public RedisCacheManager cacheManager(RedisConnectionFactory factory) {
ObjectMapper om = new ObjectMapper();
RedisSerializer<String> stringSerializer = new StringRedisSerializer();
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(om, Object.class);
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofDays(1))
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(stringSerializer))
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer))
.disableCachingNullValues();
return RedisCacheManager.builder(factory).cacheDefaults(config).build();
}
}
六、效果演示







