A minimal OpenAI Swarm starter showing how to wrap your workers with MachineID device registration and validation.
Use this template to prevent runaway agents, enforce hard device limits, and ensure every Swarm worker checks in before doing work.
The free org key supports 3 devices, with higher limits available on paid plans.
OpenAI Swarm and supporting libraries can depend on packages that do not support Python 3.13+ yet.
To avoid installation errors, the safest recommended environment is:
python3.11 -m venv venv
source venv/bin/activate
pip install -r requirements.txtPython 3.11 is the most stable choice for Swarm today.
-
swarm_agent.py:- Reads
MACHINEID_ORG_KEYfrom the environment - Uses a default
deviceIdofswarm:worker-01(override withMACHINEID_DEVICE_ID) - Calls POST
/api/v1/devices/registerwithx-org-keyand adeviceId - Calls POST
/api/v1/devices/validate(canonical) before running Swarm - Enforces a hard gate:
- If
allowed == false, execution stops immediately
- If
- Prints stable decision metadata:
allowedcoderequest_id
- Reads
-
requirements.txt:git+https://github.com/openai/swarm.gitrequests
This mirrors the same register + validate pattern used in the Python, LangChain, and CrewAI templates.
git clone https://github.com/machineid-io/swarm-machineid-template.git
cd swarm-machineid-templatepython3.11 -m venv venv
source venv/bin/activate
pip install -r requirements.txtVisit https://machineid.io
Click “Generate free org key”
Copy the key (it begins with org_)
export MACHINEID_ORG_KEY=org_your_org_key_here
export OPENAI_API_KEY=sk_your_openai_key_hereOptional override:
export MACHINEID_DEVICE_ID=swarm:worker-01One-liner (run immediately):
MACHINEID_ORG_KEY=org_xxx OPENAI_API_KEY=sk_xxx python3.11 swarm_agent.pypython3.11 swarm_agent.pyYou will see:
- A register call with plan + usage summary
- A validate decision (
allowed/code/request_id) - Either an immediate stop (not allowed) or a Swarm-generated output
- The worker registers itself with MachineID (idempotent)
- It validates (POST, canonical) before running any work
- If
allowed == true, it runs the Swarm workflow - If
allowed == false, it exits immediately (hard gate)
This ensures every worker checks in before running and keeps scaling safely controlled.
To integrate MachineID:
- Call register when your worker starts
- Call validate:
- Before each Swarm run
- Before major tasks
- Or periodically for long-running agents
- Stop execution immediately when
allowed == false
Drop the same register/validate block into any Swarm worker, agent, or background process.
swarm_agent.py— Swarm starter with MachineID register + validaterequirements.txt— DependenciesLICENSE— MIT licensed
Dashboard → https://machineid.io/dashboard
Generate free org key → https://machineid.io
Docs → https://machineid.io/docs
→ Python starter: https://github.com/machineid-io/machineid-python-starter
→ LangChain: https://github.com/machineid-io/langchain-machineid-template
→ CrewAI: https://github.com/machineid-io/crewai-machineid-template
- Plans are per org, each with its own
orgApiKey - Device limits apply to unique
deviceIdvalues registered via/api/v1/devices/register - Plan changes take effect immediately — workers do not need new code
MIT licensed · Built by MachineID