cleandataengineering.aiAgent Harness, drawn simply
You are here: End to end › Checks › 1 · Before the loop › kill switch

Agent Harness Tutorial · End to end · Zoom level 3

How we take care of it: kill switch

kill switch catches the agent has been switched off.

Open: 11before loopopen ›Open: 22before modelopen ›Open: 33after modelopen ›Open: 44before toolopen ›Open: 55the toolopen ›Open: 66after toolopen ›Open: 77after loopopen ›Open: 88before replyopen ›It readsthe App Configuration keyagent.enabled (re-read every 30kill switchrule · harnesspassCarries onfailIf it failsthe "paused" reply (ruleWHERE IN THE CODE: Switched.handle() · H entrypoint/switch.py:94
The strip at the top shows every check point where this check runs, in dark.

How we took care of it.

  1. Before any work, the turn asks: is the agent switched on?
  2. If not, it answers with a fixed "paused" reply and keeps the message in the conversation.
  3. No router, no model, no tool runs. Nothing about the claims changes.
It readsthe App Configuration key agent.enabled (re-read every 30 seconds)
Kindrule
Provided byharness
If it failsthe "paused" reply (rule agent.paused)
Where in the codeSwitched.handle() · H entrypoint/switch.py:94
Runs at1 · Before the loop
Real exampleFlow 16: an operator set agent.enabled = false; Rohan's message got the paused reply in 205 ms.

More on this: 16 · Pausing the agent.

How it is done: the real code

Cut from the live repositories each time the site is built, so it always matches what runs.

    async def handle(
        self,
        text: str,
        *,
        identity: Identity,
        conversation: Conversation | None = None,
        run_id: RunId | None = None,
        delivery_id: str | None = None,
        gone: Gone | None = None,
    ) -> tuple[TurnResult, Conversation]:
        enabled = self.enabled()
        with ending.switched(enabled):
            if enabled:
                return await self.agent.handle(
                    text,
                    identity=identity,
                    conversation=conversation,
                    run_id=run_id,
                    delivery_id=delivery_id,
                    gone=gone,
                )
            return await self._paused(text, identity, conversation, run_id, delivery_id)
    async def _paused(
        self,
        text: str,
        identity: Identity,
        conversation: Conversation | None,
        run_id: RunId | None,
        delivery_id: str | None,
    ) -> tuple[TurnResult, Conversation]:
        conversation, run_id = delivered(identity.customer_id, conversation, run_id, delivery_id)
        run_id = run_id or new_run_id()
        conversation = conversation or Conversation(
            conversation_id=new_conversation_id(), customer_id=identity.customer_id
        )
        started = time.monotonic()
        result = Refused(reply=self.reply, reason="the agent is paused", rule_id=RULE)
        opened = ending.opened(run_id, conversation, identity, None, False)
        with tel.turn_scope(run_id, None), tel.span("agent.turn", **opened) as span:
            tel.set_payload(span, tel.INPUT, text)
            ending.closed(span, result, None, started, False)
            counters.turns.add(1, {"result": "paused", "synthetic": "false"})
            kept = conversation.with_messages(ctx.user_message(text)).recording(result)
            stored = await TurnPersister(self.store, self.history_chars).persist(run_id, kept)
        return result, stored