SabaKore

Home / Articles / AI guides

Allocating Resources When Running Several AI Agents at Once

How to think about putting several AI agents with different roles on a single VPS, and how to separate them so that one running out of control doesn't drag the others down.

Ren, a junior infrastructure engineer

Ren

I want to run two AI agents, one for gathering information and one for notifications, on the same VPS. Is that a problem?
Procura, a cloud AI robot who explains

Procura

Putting them together on one machine is perfectly common. But even if you build them to run independently, keep in mind that on the same VPS they end up competing for resources.

What competing for resources means

  • Several agents share the same CPU and memory
  • While one is doing heavy processing, the other may respond more slowly
  • If one behaves abnormally, it can affect the other's operation too
Ren, a junior infrastructure engineer

Ren

Would it be better to run them independently?
Procura, a cloud AI robot who explains

Procura

Splitting them across machines is one option, but it raises costs. There's also a way to keep them together while making them less likely to affect each other. You use a mechanism that sets limits on memory and CPU for each agent separately.

Separating them while keeping them together

With container technology, you can set separate resource limits for each agent even within a single VPS. Even if one runs out of control unexpectedly and tries to use up all the memory, it can only use up to its allotted limit, so the other keeps running unaffected. If you're going to put them together, design this separation in from the start.

  • Put each agent in its own container and set limits on the resources it can use
  • Give a more generous limit to the more important one
  • Even if one goes down, keep the others running

Separate the places logs go too

Besides resources, separating where records go also helps when trouble occurs. If you put the logs of several agents into one file, then when you want to investigate abnormal behavior in one, the other's records get in the way and make it hard to read. If you keep records separate for each agent, isolating the cause goes that much faster.

  • Use a separate log destination for each agent
  • Make it clear from the file name which agent a record belongs to
  • Also prepare a common notification destination that picks up only serious abnormalities together
Procura, a cloud AI robot who explains

Procura

Putting them together isn't a bad choice. Just drop the assumption that they're independent, and design on the premise that they share resources on the same footing.
Ren, a junior infrastructure engineer

Ren

If more agents are likely to come later, should I split the machines from the start?
Procura, a cloud AI robot who explains

Procura

You don't need to force a split from the start. Set up the separation mechanism on one machine first, and then split across machines when resources truly run short. That order is often early enough.

The startup order matters more than you'd think

In a setup where several agents start at the same time, one may need to wait for the other to be ready before it starts running. If you configure everything to start at once without thinking about this order, it can lead to hard-to-understand problems, like errors that appear only right after startup. If there are dependencies, prepare both the startup order and a mechanism that waits until the other side is ready.

  • Sort out in advance whether the agents depend on each other
  • Add a mechanism that waits until what they depend on is ready before starting
  • If an error appears only right after startup, suspect an ordering problem
Ren, a junior infrastructure engineer

Ren

If you put them together, decide each one's limits first.

This article is translated from the Japanese original. If the two differ, the Japanese version is the one we keep up to date.