psyche-ai 9.1.1 → 9.1.2

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.
@@ -7,7 +7,7 @@
7
7
  // const server = createPsycheServer(engine, { port: 3210 });
8
8
  //
9
9
  // Endpoints:
10
- // POST /process-input { text, userId? } → { systemContext, dynamicContext, stimulus }
10
+ // POST /process-input { text, userId? } → { systemContext, dynamicContext, stimulus, policyModifiers?, policyContext }
11
11
  // POST /process-output { text, userId? } → { cleanedText, stateChanged }
12
12
  // GET /state → PsycheState
13
13
  // GET /protocol?locale=zh → { protocol }
package/dist/core.d.ts CHANGED
@@ -33,6 +33,20 @@ export interface ProcessInputResult {
33
33
  stimulus: StimulusType | null;
34
34
  /** v9: Structured behavioral policy modifiers — machine-readable "off baseline" signals */
35
35
  policyModifiers?: PolicyModifiers;
36
+ /**
37
+ * v9: Ready-to-use LLM prompt fragment summarizing current behavioral policy.
38
+ *
39
+ * This is the output of `buildPolicyContext(policyModifiers, locale)` —
40
+ * a human-readable string like "[行为策略] 简短回复、被动应答为主".
41
+ * Inject this into the LLM system prompt directly.
42
+ *
43
+ * Empty string when all modifiers are at baseline (no deviations to report).
44
+ *
45
+ * Note: `dynamicContext` already includes this text. This field is provided
46
+ * separately for callers who build their own prompt and only need the policy
47
+ * fragment without the full emotional context.
48
+ */
49
+ policyContext: string;
36
50
  }
37
51
  export interface ProcessOutputResult {
38
52
  /** LLM output with <psyche_update> tags stripped */
package/dist/core.js CHANGED
@@ -427,6 +427,7 @@ export class PsycheEngine {
427
427
  }),
428
428
  stimulus: appliedStimulus,
429
429
  policyModifiers,
430
+ policyContext: policyCtx,
430
431
  };
431
432
  }
432
433
  return {
@@ -443,6 +444,7 @@ export class PsycheEngine {
443
444
  }),
444
445
  stimulus: appliedStimulus,
445
446
  policyModifiers,
447
+ policyContext: policyCtx,
446
448
  };
447
449
  }
448
450
  /**
@@ -66,5 +66,25 @@ export declare function computePolicyModifiers(state: PsycheState): PolicyModifi
66
66
  /**
67
67
  * Build a compact policy summary string for prompt injection.
68
68
  * Only includes significant deviations from neutral policy.
69
+ *
70
+ * **This is the recommended path for integrating PolicyModifiers into LLM prompts.**
71
+ *
72
+ * The returned string is designed to be injected directly into the LLM's
73
+ * system/dynamic context. Do NOT self-interpret the raw PolicyModifiers
74
+ * numbers with if-else logic to make hard-coded decisions — that bypasses
75
+ * the LLM's narrative reasoning and degrades output quality.
76
+ *
77
+ * Correct usage:
78
+ * const result = await engine.processInput(text);
79
+ * // Inject result.policyContext (or result.dynamicContext which already
80
+ * // includes it) into the LLM prompt. Let the LLM interpret the policy.
81
+ *
82
+ * Anti-pattern (leads to LLM bypass):
83
+ * if (result.policyModifiers.proactivity < 0.3) { pickAction("wait"); }
84
+ * // ^ This replaces LLM reasoning with hard-coded logic.
85
+ *
86
+ * Raw policyModifiers are exposed for mechanical enforcement only
87
+ * (e.g., clamping max_tokens, requiring UI confirmation dialogs) —
88
+ * not for replacing the LLM's decision-making.
69
89
  */
70
90
  export declare function buildPolicyContext(modifiers: PolicyModifiers, locale: Locale): string;
@@ -365,6 +365,26 @@ export function computePolicyModifiers(state) {
365
365
  /**
366
366
  * Build a compact policy summary string for prompt injection.
367
367
  * Only includes significant deviations from neutral policy.
368
+ *
369
+ * **This is the recommended path for integrating PolicyModifiers into LLM prompts.**
370
+ *
371
+ * The returned string is designed to be injected directly into the LLM's
372
+ * system/dynamic context. Do NOT self-interpret the raw PolicyModifiers
373
+ * numbers with if-else logic to make hard-coded decisions — that bypasses
374
+ * the LLM's narrative reasoning and degrades output quality.
375
+ *
376
+ * Correct usage:
377
+ * const result = await engine.processInput(text);
378
+ * // Inject result.policyContext (or result.dynamicContext which already
379
+ * // includes it) into the LLM prompt. Let the LLM interpret the policy.
380
+ *
381
+ * Anti-pattern (leads to LLM bypass):
382
+ * if (result.policyModifiers.proactivity < 0.3) { pickAction("wait"); }
383
+ * // ^ This replaces LLM reasoning with hard-coded logic.
384
+ *
385
+ * Raw policyModifiers are exposed for mechanical enforcement only
386
+ * (e.g., clamping max_tokens, requiring UI confirmation dialogs) —
387
+ * not for replacing the LLM's decision-making.
368
388
  */
369
389
  export function buildPolicyContext(modifiers, locale) {
370
390
  const parts = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "psyche-ai",
3
- "version": "9.1.1",
3
+ "version": "9.1.2",
4
4
  "description": "Artificial Psyche — universal emotional intelligence plugin for any AI agent",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",