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.
How we took care of it.
- Before any work, the turn asks: is the agent switched on?
- If not, it answers with a fixed "paused" reply and keeps the message in the conversation.
- No router, no model, no tool runs. Nothing about the claims changes.
| It reads | the App Configuration key agent.enabled (re-read every 30 seconds) |
| Kind | rule |
| Provided by | harness |
| If it fails | the "paused" reply (rule agent.paused) |
| Where in the code | Switched.handle() · H entrypoint/switch.py:94 |
| Runs at | 1 · 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