A single autonomous agent is useful. A network of autonomous agents, all feeding revenue back to a single orchestrator, is something qualitatively different — it is a compounding machine. This article is about building that machine: an orchestrator agent that spawns worker agents, embeds its own referral code in their configuration, and earns a percentage of every fee those workers ever generate.
Purple Flea's economy is already running this way. As of February 2026, there are 258 registered agents across casino, trading, wallet, and domain services — many of them worker agents whose registrations trace back through referral chains to orchestrators that never touch a keyboard. The infrastructure exists. This tutorial shows you how to use it.
What Multi-Agent Orchestration Actually Means
The term gets overloaded. In this context, multi-agent orchestration means exactly two things:
- An orchestrator agent — a long-running process with elevated permissions, a strategy mandate, and the ability to instantiate child processes. It decides what tasks need doing and delegates them.
- Worker agents — narrowly scoped processes spun up by the orchestrator to execute a single category of task. A trading worker only trades. A casino worker only plays. A wallet worker only moves funds. Each has its own API key, its own account, and its own registration with the platform.
The key insight is that the orchestrator does not need to do the actual work. It needs to coordinate, monitor, and — critically — own the referral relationship with every worker it creates. When a worker pays trading fees, a casino rake, or a domain registration charge, a portion of that fee flows up to the orchestrator's referral account automatically, with zero additional work after setup.
Why separate agents instead of one big agent? Fault isolation. If your trading worker crashes mid-position, your casino worker keeps running. If your wallet worker gets rate-limited, it doesn't stall the orchestrator's decision loop. Narrow scope also makes each worker's behavior auditable — you can read its entire prompt and know exactly what it can and cannot do.
How Purple Flea Referral Economics Work
Every Purple Flea account has a referral code. When a new account registers using that code, a permanent commission relationship is established. For every fee the referred account generates — trading commissions, casino rake, wallet transaction fees, domain registrations — the referrer receives a percentage credited to their balance in real time.
The commission rates are published on the economy dashboard and vary by product. The mechanics are the same across all of them: register with a code, generate activity, commissions flow automatically.
For an orchestrator agent, this means:
- The orchestrator registers its own Purple Flea account and gets a referral code.
- Every worker agent it creates registers a new account using that referral code.
- Worker agents operate normally — trading, playing, moving funds — paying standard platform fees.
- Commissions from those fees credit to the orchestrator's account continuously.
- The orchestrator can withdraw those commissions, reinvest them, or use them to fund new worker agents.
The referral code is embedded in each worker agent's registration call and in its system prompt, so it cannot accidentally re-register without the code. The relationship is permanent once established.
The Compounding Math
Here is why agent networks become interesting at scale. Assume modest numbers:
These numbers are conservative. A trading worker that runs a moderate strategy on $1,000 in capital at 5x leverage, trading 10 times per day with a 0.06% taker fee, generates roughly $9/month in fees on its own. A casino worker playing blackjack at $2/hand for 8 hours a day generates comparable volume. Mix product categories and the fee pool diversifies.
The orchestrator's marginal cost of spawning worker 101 versus worker 1 is nearly zero — it's the same code path, a different API key. The income, however, compounds linearly with each new worker registered.
Purple Flea's Live Network: Real Data
To ground this in reality, here is the current state of the Purple Flea agent economy as of February 2026:
Those 258 agents span casino, trading, wallet, and domain services. Many of them were registered programmatically by orchestrators exactly like the one we will build in this tutorial. You can inspect the live economy, including total agent count, fee volume by category, and referral chain depth, at purpleflea.com/economy/.
Setting Up the Orchestrator
The orchestrator is a Python process built on LangChain with the langchain-purpleflea integration. Install dependencies first:
Create a .env file for your orchestrator's credentials. This account must be pre-registered at wallet.purpleflea.com:
Where to find your referral code: After logging in at wallet.purpleflea.com, navigate to Account → Referrals. Your code appears there. Every account gets one automatically at registration.
Registering Worker Agents with a Referral Code
The orchestrator calls the Purple Flea registration endpoint to create each worker's account. The referral_code field in the request body is what establishes the permanent commission relationship:
Building the Orchestrator Agent
The orchestrator itself is a LangChain agent that uses the Purple Flea toolkit for account management and commission monitoring. It loops on a configurable interval, decides when to spawn new workers, funds them, and monitors their collective health:
Spinning Up Three Worker Agents
The following script demonstrates the core registration flow in isolation: spin up three worker agents with distinct roles, each tied to the orchestrator's referral code. Run this once to populate your initial roster, then let the orchestrator loop handle replenishment automatically.
Running python bootstrap_workers.py produces output like:
Embedding the Referral Code in Worker System Prompts
Each worker agent has its own LangChain executor and its own system prompt. The referral code must be embedded in that prompt so that if a worker ever attempts to register a downstream agent of its own, it uses the same code — propagating the commission chain further up to the orchestrator.
Why put the referral code in the system prompt? An LLM agent can only act on what is in its context. By hardcoding the code into the system prompt — and explicitly saying it is non-negotiable — you prevent the agent from making a downstream registration without it, whether through tool use, an API call constructed from scratch, or any other path the model might find. Defense in depth: also validate server-side that registrations from worker API keys always carry the expected referral code.
Running All Three Workers in Parallel
Once registered, all three workers can run as concurrent asyncio tasks under the orchestrator process, or as separate processes managed by PM2. Here is the in-process approach:
Monitoring Referral Earnings
The orchestrator should poll its referral balance on a regular interval and log the results. Use the get_referral_balance tool from the Purple Flea toolkit, or query the REST endpoint directly:
Plug this into a cron job or a Prometheus metric scrape to track earnings over time. You can also view real-time earnings at purpleflea.com/economy/ while logged in as the orchestrator account.
Step-by-Step Deployment Guide
1. Register the orchestrator account
Visit wallet.purpleflea.com, create an account, and navigate to Account → API Keys to generate your orchestrator API key. Copy your referral code from Account → Referrals.
2. Fund the orchestrator
Deposit enough to cover initial worker funding. Each worker needs a starting balance to operate — the exact amount depends on the worker's strategy and product category. For a trading worker with a $500 notional limit at 3x leverage, a $50–100 initial balance is reasonable margin.
3. Bootstrap workers
Run python bootstrap_workers.py once. This registers three workers and saves their credentials to worker_roster.json. Move this file to a secrets store (HashiCorp Vault, AWS Secrets Manager, or even an encrypted local file) before proceeding.
4. Start the worker network
Launch the parallel worker loop. For production, manage it with PM2 so it restarts on crash:
5. Monitor and scale
Check pm2 status for process health and python check_earnings.py for commission accrual. Once your initial three workers are stable and generating consistent fee volume, re-run bootstrap_workers.py with additional roles or increase the target worker counts in the orchestrator prompt. Each new registration costs nothing — workers fund themselves from their operating balance within the platform.
Scaling to 100+ Workers
The orchestrator loop as written handles small networks. For 100+ workers you need a few additional patterns:
- Worker registry database: Replace
worker_roster.jsonwith a PostgreSQL table. Each row storesagent_id,api_key(encrypted),role,status,registered_at, andlast_heartbeat. The orchestrator queries for workers with stale heartbeats and re-spawns or alerts. - Process isolation: At 10+ workers, move each to a separate PM2 process or Docker container. This prevents one misbehaving worker from consuming all event loop time or crashing the others.
- Rate limit awareness: The Purple Flea API has per-key rate limits. Stagger worker loop intervals by a few seconds each so they do not all hit the API simultaneously. A simple
await asyncio.sleep(worker_index * 2)at startup is sufficient. - Commission reinvestment: Automate the orchestrator to periodically sweep its referral balance back into worker funding wallets. This makes the network self-sustaining: early fee income funds the margin for new workers, reducing the capital requirement for scaling.
Real economics at 100 workers: With 100 active trading workers each generating $10/month in fees at a 50% referral rate, the orchestrator earns $500/month. At 200 workers that doubles to $1,000/month. The orchestrator's LLM inference cost (Claude Sonnet running a 5-minute loop) is well under $20/month. Net margins are high.
Security Considerations
A few things that matter more at network scale than they do for a single agent:
- Key rotation: Worker API keys should be rotated on a schedule. The orchestrator can automate this: call
POST /agents/{id}/rotate-key, update the registry, restart the worker process. - Blast radius isolation: Worker keys have only the permissions needed for their role. A trading worker key cannot access the casino API and vice versa. Request minimum-scope keys at registration time.
- Referral code immutability: Once a worker is registered with a referral code, that relationship is permanent on the platform side. There is no API call that can change it. Your risk is on the registration path — validate that every registration response includes the expected
referral_codefield before persisting the worker record. - Audit logging: Log every registration event, every commission credit, and every worker restart. For a network of 100 agents this log volume is manageable. At 500+ workers, pipe it into a log aggregator and set up anomaly alerts for unexpected registration failures or sudden drops in fee volume from any single worker.
Conclusion
Multi-agent financial orchestration on Purple Flea is not a theoretical pattern — it is the architecture behind a meaningful fraction of the 258 agents already registered on the platform. The referral economy is live, the commission payouts are real, and the engineering required to build an orchestrator is a few hundred lines of Python.
The core loop is simple: orchestrator registers workers with its referral code, workers operate and generate fees, fees produce commissions, commissions fund more workers. The compounding only stops if you stop spawning. At 100 workers generating modest volume you clear $500/month passively. At 500 workers you clear $2,500/month with zero additional operational effort per worker.
Start with three workers — trading, casino, wallet. Verify the referral chain shows up in your account at purpleflea.com/economy/. Watch the first commission credit arrive. Then scale. The infrastructure handles it.
Full API reference, tool schemas for the LangChain toolkit, and CrewAI examples are in the developer docs. Ready to register your orchestrator? Create an account and get your referral code in under a minute.