Marcelo, maybe you could try something like this instead of all this casts:
StatefulKnowledgeSession ks = ksession.execute(new GenericCommand<StatefulKnowledgeSession>() {
public StatefulKnowledgeSession execute(Context context) {
return ((KnowledgeCommandContext) context).getStatefulKnowledgesession();
}
});
where ksession is CommandBasedStatefulKnowledgeSession and ks will be its undelying InternalKnowledgeRuntime.
HTH