Menu

How can I access belief and belief set from outside?

Help
2016-09-08
2016-09-08
  • Mahmud Hasan

    Mahmud Hasan - 2016-09-08

    Hi,

    I am starting my platfrom from a main function,
    And created a simple Interface to change a boolean flag (a belief) that triggers my root goal.

    Here is my code:

     public static void main(String[] args) throws Exception
     {
    
        PlatformConfiguration config = PlatformConfiguration.getDefault();
        RootComponentConfiguration rootConfig = config.getRootConfig();
    
        rootConfig.setGui(false);
        rootConfig.setWelcome(false);
        rootConfig.setCli(false);
        rootConfig.setPrintPass(false);
    
        IFuture<IExternalAccess> platformFuture = Starter.createPlatform(config);
        IExternalAccess platform = platformFuture.get();
    
        IComponentManagementService cms = SServiceProvider.getService(platform,
        IComponentManagementService.class, RequiredServiceInfo.SCOPE_PLATFORM).get();
    
    
        String CasperModel = "simsol.casper.agent.CasperAgentBDI.class";
    
        final ITuple2Future<IComponentIdentifier, Map<String, Object>> componentFuture =
                   cms.createComponent("CasperAgentBDI", CasperModel, null);
    
        IComponentIdentifier component = componentFuture.getFirstResult();
    
        IExternalAccess external = cms.getExternalAccess(component).get();
    
    
        IInitialisationService serviceSQ 
         = SServiceProvider.getDeclaredService(external, IInitialisationService.class).get();
    
        serviceSQ.SetExecution(true);
    
    }
    

    Now I can see that I can add more interface to change belief from outside.
    But I am not sure if this is the correct way to do it.

    I am assuming that it is possible to access IBeliefSet and IBelief. But I am confused How can I do it from my main() function.

    Moreover, how can I add a listener in my belief so that it can trigger an external method when belief is changed? Or what is the best way to update external module when agent do some action?

    Thanks.

     
  • Lars Braubach

    Lars Braubach - 2016-09-08

    Hi,

    the short answer is you cannot do it from outside a component because this would violate its autonomy.

    The longer answer is you can do it by 'changing execution to the component' using scheduleStep (in newer versions on the IExecutionFeature). This allows you to execute a command (IComponentStep) directly on the component itself. In this way you have direct access to all of the agent's internals because you now have the IInternalAccess at your disposal (instead of the IIExternalAccess).

    Kind regards
    Lars

     
  • Mahmud Hasan

    Mahmud Hasan - 2016-09-08

    Thanks Dr. Lars,

    Could you please point me any of the example code that uses newer way to do it using IExecutionFeature?

    One quick clarification,
    in the initialization code (above, my first post),

    I have,

    IExternalAccess external = cms.getExternalAccess(component).get();

    When I was trying to use getBeliefBase() from external, it looked like it was not available.
    was I missing something?

    Thanks.

     
  • Lars Braubach

    Lars Braubach - 2016-09-08

    You can access the BDI pojo agent object this way

    IExternalAccess ea = ...;
    ea.scheduleStep(new IComponentStep<void>()
    {
    public IFuture<void> execute(IInternalAccess ia)
    {
    CleanerBDI cleaner = (CleanerBDI)ia.getComponentFeature(IPojoComponentFeature.class).getPojoAgent();
    }
    });</void></void>

     
  • Mahmud Hasan

    Mahmud Hasan - 2016-09-08

    So, just to clarify,

    I can use scheduleStep from my connection class to access my agent pojo object.
    But, for that I need access to IExternalAccess interface.

    Looking into some of the example code, it looks, like IExternalAccess interface is supplied through constructor. That is, the object was instantiated in agent body.

    Is that correct?

    Thanks.

     

Log in to post a comment.

MongoDB Logo MongoDB