Agents
An agent is the thing doing the work. In MarginFront, an agent represents anything that produces billable activity — an AI agent, a microservice, a worker, a team of humans, a Lambda function, you name it. Whatever produces the usage you want to track, that’s an agent. You create an agent once. Then you attach metrics (signals) to it, attach pricing plans to it, and start logging usage events against it. Everything in MarginFront — pricing, usage tracking, invoicing — ultimately traces back to an agent.Why agents exist
A common question: “Why do I need agents at all? Can’t I just track customer usage directly?” Short answer: because a single customer might use multiple different products/services you offer, and each one might bill differently. Agents let you split that up. Example: you run an AI company with three products — a chatbot, a document analyzer, and an image generator. Each one has different costs, different pricing, and different metrics. If you just tracked “usage per customer,” you’d smoosh all three together and lose the ability to bill them differently. Instead you create three agents (chatbot, doc-analyzer, image-gen), and every usage event says “customer X used agent Y.” Now you can set different prices per agent, see per-agent profitability, and give each customer an itemized bill.
If you only have one product, you only need one agent. Still, create it — it’s the anchor everything else attaches to.
Create an agent
In plain English: Register a new agent (service, product, worker) with MarginFront so you can track and bill usage against it. Method & URL:Authorization header. See Authentication.
Required fields:
name(string, max 255 chars) — Human-readable name for the agent. Shows up in the dashboard, on reports, and on invoices.agentCode(string, max 255 chars) — A short, unique code for this agent that YOU pick. Think of it likeexternalIdfor customers — it’s the handle you’ll use to reference this agent in other API calls (especially usage events via the SDK). Pick something short and clear, likechatbot,doc-analyzer,cs-bot-v2.
description(string) — A longer explanation of what this agent does. Useful for your team’s reference.isActive(boolean, defaulttrue) — Whether the agent is currently in use. Set tofalseto retire an agent without deleting it.context(object) — Any custom key/value pairs you want to attach. MarginFront stores them but doesn’t interpret them. Good place to stash things like{ "department": "support", "tier": 1 }.
201 Created):
400 Bad Request— You’re missingnameoragentCode, or one of them is too long (255 char max). The response body tells you which.409 Conflict— An agent with thatagentCodealready exists in this org. Pick a different code, or update the existing agent.401 Unauthorized— Your API key is missing or wrong.
Read an agent
Method & URL:404 Not Found— Agent doesn’t exist in this org.
List agents
Method & URL:Update an agent
Method & URL:404 Not Found— Agent doesn’t exist.
Delete an agent
Method & URL:Usually you wantCommon errors:isActive: falseinstead of delete. SettingisActive: false(via PATCH) keeps all the historical usage data intact and just marks the agent as “no longer in use.” Deleting an agent is rare and mostly useful for cleaning up mistakes.
409 Conflict— Agent still has signals or pricing plans attached. Clean those up first.
Using the Node SDK
The SDK doesn’t have anmf.agents resource yet, but it references agents by agentCode when you log usage events:
agentCode has to match an agent you’ve already created via the admin API. If it doesn’t match anything, MarginFront will auto-create a minimal agent for you using that code — convenient for prototyping but you’ll want to go back and flesh out the agent’s name and description afterwards.
