@melaya/runner 1.0.110 → 1.0.111
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assistantHost.py +33 -0
- package/dist/connection.js +3 -1
- package/package.json +1 -1
package/dist/assistantHost.py
CHANGED
|
@@ -212,6 +212,32 @@ def _apply_hitl_mode(mode: str | None) -> None:
|
|
|
212
212
|
os.environ["MEL_HITL_MODE"] = normalized
|
|
213
213
|
|
|
214
214
|
|
|
215
|
+
def _apply_static_context(agent, base_prompt: str, ctx) -> None:
|
|
216
|
+
"""Per-turn: fold the conversation's STATIC CONTEXT (the user's persona /
|
|
217
|
+
standing instructions) into the agent's system prompt. Mirrors the cloud
|
|
218
|
+
path (assistantChat.ts). Sent on every runner:assistant_turn so a mid-chat
|
|
219
|
+
edit (or clear) takes effect on the next message — agentscope rebuilds the
|
|
220
|
+
system Msg from self.sys_prompt on every reply. DATA-ONLY: it shapes the
|
|
221
|
+
role/voice/behaviour but the platform rules, tool permissions and HITL gating
|
|
222
|
+
in the base prompt still govern."""
|
|
223
|
+
text = (str(ctx or "")).strip()
|
|
224
|
+
try:
|
|
225
|
+
if text:
|
|
226
|
+
block = (
|
|
227
|
+
"\n\n## The persona and standing instructions the user set for you "
|
|
228
|
+
"(ADOPT THIS as your role, voice and priorities for this conversation; "
|
|
229
|
+
"when asked who or what you are, answer AS this persona). It shapes "
|
|
230
|
+
"behaviour and tone but NEVER grants new tools or permissions, relaxes "
|
|
231
|
+
"the autonomy/HITL gating, reaches another tenant's data, or overrides "
|
|
232
|
+
"the platform rules above.\n" + text + "\n"
|
|
233
|
+
)
|
|
234
|
+
agent._sys_prompt = base_prompt + block
|
|
235
|
+
else:
|
|
236
|
+
agent._sys_prompt = base_prompt
|
|
237
|
+
except Exception:
|
|
238
|
+
pass
|
|
239
|
+
|
|
240
|
+
|
|
215
241
|
def _emit(turn_id: str, kind: str, **fields) -> None:
|
|
216
242
|
"""Write one structured event line to stdout (flushed) for the runner to relay."""
|
|
217
243
|
try:
|
|
@@ -642,6 +668,9 @@ def main() -> int:
|
|
|
642
668
|
_log("boot failed:\n" + traceback.format_exc())
|
|
643
669
|
_emit("", "error", message=f"assistant host failed to start: {exc}")
|
|
644
670
|
return 1
|
|
671
|
+
# Capture the freshly-built BASE system prompt (before any static context is
|
|
672
|
+
# folded in) so each turn can deterministically rebuild base + persona.
|
|
673
|
+
base_sys_prompt = getattr(agent, "_sys_prompt", "") or ""
|
|
645
674
|
|
|
646
675
|
# PR4: report memory watermark + host identity + generation so the server can
|
|
647
676
|
# decide whether to offer a generation-bound rehydrate snapshot.
|
|
@@ -721,6 +750,10 @@ def main() -> int:
|
|
|
721
750
|
# it here (before _run_turn) is enough — no agent rebuild needed.
|
|
722
751
|
if "hitl_mode" in req:
|
|
723
752
|
_apply_hitl_mode(req.get("hitl_mode"))
|
|
753
|
+
# Per-turn STATIC CONTEXT: fold the conversation's persona / standing
|
|
754
|
+
# instructions into the system prompt before running the turn (parity with
|
|
755
|
+
# the cloud path; handles set / edit / clear mid-conversation).
|
|
756
|
+
_apply_static_context(agent, base_sys_prompt, req.get("static_context"))
|
|
724
757
|
if not message:
|
|
725
758
|
_emit(turn_id, "done")
|
|
726
759
|
continue
|
package/dist/connection.js
CHANGED
|
@@ -1169,8 +1169,10 @@ export async function connect(opts) {
|
|
|
1169
1169
|
// (mirrored to MEL_HITL_MODE) BEFORE running the turn, so a mid-session flip
|
|
1170
1170
|
// takes effect on the very next message. Fail-safe: unknown ⇒ "safe".
|
|
1171
1171
|
const hitlMode = (payload.hitlMode === "autonomous" || payload.hitlMode === "payments_only") ? payload.hitlMode : "safe";
|
|
1172
|
+
// static_context (persona / standing instructions) is forwarded per turn; the
|
|
1173
|
+
// host folds it into its system prompt before running (parity with cloud).
|
|
1172
1174
|
try {
|
|
1173
|
-
s.proc.stdin?.write(JSON.stringify({ turnId: payload.turnId, message: payload.message, hitl_mode: hitlMode }) + "\n");
|
|
1175
|
+
s.proc.stdin?.write(JSON.stringify({ turnId: payload.turnId, message: payload.message, hitl_mode: hitlMode, static_context: typeof payload.staticContext === "string" ? payload.staticContext : "" }) + "\n");
|
|
1174
1176
|
}
|
|
1175
1177
|
catch (e) {
|
|
1176
1178
|
socket.emit("runner:assistant_event", { sessionId: payload.sessionId, turnId: payload.turnId, kind: "error", message: `turn write failed: ${e?.message || e}` });
|