Everyone wants a copy of the agent decisions
Once an agent starts deciding help-desk cases at Belgavi's Book Store, several teams want to see those decisions. Quality reviewers want samples for grading. The analytics team wants a daily table of decisions by category. Security wants every refund approval in an audit store. An evaluation pipeline wants the inputs and outputs to replay against a new prompt. The fastest way to satisfy all of them is to add four calls at the end of the decision handler. That is also the fastest way to make the refund path depend on the analytics database.
The Enterprise Integration Patterns catalogue describes a Wire Tap: a fixed recipient list with two outputs, which consumes a message from the primary channel and publishes it unmodified to the main channel and to a secondary channel. The value of the pattern is not the copy itself. It is the contract that the main flow does not change because the tap exists, and that observers attach to the secondary channel instead of to the handler.
Agents make that contract more important. Decision records are larger than ordinary events: a prompt version, retrieved context identifiers, tool calls, the proposed action and the final action. Observers are also more numerous and more experimental. A tap is where a team can add a new grader on Tuesday and remove it on Friday without redeploying the code that issues refunds.
Two contracts, not one
A tap can promise one of two delivery contracts, and they are built differently.
Best-effort observation. The copy may be lost under pressure. A failed or slow observer must never slow, fail or alter the main flow. Sampling for quality review and dashboards usually fits here.
Required record. The copy must exist whenever the main action happened. An audit trail of refund approvals is in this class. The record cannot be best effort, so it cannot be a side channel that drops messages when a queue is full.
The common mistake is to build the first and assume the second. A required record belongs in the same transaction as the decision, typically as an outbox row written with the decision row, then published by a relay. The best-effort tap then reads from that published stream or from an in-process buffer. Keeping the two separate prevents a familiar outage: the audit store is slow, the in-process tap blocks, and the refund path stalls because someone wanted dashboards.
How a tap ends up blocking the main flow
Tap implementations often hide a synchronous fallback. Apache Camel documents its Wire Tap as copying the exchange and sending the copy on a separate thread, which is the behaviour most people expect. The same page also documents that when the tap's thread pool is exhausted, further wire taps are executed synchronously by the calling thread. That is a sensible default for a framework that does not want to lose messages, and it is exactly the coupling a best-effort observer must avoid. The remedy Camel suggests is an explicit thread pool with a different rejection policy, a larger queue or more threads.
The same thing happens in hand-written code. An ExecutorService with a caller-runs rejection policy, a bounded queue.put without a timeout, or an HTTP client call to an observer inside the request handler all turn the observer's latency into the main flow's latency. The decision on overload has to be written down: drop the copy and count the drop, or block, and accept that observation is now on the critical path.
A tap that drops instead of blocking
The sketch below copies an immutable decision record into a bounded queue without waiting. A worker thread fans the copy out to observers. The main path does one dictionary copy and one non-blocking enqueue.
import queue, threading, copy
class WireTap:
def __init__(self, observers, capacity=1000):
self.q, self.observers = queue.Queue(maxsize=capacity), observers
self.dropped = 0
threading.Thread(target=self._run, daemon=True).start()
def publish(self, record):
try:
self.q.put_nowait(copy.deepcopy(record))
except queue.Full:
self.dropped += 1 # exported as a metric; never raised to the caller
def _run(self):
while True:
record = self.q.get()
for observe in self.observers:
try:
observe(record)
except Exception:
pass # an observer failure is the observer's problemTwo details matter. The copy is deep, so an observer that annotates the record cannot change what the main flow later reads. And the drop counter is a first-class metric: a dashboard that silently loses half its input under load is worse than one that admits it. The companion example runs a burst of synthetic decisions through a tap with a deliberately slow observer and asserts that main-path latency does not grow, while the drop counter does.
A worked example with numbers
The help desk agent decides 200 synthetic cases in a burst. A grader observer takes 50 ms per record and the tap queue holds 20 records. In the example the decisions arrive 0.01 ms apart. With the drop-on-full policy, the main path never waits: 21 copies are accepted, 20 in the queue and 1 with the grader, and the other 179 are counted as dropped. With a blocking put and the same queue, the main path waits for the grader: after the first 21 records, each new decision waits for the next 50 ms slot, so a burst that took 2 ms now ends after 8.95 seconds. Neither number is a benchmark; they follow directly from the declared timings, and the example reproduces them with a virtual clock.
Which of those two outcomes is correct depends on the observer. For sampled grading, dropping 179 of 200 records in a burst is acceptable if the sample stays unbiased. For the refund audit, neither is acceptable, which is why that record is written in the decision transaction and not through the tap.
What the tap must not do
A tap observes; it does not participate. It must not modify the record, enrich the main message, decide whether the main action proceeds or provide data the main flow reads back. If a grader's score should block an action, that grader is a step in the main flow with its own timeout and failure policy, not an observer. Mixing the roles produces a system in which a dashboard outage changes refund behaviour.
Redaction belongs at the tap boundary. Decision records often contain customer messages. Observers rarely need raw text, so publish a projection: identifiers, categories, prompt and model versions, tool names, outcome codes and hashes of large inputs. Observers that do need content, such as a replay pipeline, should read from a store with its own access control rather than from a broadcast channel.
What stays deterministic
The deterministic parts are the record schema, the projection and redaction rules, the overload policy, the drop accounting and the separation between required records and best-effort copies. The agent produces the decision; it does not decide who observes it or what they receive. Versioning the record schema lets observers evolve independently; adding a field must not break an older grader that ignores it.
Migrating from inline observer calls
- Inventory every call in the decision handler that exists only to inform another team: metrics pushes, logging of full payloads, HTTP calls to graders, writes to analytics tables.
- Classify each as best-effort or required. Move required records into the decision transaction through an outbox.
- Define one decision record schema and a redacted projection for best-effort observers.
- Replace inline calls with a single non-blocking publish to the tap, and move each observer behind it.
- Add metrics for enqueue drops, observer failures and observer lag, and an alert when drop rate exceeds what sampling tolerates.
- Load-test with a deliberately slow observer and confirm the main path latency does not move.
Failure modes
Hidden synchronous fallback. A pool that runs work on the caller when full couples the main flow to the observer. Configure the overload behaviour explicitly.
Shared mutable records. An observer that mutates the object the main flow still holds changes later decisions. Copy at the boundary.
Unbounded buffers. An unbounded tap queue turns a slow observer into memory growth and an eventual crash of the main process.
Biased samples. Dropping during bursts under-samples busy periods. If grading needs representative data, sample deterministically by case identifier before the queue instead of relying on drops.
Required data on a best-effort channel. An audit record that can be dropped is not an audit record.
When a tap is unnecessary
If one consumer needs the data and the producer already writes it durably, that consumer can read the store. If the observation is a counter or a histogram, emit a metric directly; metrics libraries already aggregate without blocking. If the platform has a durable log with independent consumer groups, each observer can subscribe to the log and the tap is the log itself. And if no one will look at the copies, do not create them: every tap is another place where customer text can leak.
Verification checklist
- Main-path latency test with a stalled observer, comparing p99 with and without the tap.
- Drop accounting test: enqueue more than capacity and confirm the counter equals the shortfall.
- Isolation test: an observer that mutates its copy does not change the main record.
- Redaction test: the published projection contains no free-text customer fields.
- Audit completeness test: every committed refund decision has exactly one outbox record, independent of the tap.