How a single java agent works for two targets based on the view

I have a requirement like, java agent has to get all the selected documents from any view like inbox,draft…I can get these by using getUnprocessedDocuments() and the agent target should be “All Selected Documents”.But if i run the agent for any open mails and those are not saved then it saying like “Please save the document”.This will work if i make target of that java agent to “None”.As per our requirement i need to get these two features, if inbox view is opened i need to get all the selected documents, if i open a new memo, it should not ask for saving the document before calling agent. Is these any way to solve this problem from one single java agent OR is there any way to call one java agent from another java agent through coding.

Thanks in advance,