Files
Easy-Agents/easy-agents-agent-runtime/src/main/java/com/easyagents/agent/runtime/AgentDefinition.java
陈子默 43f45956ff feat: 对接 Agent MCP 能力
- 新增 runtime MCP 声明、ClientFactory、Toolkit 适配与工具别名映射

- 增加 MCP 环境检测与 stdio 环境变量透传

- 补齐 MCP 工具事件、审批与生命周期释放测试
2026-05-29 11:08:39 +08:00

310 lines
7.6 KiB
Java

package com.easyagents.agent.runtime;
import com.easyagents.agent.runtime.knowledge.AgentKnowledgeSpec;
import com.easyagents.agent.runtime.memory.AgentMemoryPolicy;
import com.easyagents.agent.runtime.mcp.McpSpec;
import com.easyagents.agent.runtime.model.AgentGenerationOptions;
import com.easyagents.agent.runtime.model.AgentModelSpec;
import com.easyagents.agent.runtime.persistence.AgentPersistencePolicy;
import com.easyagents.agent.runtime.skill.AgentSkillBoxSpec;
import com.easyagents.agent.runtime.tool.AgentToolSpec;
import com.easyagents.agent.runtime.tool.operate.AgentOperateToolSpec;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* 主入口
* ReAct 智能体的声明式定义
*/
public class AgentDefinition {
private String agentId;
private String agentName;
private String description;
private String systemPrompt;
private AgentModelSpec modelSpec;
private AgentGenerationOptions generationOptions = new AgentGenerationOptions();
private AgentExecutionOptions executionOptions = new AgentExecutionOptions();
private List<AgentToolSpec> toolSpecs = new ArrayList<>();
private List<McpSpec> mcpSpecs = new ArrayList<>();
private List<AgentOperateToolSpec> operateToolSpecs = new ArrayList<>();
private List<AgentKnowledgeSpec> knowledgeSpecs = new ArrayList<>();
private AgentMemoryPolicy memoryPolicy = AgentMemoryPolicy.autoContext();
private AgentPersistencePolicy persistencePolicy = AgentPersistencePolicy.disabled();
private AgentSkillBoxSpec skillBoxSpec;
private Map<String, Object> metadata = new LinkedHashMap<>();
/**
* 获取agent id。
*
* @return 智能体ID
*/
public String getAgentId() {
return agentId;
}
/**
* 设置agent id。
*
* @param agentId 智能体ID
*/
public void setAgentId(String agentId) {
this.agentId = agentId;
}
/**
* 获取agent name。
*
* @return 智能体名称
*/
public String getAgentName() {
return agentName;
}
/**
* 设置agent name。
*
* @param agentName 智能体名称
*/
public void setAgentName(String agentName) {
this.agentName = agentName;
}
/**
* 获取agent description。
*
* @return 智能体描述
*/
public String getDescription() {
return description;
}
/**
* 设置agent description。
*
* @param description 智能体描述
*/
public void setDescription(String description) {
this.description = description;
}
/**
* 获取system prompt。
*
* @return 系统提示词
*/
public String getSystemPrompt() {
return systemPrompt;
}
/**
* 设置system prompt。
*
* @param systemPrompt 系统提示词
*/
public void setSystemPrompt(String systemPrompt) {
this.systemPrompt = systemPrompt;
}
/**
* 获取模型设置。
*
* @return 模型设置
*/
public AgentModelSpec getModelSpec() {
return modelSpec;
}
/**
* 设置模型设置。
*
* @param modelSpec 模型设置
*/
public void setModelSpec(AgentModelSpec modelSpec) {
this.modelSpec = modelSpec;
}
/**
* 获取生成参数。
*
* @return 生成参数
*/
public AgentGenerationOptions getGenerationOptions() {
return generationOptions;
}
/**
* 设置生成参数。
*
* @param generationOptions 生成参数
*/
public void setGenerationOptions(AgentGenerationOptions generationOptions) {
this.generationOptions = generationOptions == null ? new AgentGenerationOptions() : generationOptions;
}
/**
* 获取执行参数。
*
* @return 执行参数
*/
public AgentExecutionOptions getExecutionOptions() {
return executionOptions;
}
/**
* 设置执行参数。
*
* @param executionOptions 执行参数
*/
public void setExecutionOptions(AgentExecutionOptions executionOptions) {
this.executionOptions = executionOptions == null ? new AgentExecutionOptions() : executionOptions;
}
/**
* 获取工具定义。
*
* @return 工具定义
*/
public List<AgentToolSpec> getToolSpecs() {
return toolSpecs;
}
/**
* 设置工具定义。
*
* @param toolSpecs 工具定义
*/
public void setToolSpecs(List<AgentToolSpec> toolSpecs) {
this.toolSpecs = toolSpecs == null ? new ArrayList<>() : new ArrayList<>(toolSpecs);
}
/**
* 获取 MCP 声明。
*
* @return MCP 声明
*/
public List<McpSpec> getMcpSpecs() {
return mcpSpecs;
}
/**
* 设置 MCP 声明。
*
* @param mcpSpecs MCP 声明
*/
public void setMcpSpecs(List<McpSpec> mcpSpecs) {
this.mcpSpecs = mcpSpecs == null ? new ArrayList<>() : new ArrayList<>(mcpSpecs);
}
/**
* 获取操作类工具定义。
*
* @return 操作类工具定义
*/
public List<AgentOperateToolSpec> getOperateToolSpecs() {
return operateToolSpecs;
}
/**
* 设置操作类工具定义。
*
* @param operateToolSpecs 操作类工具定义
*/
public void setOperateToolSpecs(List<AgentOperateToolSpec> operateToolSpecs) {
this.operateToolSpecs = operateToolSpecs == null ? new ArrayList<>() : new ArrayList<>(operateToolSpecs);
}
/**
* 获取知识库定义。
*
* @return 知识库定义
*/
public List<AgentKnowledgeSpec> getKnowledgeSpecs() {
return knowledgeSpecs;
}
/**
* 设置知识库定义。
*
* @param knowledgeSpecs 知识库定义
*/
public void setKnowledgeSpecs(List<AgentKnowledgeSpec> knowledgeSpecs) {
this.knowledgeSpecs = knowledgeSpecs == null ? new ArrayList<>() : new ArrayList<>(knowledgeSpecs);
}
/**
* 获取记忆策略。
*
* @return 记忆策略
*/
public AgentMemoryPolicy getMemoryPolicy() {
return memoryPolicy;
}
/**
* 设置记忆策略。
*
* @param memoryPolicy 记忆策略
*/
public void setMemoryPolicy(AgentMemoryPolicy memoryPolicy) {
this.memoryPolicy = memoryPolicy == null ? AgentMemoryPolicy.autoContext() : memoryPolicy;
}
/**
* 获取持久化策略。
*
* @return 持久化策略
*/
public AgentPersistencePolicy getPersistencePolicy() {
return persistencePolicy;
}
/**
* 设置持久化策略。
*
* @param persistencePolicy 持久化策略
*/
public void setPersistencePolicy(AgentPersistencePolicy persistencePolicy) {
this.persistencePolicy = persistencePolicy == null ? AgentPersistencePolicy.disabled() : persistencePolicy;
}
/**
* 获取SkillBox 设置。
*
* @return SkillBox 设置
*/
public AgentSkillBoxSpec getSkillBoxSpec() {
return skillBoxSpec;
}
/**
* 设置SkillBox 设置。
*
* @param skillBoxSpec SkillBox 设置
*/
public void setSkillBoxSpec(AgentSkillBoxSpec skillBoxSpec) {
this.skillBoxSpec = skillBoxSpec;
}
/**
* 获取元数据。
*
* @return 元数据
*/
public Map<String, Object> getMetadata() {
return metadata;
}
/**
* 设置元数据。
*
* @param metadata 元数据
*/
public void setMetadata(Map<String, Object> metadata) {
this.metadata = metadata == null ? new LinkedHashMap<>() : metadata;
}
}