Skip to content

Commit d44bbc2

Browse files
committed
Fixed KDOC comments and applied smart cast by 'check'
1 parent 94c236a commit d44bbc2

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

embabel-agent-api/src/main/kotlin/com/embabel/agent/api/common/TerminationSignal.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ enum class TerminationScope(val value: String) {
3232
}
3333

3434
/**
35-
* Signal for graceful termination. When placed on the blackboard,
35+
* Signal for graceful termination. When set on the agent process,
3636
* the agent or action will terminate at the next natural checkpoint.
3737
*
3838
* For agent termination: checked before each tick() in AbstractAgentProcess.

embabel-agent-api/src/main/kotlin/com/embabel/agent/api/termination/TerminationExtensions.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ import com.embabel.agent.core.support.AbstractAgentProcess
3737
* @see com.embabel.agent.api.tool.TerminateAgentException for immediate termination
3838
*/
3939
fun ProcessContext.terminateAgent(reason: String) {
40-
(agentProcess as AbstractAgentProcess).setTerminationRequest(
41-
TerminationSignal(TerminationScope.AGENT, reason)
42-
)
40+
check(agentProcess is AbstractAgentProcess) {
41+
"Termination signals require AbstractAgentProcess (found: ${agentProcess::class.simpleName})"
42+
}
43+
agentProcess.setTerminationRequest(TerminationSignal(TerminationScope.AGENT, reason))
4344
}
4445

4546
/**
@@ -58,9 +59,10 @@ fun ProcessContext.terminateAgent(reason: String) {
5859
* @see com.embabel.agent.api.tool.TerminateActionException for immediate termination
5960
*/
6061
fun ProcessContext.terminateAction(reason: String) {
61-
(agentProcess as AbstractAgentProcess).setTerminationRequest(
62-
TerminationSignal(TerminationScope.ACTION, reason)
63-
)
62+
check(agentProcess is AbstractAgentProcess) {
63+
"Termination signals require AbstractAgentProcess (found: ${agentProcess::class.simpleName})"
64+
}
65+
agentProcess.setTerminationRequest(TerminationSignal(TerminationScope.ACTION, reason))
6466
}
6567

6668
/**

0 commit comments

Comments
 (0)