Algorithms inside marketing agents
Step through the deterministic core behind skills, MCP tools, plugins, CLIs, agent orchestration, and governed control planes. Each animation uses marketing system shapes: campaigns, crawls, reports, tool paths, incident clusters, approvals, permission graphs, and audit logs.
Choose a visualizerFind
Binary Search
Find the first day a sorted campaign metric crosses a target without scanning every row.
1 def find_threshold_date(series, target): 2 lo, hi = 0, len(series) - 1 3 result = None 4 while lo <= hi: 5 mid = (lo + hi) // 2 6 if series[mid].value >= target: 7 result = series[mid] 8 hi = mid - 1 9 else:10 lo = mid + 111 return resultThe CPA series is sorted by date. We start with the full window and target 6.00.
A skill or MCP endpoint can answer threshold questions over long time series without spending tokens or API time on a full scan.
The Deterministic Core
The systems argument for why marketing agents need explicit algorithms for finding, exploring, ordering, routing, deduplicating, and compressing work.
The Anatomy of a Marketing Agent
How runtime, harness, tools, and permissions interact in a marketing workflow.
Secure Marketing Agents
The ad-platform source for scoped campaign-change grants, policy-gated execution, approval records, and rollback evidence in DV360 and Google Ads workflows.
From the source analysis
Where each structure sits in the agent stack
Skills
BFS, DFS, topological sort, Bloom filters, and circular buffers keep workflow steps explicit and bounded.
Tools and MCP
Binary search, heaps, Rabin-Karp, and routing algorithms make structured tool responses fast, auditable, and safe to inspect.
Plugins and Memory
Plugin packages rely on memory windows, indexes, dependency graphs, and portable execution rules.
Orchestration
Topological sort, Dijkstra, Union-Find, and lease-locked queues turn multi-agent work into schedulable, recoverable paths.
Control Plane
Approval state machines, token buckets, permission graphs, and audit hash chains enforce identity, policy, rate limits, and tamper-evident logs.
Ad platform control plane
Plan, validate, approve, execute, record
Agent drafts a change
The read-only agent proposes a structured DV360 or Google Ads diff: entity, current state, proposed state, rationale, expected impact, and risk tier.
change_plan.jsonPolicy checks scope and risk
The policy engine checks advertiser scope, max bid or budget delta, targeting breadth, workspace ownership, and same-entity write conflicts.
policy_decisionHuman signs high-risk action
Budget increases, targeting broadening, audience expansion, and tracking changes create an approval record before execution can continue.
approval_idNarrow service writes to API
The executor retrieves scoped credentials, validates current platform state, applies the approved change, and queues same-line-item DV360 writes.
execution_grantAudit captures rollback evidence
The system stores pre-image, post-image, API payload, policy result, approver, execution token, and rollback patch for review or recovery.
audit_eventScoped campaign-change grant
One action, one advertiser, one expiry window
The campaign equivalent of a scoped payment token: enough authority to apply one approved change, not broad access to the whole ad account.
{
"platform": "dv360",
"advertiser_id": "987654",
"entity_type": "line_item",
"allowed_action": "apply_bid_delta",
"max_delta_percent": 10,
"approval_id": "approval_abc"
}Implementation notes
How this mirrors the reference pattern
The published analysis provides the systems argument and the six operation model: find, explore, order, deduplicate, route, and compress. This lab turns those categories into visual states, code traces, and marketing-specific data examples you can inspect step by step and adapt to your own systems.