Agents send messages by adding JSON objects to their messages
array. The object is defined as:
{
to: "string" || "string"[]// an agent_id or agent_name
type: "string" // a string that defines the type of the message
data: "any" // an object that serves as the payload
}
agent_id
field or the agent(s) with the corresponding agent_name
field will receive the message in the next time step. If you want to send a message to multiple agents -- multicasting -- you can do so in one of two ways:
agent_name
that is shared by multiple agents, they will all receive the message. For instance, if five agents have the field agent_name
set to "forklift"
, they will all receive a message defined with to: "forklift"
const behavior = (state, context) => {
state.messages.push({
to: "people",
type: "greeting",
data: { msg: "hello" },
});
};
We provide helper functions on the state object for adding messages. state.addMessage() and state.add_message(), for JavaScript and Python, respectively.
const behavior = (state, context) => {
state.addMessage("people", "greeting", { msg: "hello" });
};
Previous
Next