General questions about agents

I am eagerly awaiting delivery of two imps and in the mean time I have a few questions about the agent/imp relationship

If I have both imps in the same model (I hope I’m using the right terminology here) then does that mean there will be two instances of the agent code running on the cloud? Or will there be one instance that communicates with both imps? I can see either way as being useful in various situations. Is it possible to choose how many agent instances are running?

Also, if I have both imps in the same model does that mean they will be running the same device code or can I have them running different device code while still talking to the same agent?

I can’t seem to find the answers to this sort of question anywhere in the documentation and I’ve looked through quit a lot so far.

1 imp = 1 device = 1 agent = 1 AgentUrl
2 imps = 2 devices = 2 agents = 2 AgentUrls
you can assign 1 model to more imps, but they don’t share any data, only the code

Each device – ie. imp + gadget it gives connectivity to – has its own, unique agent. If both devices are set to the same model, there will be two instances of the model’s agent code, one for each device.

Depending upon how you plan to use then, there’s no reason the two agents can’t be coded to identify one to the other. Both have unique URLs, which can be discovered by each instance using the http.agenturl() API method.

If you want each device to run different code, but have both connect to the same agent code, you need to create two models with identical agent code, but different device code.

Ok, that makes more sense now. Thanks for the help

Another question occurs…

My imps power up and connect to the agent, transfer some data and then the imps disconnect for 1 minute (to conserve battery power) and reconnect. Does this cause the agent to be destroyed and re-created when the reconnect happens? If not then how long does the agent stay alive for after the disconnect happens?

My understanding of the agent’s scope of operation is full of holes it seems :slight_smile:

Is there any good documentation describing this anywhere?

The agent stays alive continually. If it’s not actually processing anything, the server will do things like reduce the agent’s virtual CPU speed, but the agent always stays sufficiently awake to monitor for incoming external HTTP requests and for communication from the agent. There are tools you can use to tell the agent your device is going to sleep for a time, and this helps it use resources more efficiently for that period.