# Keyless stand-in router

A drop-in for any open agentic website built with the
[agentify-website](https://github.com/cognizant-ai-labs/agentic-web/tree/main/skills/agentify-website)
runtime. It lets a visitor (or a judge) try the site's **real** agent network, **real**
`website_*` tools, **real** consent cards and confirmation dialogs with **no AI key and no
server**.

It is not a language model. A service worker answers the runtime's OpenAI-compatible
`/chat/completions` requests with tool calls and answers planned by small rule packs, one
per agent. Everything else, the network file, the runtime, the tools, the partner calls,
is the same code that runs with a real model. When the visitor adds a key, the runtime
switches to their provider and the stand-in is no longer used.

## Why

Most visitors and judges arrive without an AI key. Without one, the chat on an agentic
website is a dead box, so nobody sees the agents work. A mock that echoes tool output
(`browser://mock`) does not show anything a person would recognise. A publisher-paid
proxy costs money and needs a server. The stand-in is the middle: free, static, honest
about what it is, and good enough for the questions on your page.

## Files

| File | What it does |
| --- | --- |
| `../stand-in-sw.js` | The service worker. Put it at the site root (its scope must cover the page). It loads the engine and your rule packs with `importScripts`. |
| `engine.js` | Parses the runtime's request (instructions, the visitor's message, this turn's tool results), picks a pack by a pattern on the agent's instructions, and streams the reply as server-sent events in the OpenAI shape. A generic pack handles agents with no pack, from their tool schemas (see below). |
| `rules-yakguk.js` | Yakguk's packs, as a worked example: keyword rules that choose a tool and write the answer from its result. |

## Use it on your site

1. Copy `stand-in-sw.js` to your site root and `stand-in/engine.js` next to it. Write a rule
   pack (copy `rules-yakguk.js`; a pack is `{name, match(ctx), plan(ctx)}` and returns
   `StandIn.call(tool, args)` or `StandIn.say(markdown)`), and list it in `importScripts`.
2. In `agent-manifest.json`:

   ```json
   "llm_router": {
     "base_url": "./stand-in/v1",
     "publisher_funded": true,
     "mock": false,
     "byok_router": "https://api.otari.ai/api/v1"
   }
   ```

   `publisher_funded` makes the runtime call `base_url` without a key (spec §4, default
   inference). It never sends a visitor's key there.
3. Register the service worker before the runtime boots and wait until it controls the
   page (see `startStandIn()` in `../site.js`).
4. Say what it is. `../site.js` relabels the runtime's "In use" line and model badge to
   "keyless stand-in (not AI)", and every stand-in answer ends with a note that tells the
   visitor to add a key for full conversation.

## When another site calls yours

A caller runs your network on **its** router. If the caller is on a stand-in too, its
service worker has no rules for your agents, so the generic pack plans for them from your
tools' JSON Schemas alone: it picks the tool whose name and description share the rarest
words with the request, fills enum fields with the values the request names and search
fields with its key terms, and reports the tool's `summary` and first rows. If a better
tool needs inputs only a model could pick out (a list of medicine names, say), it says so
instead of answering with a weaker tool. The Lantern Guesthouse demo works this way: it
has its own pack for its front desk and none for Yakguk. With a real key on the caller,
your network runs on the caller's model as usual.

So: write clear tool names and descriptions, and use `enum` for fields with a fixed set of
values. That helps real models too.

## Limits

- Rule packs understand only what you wrote rules for. Keep the page's example questions
  inside them, and let anything else get a plain "add a key" answer.
- Service workers need HTTPS (or localhost) and are off in some private-browsing modes.
  Without one the chat asks for a key, as it would anyway.
- The runtime's agent panel still names the network's model in some places; the label
  fixes in `site.js` cover the "In use" line and the badge.

MIT license.
