Message routing
Message routing can be split up into the routing of incoming and outgoing Messages.
It is important to keep in mind that interaction protocols can be maintained between agents (agent to agent) and between components of the AEA (component to component). In the former case, the to/sender fields of the Envelope are agent addresses which must follow the address standard of agents, in the latter case they are component public ids. Crucially, both addresses must reference the same type: agent or component.
Incoming Messages
Connectionsreceive or createEnvelopeswhich they deposit in theInBox- for agent-to-agent communication only, the
Multiplexerkeeps track of theconnection_idvia which theEnvelopewas received. - the
AgentLooppicksEnvelopesoff theInBox - the
AEAtries to decode the message; errors are handled by theErrorHandler -
Messagesare dispatched based on two rules:- checks if
tofield can be interpreted asskill_id, if so uses that together with theprotocol_idto dispatch to the protocol'sHandlerin the specifiedSkill, else - uses the
protocol_idto dispatch to the protocol'sHandlerin all skills supporting the protocol.
- checks if
Note
For agent-to-agent communication it is advisable to have a single skill implement a given protocol. Skills can then forward the messages via skill-to-skill communication to other skills where required. Otherwise, received agent-to-agent messages will be forwarded to all skills implementing a handler for the specified protocol and the developer needs to take care to handle them appropriately (e.g. avoid multiple replies to a single message).
Outgoing Messages
SkillsdepositMessagesinOutBoxOutBoxconstructs anEnvelopefrom theMessage-
Multiplexerassigns messages to relevantConnectionbased on the following rules:- Component to component messages are routed by their
component_id - Agent to agent messages are routed following four rules:
- checks if
EnvelopeContextexists and specifies aConnection, if so uses that else - checks which connection handled the last message from
sender, if present uses that else - checks if default routing is specified for the
protocol_idreferenced in theEnvelope, if so uses that else - sends to default
Connection.
- checks if
- Component to component messages are routed by their
-
Connectionscan processEnvelopesdirectly or encode them for transport to another agent.
Usage of the EnvelopeContext
The EnvelopeContext is used to maintain agent-to-agent communication only and is managed almost entirely by the framework. The developer can set the EnvelopeContext explicitly for the first message in a dialogue to achieve targeted routing to connections (see 2. for outgoing messages). This is relevant when the same agent can be reached via multiple connections.
The EnvelopeContext is not sent to another agent.