mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
refactor(context): add StateHintContent to fit information exchange between different modules with communication producer
This commit is contained in:
@@ -183,7 +183,7 @@ private data class ResolvedContextBlock(
|
||||
data class ContextBlock @JvmOverloads constructor(
|
||||
val blockContent: BlockContent,
|
||||
val compactBlock: BlockContent = blockContent,
|
||||
val abstractBlock: BlockContent = blockContent,
|
||||
val abstractBlock: BlockContent = compactBlock,
|
||||
/**
|
||||
* 该 block 集中在哪些域
|
||||
*/
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package work.slhaf.partner.module
|
||||
|
||||
import work.slhaf.partner.common.base.Block
|
||||
import work.slhaf.partner.framework.agent.model.pojo.Message
|
||||
|
||||
abstract class TaskBlock @JvmOverloads constructor(
|
||||
blockName: String = "task_input"
|
||||
) : Block(blockName) {
|
||||
|
||||
fun encodeToMessage(): Message {
|
||||
return Message(Message.Character.USER, encodeToXmlString())
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import work.slhaf.partner.framework.agent.factory.component.abstracts.AbstractAg
|
||||
import work.slhaf.partner.framework.agent.factory.component.annotation.Init;
|
||||
import work.slhaf.partner.framework.agent.factory.component.annotation.InjectModule;
|
||||
import work.slhaf.partner.framework.agent.support.Result;
|
||||
import work.slhaf.partner.module.StateHintContent;
|
||||
import work.slhaf.partner.module.action.executor.ActionExecutor;
|
||||
import work.slhaf.partner.module.action.planner.evaluator.ActionEvaluator;
|
||||
import work.slhaf.partner.module.action.planner.evaluator.entity.EvaluatorInput;
|
||||
@@ -89,12 +90,22 @@ public class ActionPlanner extends AbstractAgentModule.Running<PartnerRunningFlo
|
||||
private void appendTendencyBlock(List<String> tendencies) {
|
||||
String datetime = ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
cognitionCapability.contextWorkspace().register(new ContextBlock(
|
||||
buildTendenciesEvaluatingFullBlock(tendencies),
|
||||
buildTendenciesEvaluatingCompactBlock(tendencies, datetime),
|
||||
buildTendenciesEvaluatingCompactBlock(tendencies, datetime),
|
||||
buildTendenciesEvaluatingAbstractBlock(tendencies, datetime),
|
||||
Set.of(ContextBlock.FocusedDomain.ACTION),
|
||||
60, 18, 4
|
||||
));
|
||||
|
||||
cognitionCapability.contextWorkspace().register(StateHintContent.createBlock(new StateHintContent(
|
||||
BLOCK_SOURCE,
|
||||
"Partner is evaluating whether any action tendency should be taken for the latest input."
|
||||
) {
|
||||
@Override
|
||||
public void fillStateContent(@NotNull Document document, @NotNull Element stateElement) {
|
||||
appendListElement(document, stateElement, "action_tendencies", "tendency", tendencies);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private @NotNull BlockContent buildTendenciesEvaluatingAbstractBlock(List<String> tendencies, String datetime) {
|
||||
@@ -114,23 +125,12 @@ public class ActionPlanner extends AbstractAgentModule.Running<PartnerRunningFlo
|
||||
int size = tendencies.size();
|
||||
boolean num = size > 3;
|
||||
appendTextElement(document, root, "datetime", datetime);
|
||||
appendTextElement(document, root, "state", "Candidate action tendencies are under evaluation");
|
||||
appendTextElement(document, root, "tendencies_count", size);
|
||||
appendListElement(document, root, num ? "tendencies_truncated" : "tendencies", "tendency", num ? tendencies.subList(0, 3) : tendencies);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private @NotNull BlockContent buildTendenciesEvaluatingFullBlock(List<String> tendencies) {
|
||||
return new BlockContent(TENDENCIES_EVALUATING_BLOCK_NAME, getModuleName()) {
|
||||
@Override
|
||||
protected void fillXml(@NotNull Document document, @NotNull Element root) {
|
||||
appendTextElement(document, root, "state", "Candidate action tendencies are under evaluation");
|
||||
appendListElement(document, root, "tendencies", "tendency", tendencies);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void evaluateTendency(String source, String input, ExtractorResult extractorResult) {
|
||||
executor.execute(() -> {
|
||||
EvaluatorInput evaluatorInput = assemblyHelper.buildEvaluatorInput(extractorResult);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package work.slhaf.partner.module
|
||||
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Element
|
||||
import work.slhaf.partner.common.base.Block
|
||||
import work.slhaf.partner.core.cognition.CommunicationBlockContent
|
||||
import work.slhaf.partner.core.cognition.ContextBlock
|
||||
import work.slhaf.partner.framework.agent.model.pojo.Message
|
||||
|
||||
abstract class TaskBlock @JvmOverloads constructor(
|
||||
blockName: String = "task_input"
|
||||
) : Block(blockName) {
|
||||
|
||||
fun encodeToMessage(): Message {
|
||||
return Message(Message.Character.USER, encodeToXmlString())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
abstract class StateHintContent protected constructor(
|
||||
source: String,
|
||||
val stateMsg: String
|
||||
) : CommunicationBlockContent("new_state", source, Urgency.NORMAL, Projection.SUPPLY) {
|
||||
|
||||
override fun fillXml(document: Document, root: Element) {
|
||||
appendTextElement(document, root, "state_msg", stateMsg)
|
||||
appendChildElement(document, root, "state_content") {
|
||||
fillStateContent(document, this@appendChildElement)
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun fillStateContent(document: Document, stateElement: Element)
|
||||
|
||||
private fun toContextBlock(): ContextBlock {
|
||||
return ContextBlock(
|
||||
blockContent = this,
|
||||
focusedOn = setOf(ContextBlock.FocusedDomain.COGNITION),
|
||||
replaceFadeFactor = 60.0,
|
||||
timeFadeFactor = 30.0,
|
||||
activateFactor = 0.0
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun createBlock(block: StateHintContent): ContextBlock {
|
||||
return block.toContextBlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user