Agent Code structure and flow?

Whereas the wiki describes Code structure and flow for the imps there isn’t too much in the way of conceptual description of Agents. Observing my Agents they obviously don’t sleep like an imp but they idle for events. Assuming my assumptions are correct I’ve drawn an Agent sate diagram to reflect my understating?

A few questions though

  1. On an imp: "Only one event handler can execute at a time, so colliding events will be queued."
    Is this the case for Agents?

  2. What is buffer sizes for inbound
    a: http requests
    b: devcie.on requests

  3. It’s still not clear to me under what conditions an Agent re-starts.

Thanks as always

I am also interested in the answer to this. At the moment, my mental picture is that the “Boot” process is triggered by the imp powering up and connecting to the cloud server on its own. The server then instantiates the agent and gives it control.

  1. Is this a valid assumption?
  2. What happens if the server reboots? Does it automatically reinstantiate agents that were up at the time?


  1. Just the same as an imp; only one thing can run at any time. Events that need processing will get queued.

  2. There’s no specific set buffer size, but the agent has a memory limit; currently this is 1MB (and you can read free memory just as you can with the imp), but it is subject to change as we scale and determine the sweet spot for well behaved applications.

  3. Agents can restart for various reasons: runtime errors (like an imp), or when the VM restarts (often during beta), or when we migrate the agent to another server. For orderly moves, agents will get a shutdown notification allowing them to save state data before they are killed and restarted elsewhere.


  1. Yes.
  2. Yes, it will restart the agents that were running before shutdown.

Hugo thanks, Just one more …

Will a imp warm re-boot load & run a pending Agent update?

Updated digram attached.

There shouldn’t be pending agent updates - when you hit run, it should restart the agent with the new code immediately?

Ok all my imps are deep sleeping the Agent will only update when I comment out the server sleepfor and cold boot.

Also when you “Run” a update to an Agent and the imp is offline the Agent won’t update till the imp is back on-line.

I believe the deepsleep not Agent update is a bug. But the imp offline then updating makes sense & so there’s a sort of pending state between hitting ide-run & imp coming on-line.

Ah, yes. That is indeed a bug - agents don’t get updates unless the imp is online. It’s not meant to be like that though :slight_smile: