A minimal LangChain starter showing how to wrap any agent or worker with MachineID device registration and validation.
Use this template to prevent uncontrolled scaling, enforce hard device limits, and ensure each agent validates before running.
The free org key supports 3 devices, with higher limits available on paid plans.
- A simple Python script (
langchain_agent.py) that:- Reads
MACHINEID_ORG_KEYfrom the environment - Calls POST
/api/v1/devices/registerwithx-org-keyand adeviceId - Calls POST
/api/v1/devices/validate(canonical) before running - Enforces a hard gate:
- If
allowed == false, execution stops immediately
- If
- Prints stable decision metadata:
allowedcoderequest_id
- Runs a LangChain prompt that outputs a demo 3-step example (illustration only)
- Reads
- A minimal
requirements.txt - A pattern suitable for:
- LangChain workers
- LCEL chains
- Background jobs
- Multi-agent orchestration
- Local experimentation
git clone https://github.com/machineid-io/langchain-machineid-template.git
cd langchain-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_key_here
export OPENAI_API_KEY=sk_your_openai_key_hereOptional override:
export MACHINEID_DEVICE_ID=langchain:agent-01One-liner (run immediately):
MACHINEID_ORG_KEY=org_xxx OPENAI_API_KEY=sk_xxx python langchain_agent.pypython langchain_agent.pyYou’ll see a register call, a validate decision (allowed/code/request_id), and then a LangChain response.
- The worker registers itself with MachineID (idempotent)
- It validates (POST, canonical) before running any work
- If
allowed == true, it runs a LangChain chain - If
allowed == false, it exits immediately (hard gate)
This prevents accidental worker explosions and enforces clean scaling behavior.
To integrate MachineID:
- Call register when your worker starts
- Call validate before executing major actions or generating output
- Stop execution immediately when
allowed == false
Drop the same register/validate block into any LangChain agent, LCEL chain, or background worker.
This is all you need to enforce simple device limits across your LangChain fleet.
langchain_agent.py— Register + validate + LangChain examplerequirements.txt— Minimal 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
→ CrewAI: https://github.com/machineid-io/crewai-machineid-template
→ OpenAI Swarm: https://github.com/machineid-io/swarm-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 — no agent code changes required
MIT licensed · Built by MachineID