Hi there.. it's a very simple mechanism. You need to implement the WorkItemHandler interface and put your logic inside the execute() method.
Then you need to register you implementation in the workItemManager inside the session:
ksession.getWorkItemManager().registerWorkItemHandler( "MyWorkItemManager",
myImplementation );