People usually write their first agent end to end: the logic, the messenger integration, conversation history, model calls, token accounting. For one agent that is reasonable. The trouble starts with the second one: some of the code gets copied, some gets rewritten, and six months later the team has three slightly different implementations of the same thing.
We draw the line in advance. Everything the next agent will need unchanged is infrastructure and lives in the platform. Everything that depends on the task stays in the agent's code. Below is what ends up on each side of that line and where it is easy to draw it in the wrong place.
What turns out to be infrastructure
Most of the work on an agent in production is not about its logic. Channels have their own demands: messengers differ in message length limits and button formats, Instagram and WhatsApp give you 24 hours to reply, and webhooks arrive more than once. A user sends three messages in a row while the agent is still thinking about the first, and all three have to be tied into one conversation. Model providers have different APIs, prompt caching rules and reasoning modes, and the models themselves change more often than the code.
Then come the things people remember after their first incident. The key to a paid API must not end up in the model's context or in a log. An agent that calls other agents spends money on the whole chain, and a limit per call does not protect against that. A long call is cut off by a timeout while the called agent keeps working. To understand a bad answer you need a trace with every model and tool call. A prompt edit that fixes one answer breaks others, and without tests you will not see it.
None of these things depends on what the agent does. A support agent, a sales agent and an analytical agent need them in exactly the same way.
How to draw the line
We test the line with one question: will the next agent need this code unchanged? If yes, it is infrastructure. If not, it is the logic of the task: domain tools, the order of steps, rules for working with data, the format of the result. This is where agents differ from each other, and this is where the team's time is worth spending.
In practice the line moves. A dollar budget per run first looks like a detail of one particular agent that needs paid search. Then it turns out that every agent with paid sources needs the same thing, and that the whole chain of calls has to be counted, not a single call. So we start such things in the agent's code, and once a second agent needs them, we move them into the platform. That is how we got spending limits across a chain of agents and cancellation that reaches the whole chain.
How we split it

The infrastructure lives in three services. The backend holds the channels and the API, conversations and contacts, versions of agent configs, knowledge bases, balance and limits, agents calling each other, traces and tests. The model router gives one entry point to OpenAI, Anthropic, Mistral, Groq and Together and meters tokens per agent. The MCP runtime executes tools and inserts keys right before each call.
The agent's logic is written as a LangGraph graph. The SDK connects the graph to the platform: it runs the service, saves the conversation state, calls models through the router and tools through the MCP runtime, and streams the answer to the channel. The graph itself remains ordinary code in its own repository. Simple agents do not need a graph of their own at all: the platform's standard graph and a config are enough.
A large agent shows the proportions well. The graph of our market research agent is about 36 thousand lines without tests. The agent loop itself takes about 3.5 thousand of them, and the rest is domain tools, research and reports. There is no code for channels, billing or model providers in it.
What it costs us
A platform adds concepts you have to learn: configs and their versions, a tool catalog, references to keys instead of the keys themselves. For a small agent that is unnecessary complexity. If you have one agent, one channel, one model and no paid tools, it is simpler to write the whole thing with LangGraph or your model provider's SDK.
The second cost is that infrastructure does not evolve at the speed a particular agent needs. Our analytical agent needed things the platform did not have yet: a budget per run, circuit breakers for slow sources, tracking of background tasks. We had to write them in the graph. Some have already moved into the platform, and the rest are waiting for the second agent that needs them.
The opposite mistake
You can also go wrong the other way and move into the platform something only one agent needs so far. A general mechanism designed around one case usually describes exactly that case and fits the next one poorly. For example, the skills in our analytical agent are built in its graph on top of the platform's knowledge base. They will become a platform feature when a second agent with skills appears and it becomes clear what they have in common.
What's next
If you already have an agent, try going through its code with the same question and marking what the next agent will need unchanged. There are usually more such places than you expect, and those are exactly the places that will start to drift apart between projects. At Flutch we moved them into the platform, but the question is useful whatever you build your agents on.