22/12/2021

Agent to agent communication using mail

Suppose you want to have an agent (agent1) in database A, and a some point you want some other agent (agent2) to start or take over, maybe even in database B. There are several possibilities:

Now suppose we have to pass some information from one agent to the other. When you embed the code of the 2nd agent, it's a no-brainer: there is in fact only one agent, so the code of the second agent uses the same space as the first.

In order to pass information to a separate agent, you can use a Notes document and pass the document to the second agent. If you don't save the document, the information stays in memory so you don't have to delete anything.


	Set docTemp= New NotesDocument(db)
	...  ' set field values
	Call agent2.runWithDocumentContext(docTemp) 
	
When agent2 executes, the execution of agent1 is stopped. It will only continue when agent2 stops.

Suppose you want to decouple both agents completely: different databases, different rights, maybe even different servers, and not synchronised. In that case you can prepare a Notes document, just like in the previous example, and you send it to the other database.
"Er... How?" Well, using NotesDocument.Send()
"Ok, but to what address?" Ah, right: to a Mail-In database!

In principle, any database on the server can receive mails, when correctly set up by the Administrator. What needs to be done is: create a Mail-In Database document in the Domino Directory (names.nsf) on the server. Once such a document exists, the address can be used to send mail to.

The mail doesn't need to be fancy, and it doesn't have to follow any mail conventions at all. What you need though is a means of identifying the mail, especially if you are going to use the mechanism for more than one action. I often use fields like "Command" to define what action should be executed in the target database.

Advantages:

Disadvantages: