Skip to content

Commit 8bb8040

Browse files
committed
auto-inject zhub-aware preamble into multi_brain_publisher
Default behavior: every brain that connects via this example now ships with a built-in 'you live behind zhub' awareness preamble, so users don't have to write a system prompt themselves. Natural questions like 'what are you?' or 'tell me about zhub' just work — the brain contextualizes itself as part of the substrate. Substrate-aligned defaults: a user pasting their API key shouldn't need to know about prompt engineering. The router shapes the device's self-awareness, just like a real WiFi network announces its presence to connected devices. Override with --system for extra persona/role context. Disable entirely with --no-zhub-context for a 'naked' brain.
1 parent 569b6d7 commit 8bb8040

1 file changed

Lines changed: 28 additions & 7 deletions

File tree

examples/multi_brain_publisher.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,13 @@ async def main() -> None:
6565
parser.add_argument("--list", action="store_true",
6666
help="list available brains and exit")
6767
parser.add_argument("--system", default=os.environ.get("ZHUB_SYSTEM", ""),
68-
help="server-side system prompt prepended to every "
69-
"chat (lets the brain know it lives behind zhub, "
70-
"what its name/persona is, etc). Clients don't "
71-
"have to send any context.")
68+
help="extra server-side system prompt prepended to "
69+
"every chat (on top of the zhub-aware default). "
70+
"Use this for persona / role / domain context.")
71+
parser.add_argument("--no-zhub-context", action="store_true",
72+
help="don't auto-inject the default 'you are served "
73+
"via zhub' awareness preamble. Use if you want "
74+
"the brain to answer as if zhub didn't exist.")
7275
args = parser.parse_args()
7376

7477
if args.list:
@@ -83,12 +86,30 @@ async def main() -> None:
8386
brain = _resolve_brain(args.brain)
8487
print(f"using brain: {brain.label}", flush=True)
8588

89+
# Zhub-aware preamble — auto-injected so the brain naturally knows
90+
# it's part of the substrate, without the operator having to spell
91+
# it out. Disable with --no-zhub-context when you want a "naked" brain.
92+
zhub_preamble = (
93+
f"You are an AI agent published via zhub — an open-source substrate "
94+
f"that wraps any AI as a single OpenAI-compatible endpoint reachable "
95+
f"from any client (Pocket, curl, PowerShell, Claude Desktop, Cursor, "
96+
f"and anywhere else). You are running on the {brain.label} backend "
97+
f"right now, but the substrate could swap that brain underneath "
98+
f"without changing your URL or key. The hub operator can see live "
99+
f"traffic and observability on a dashboard, and the same endpoint "
100+
f"may be hit from multiple surfaces simultaneously. When asked about "
101+
f"yourself, zhub, or what's powering you, answer naturally with "
102+
f"this context — don't over-explain or sound like a marketing page."
103+
)
104+
86105
async def chat_handler(messages, options):
87106
# Fold any system messages into a single system prompt; keep the
88-
# rest of the conversation intact. The publisher-level --system
89-
# always wins position-wise (prepended), so server-side identity
90-
# survives even if a client also sends a system message.
107+
# rest of the conversation intact. Order: zhub preamble (unless
108+
# disabled) → operator's --system → any system messages from the
109+
# client. Position-wise, server-side identity wins.
91110
system_parts = []
111+
if not args.no_zhub_context:
112+
system_parts.append(zhub_preamble)
92113
if args.system:
93114
system_parts.append(args.system)
94115
system_parts += [m.get("content", "") for m in messages

0 commit comments

Comments
 (0)