Following is a simple demonstration of how documents in memory can be used to communicate between XPages and Agents.The beauty in the following description is that the document in memory is never being saved. That is an awesome stuff that I feel is really helpful for developers in many occations
Create an XPage with a couple of input fields named "boxA" and "boxB" as shown in the following image
1. it simply creates a document on the fly named "inMemoryDoc"
2. Handle to an agent present in the backend is obtained
3. The agent is asked to be executed with the inMemoryDoc created in the first step as documentcontext
4. The inMemory document gets updated (not saved) in the backend and the updated values are asked to be displayed on the UI using the getComponent("").setValue() methods.
The code fragment in the agent that resides on the backend is as follows
So as a result when you preview the XPage on the browser and hit the button the out put will be as follows
Hope this helps :)