refactor(MetaActionInfo): remove key attribute and update related logic

Context:
MetaActionInfo was previously located via its own key attribute.
This is now redundant, as ActionCore already uses the key of existedMetaActions
as the single source of truth.
This commit is contained in:
2025-12-19 20:41:07 +08:00
parent e851e33b2e
commit 225802c1a8
5 changed files with 14 additions and 17 deletions

View File

@@ -10,6 +10,7 @@ import work.slhaf.partner.core.action.entity.cache.CacheAdjustData;
import work.slhaf.partner.core.action.runner.SandboxRunnerClient;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Phaser;
@@ -43,7 +44,7 @@ public interface ActionCapability {
MetaActionInfo loadMetaActionInfo(@NonNull String actionKey);
List<MetaActionInfo> listAvailableActions();
Map<String, MetaActionInfo> listAvailableActions();
boolean checkExists(String... actionKeys);

View File

@@ -1,6 +1,5 @@
package work.slhaf.partner.core.action;
import cn.hutool.core.bean.BeanUtil;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import work.slhaf.partner.api.agent.factory.capability.annotation.CapabilityCore;
@@ -183,8 +182,8 @@ public class ActionCore extends PartnerCore<ActionCore> {
}
@CapabilityMethod
public List<MetaActionInfo> listAvailableActions() {
return existedMetaActions.values().stream().toList();
public Map<String, MetaActionInfo> listAvailableActions() {
return existedMetaActions;
}
@CapabilityMethod
@@ -221,15 +220,16 @@ public class ActionCore extends PartnerCore<ActionCore> {
@CapabilityMethod
public MetaAction loadMetaAction(@NonNull String actionKey) {
for (MetaActionInfo actionInfo : existedMetaActions.values()) {
if (actionInfo.getKey().equals(actionKey)) {
MetaAction metaAction = new MetaAction();
BeanUtil.copyProperties(actionInfo, metaAction);
return metaAction;
}
}
MetaActionInfo metaActionInfo = existedMetaActions.get(actionKey);
if (metaActionInfo == null) {
throw new MetaActionNotFoundException("未找到对应的行动程序信息" + actionKey);
}
MetaAction metaAction = new MetaAction();
metaAction.setParams(metaActionInfo.getParams());
metaAction.setType(metaActionInfo.getType());
metaAction.setIo(metaActionInfo.isIo());
return metaAction;
}
@CapabilityMethod
public List<PhaserRecord> listPhaserRecords() {

View File

@@ -8,7 +8,6 @@ import java.util.Map;
@Data
public class MetaActionInfo {
private String key;
private boolean io;
private MetaActionType type;

View File

@@ -103,7 +103,7 @@ public abstract class RunnerClient {
// 忽略非文本类型,行动描述信息只会以文本形式存在
if (resourceContent instanceof McpSchema.TextResourceContents content) {
MetaActionInfo metaActionInfo = JSONObject.parseObject(content.text(), MetaActionInfo.class);
existedMetaActions.put(id + "::" + metaActionInfo.getKey(), metaActionInfo);
existedMetaActions.put(id + "::" + resource.name(), metaActionInfo);
}
}
}

View File

@@ -11,7 +11,6 @@ import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunn
import work.slhaf.partner.api.chat.pojo.ChatResponse;
import work.slhaf.partner.common.thread.InteractionThreadPoolExecutor;
import work.slhaf.partner.core.action.ActionCapability;
import work.slhaf.partner.core.action.entity.MetaActionInfo;
import work.slhaf.partner.core.memory.pojo.EvaluatedSlice;
import work.slhaf.partner.module.modules.action.planner.evaluator.entity.EvaluatorBatchInput;
import work.slhaf.partner.module.modules.action.planner.evaluator.entity.EvaluatorInput;
@@ -69,9 +68,7 @@ public class ActionEvaluator extends AgentRunningSubModule<EvaluatorInput, List<
BeanUtil.copyProperties(data, temp);
temp.setTendency(tendency);
Map<String, String> availableActions = new HashMap<>();
for (MetaActionInfo metaActionInfo : actionCapability.listAvailableActions()) {
availableActions.put(metaActionInfo.getKey(), metaActionInfo.getDescription());
}
actionCapability.listAvailableActions().forEach((key, info) -> availableActions.put(key, info.getDescription()));
temp.setAvailableActions(availableActions);
list.add(temp);
}