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 visualizer

Find

Binary Search

Find the first day a sorted campaign metric crosses a target without scanning every row.

1/7
AnimationInitial bounds
target CPA 6.00 Mar 01 4.20 0 Mar 02 4.55 1 Mar 03 5.10 2 Mar 04 5.80 3 Mar 05 6.25 4 Mar 06 7.40 5 Mar 07 7.10 6
lo: 0 mid: - hi: 6 result: -
Reference codeO(log n)
 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 result
Current step

The CPA series is sorted by date. We start with the full window and target 6.00.

Why it helps LLM apps

A skill or MCP endpoint can answer threshold questions over long time series without spending tokens or API time on a full scan.

Sources

The Deterministic Core

The systems argument for why marketing agents need explicit algorithms for finding, exploring, ordering, routing, deduplicating, and compressing work.

Read algorithms essay

The Anatomy of a Marketing Agent

How runtime, harness, tools, and permissions interact in a marketing workflow.

Read control-plane article

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.

Read security architecture

From the source analysis

Where each structure sits in the agent stack

01

Skills

BFS, DFS, topological sort, Bloom filters, and circular buffers keep workflow steps explicit and bounded.

02

Tools and MCP

Binary search, heaps, Rabin-Karp, and routing algorithms make structured tool responses fast, auditable, and safe to inspect.

03

Plugins and Memory

Plugin packages rely on memory windows, indexes, dependency graphs, and portable execution rules.

04

Orchestration

Topological sort, Dijkstra, Union-Find, and lease-locked queues turn multi-agent work into schedulable, recoverable paths.

05

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

01
Plan

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.json
02
Validate

Policy 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_decision
03
Approve

Human signs high-risk action

Budget increases, targeting broadening, audience expansion, and tracking changes create an approval record before execution can continue.

approval_id
04
Execute

Narrow 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_grant
05
Record

Audit 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_event

Scoped 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

01

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.