Failred to push messages between agents

going through the Alice and Bob tutorial. Simply trying to pass messages and change color upon receipt…

  1. Cant see messages for Alice in Raw Data for every step of the simulation
  2. Cannot change color for Alice or Bob, despite seeing messages in Bob
  3. Shouldnt I see Bob’s message in Alice’s message array?

Code below, any ideas why I am stuck?

`[
{
“agent_name”: “Alice” ,
“position”: [0,10] ,
“behavior”:[“hello_alice.js”]

},
{
“agent_name”: “Bob”,
“position”: [10,0],
“behaviors”: [“hello_bob.js”]
}
]

//(hello_Alice.js)

function behavior(state, context) {

let greetings = context.messages().filter(msg => msg.type === “greeting”);

if (greetings.length > 0) {

state.set("color", "blue");

}

let messages = state.get(“messages”)

messages.push({

    to: "Bob",

    type: "greeting",

    data: {

        "msg":"hello to you too"

    }

});



state.set("messages", messages)

}

(hello_bob.js)

function behavior(state, context) {

let greetings = context.messages().filter(msg => msg.type === “greeting”);

if (greetings.length > 0) {

state.set("color", "yellow");

}

let messages = state.get(“messages”)

messages.push({

    to: "Alice",

    type: "greeting",

    data: {

        "msg":"helllo"

    }

});



state.set("messages", messages)

}
`

Hello,

It looks like you have a typo in your agent definition for Alice. You’ve given the agent a behavior field instead of a behaviors field. Your agent definition for Alice should actually look like:

{
  “agent_name”: “Alice” ,
  “position”: [0,10] ,
  “behaviors”:[“hello_alice.js”]
}

Making that change should solve your first 2 issues. The answer to your third question is actually no, since incoming messages aren’t stored on the agent, they’re stored in the context, which is served to the agent at the beginning of each step. If you wanted to see the incoming messages you could print them to the console with console.log(context.messages()).

-Nur