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
Connections
receive or createEnvelopes
which they deposit in theInBox
- for agent-to-agent communication only, the
Multiplexer
keeps track of theconnection_id
via which theEnvelope
was received. - the
AgentLoop
picksEnvelopes
off theInBox
- the
AEA
tries to decode the message; errors are handled by theErrorHandler
-
Messages
are dispatched based on two rules:- checks if
to
field can be interpreted asskill_id
, if so uses that together with theprotocol_id
to dispatch to the protocol'sHandler
in the specifiedSkill
, else - uses the
protocol_id
to dispatch to the protocol'sHandler
in 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
Skills
depositMessages
inOutBox
OutBox
constructs anEnvelope
from theMessage
-
Multiplexer
assigns messages to relevantConnection
based 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
EnvelopeContext
exists 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_id
referenced in theEnvelope
, if so uses that else - sends to default
Connection
.
- checks if
- Component to component messages are routed by their
-
Connections
can processEnvelopes
directly 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.