fix: Chains invoke error

This commit is contained in:
Michael Yang 2024-05-11 17:19:01 +08:00
parent ee863db58d
commit c40b804f72
3 changed files with 42 additions and 16 deletions

View File

@ -270,11 +270,14 @@ public abstract class Chain implements Serializable {
notifyInput(waitInputParameters);
}
}
if (status == ChainStatus.START) {
setStatus(ChainStatus.FINISHED_NORMAL);
notifyEvent(new OnFinishedEvent());
} else if (status == ChainStatus.ERROR) {
setStatus(ChainStatus.FINISHED_ABNORMAL);
try {
if (status == ChainStatus.START) {
setStatus(ChainStatus.FINISHED_NORMAL);
} else if (status == ChainStatus.ERROR) {
setStatus(ChainStatus.FINISHED_ABNORMAL);
}
} finally {
notifyEvent(new OnFinishedEvent());
}
}

View File

@ -29,6 +29,7 @@ public abstract class AbstractBaseNode implements ChainNode {
this.id = UUID.randomUUID();
}
@Override
public Object getId() {
return id;
@ -38,6 +39,12 @@ public abstract class AbstractBaseNode implements ChainNode {
this.id = id;
}
public AbstractBaseNode id(Object id) {
this.id = id;
return this;
}
@Override
public String getName() {
return name;
@ -47,6 +54,11 @@ public abstract class AbstractBaseNode implements ChainNode {
this.name = name;
}
public AbstractBaseNode name(String name) {
this.name = name;
return this;
}
public void setSkip(boolean skip) {
this.skip = skip;
}
@ -56,8 +68,10 @@ public abstract class AbstractBaseNode implements ChainNode {
return skip;
}
public void skip() {
public AbstractBaseNode skip() {
this.skip = true;
return this;
}
}

View File

@ -50,19 +50,28 @@ public class AgentNode extends AbstractBaseNode {
@Override
public Map<String, Object> execute(Chain chain) {
List<Parameter> inputParameters = agent.getInputParameters();
Map<String, Object> variables = new HashMap<>();
List<Parameter> requiredParameters = null;
for (Parameter parameter : inputParameters) {
Object value = chain.get(parameter.getName());
if (value == null && parameter.isRequired()) {
if (requiredParameters == null) {
requiredParameters = new ArrayList<>();
}
requiredParameters.add(parameter);
} else {
variables.put(parameter.getName(), value);
List<Parameter> inputParameters = agent.getInputParameters();
// Agent 未定义输入参数
if (inputParameters.isEmpty()) {
variables.putAll(chain.getMemory().getAll());
}
// Agent 定义了固定的输入参数
else {
for (Parameter parameter : inputParameters) {
Object value = chain.get(parameter.getName());
if (value == null && parameter.isRequired()) {
if (requiredParameters == null) {
requiredParameters = new ArrayList<>();
}
requiredParameters.add(parameter);
} else {
variables.put(parameter.getName(), value);
}
}
}