Agent Process Callback
interface AgentProcessCallback
Callback interface for interleaving logic with the lifecycle of an AgentProcess and its actions.
This is particularly useful for ConcurrentAgentProcess, where launched actions run in their own threads and may, for example, need a Spring Security context proliferated to the thread in which the action runs:
@Component
@Scope("prototype")
class SecurityContextAgentProcessCallback : AgentProcessCallback {
var securityContext: SecurityContext? = null
override fun beforeActionLaunched(process: AgentProcess) {
securityContext = SecurityContextHolder.getContext()
}
override fun onActionLaunched(
process: AgentProcess,
action: Action,
) {
securityContext?.let {
SecurityContextHolder.setContext(it)
}
}
override fun onActionCompleted(
process: AgentProcess,
action: Action,
) {
SecurityContextHolder.clearContext()
}
}Content copied to clipboard