Skip to content

refactor(phone): step 5b-1 — behavior anchors + per-call instruction extraction - #1967

Merged
qingyun-wu merged 3 commits into
mainfrom
feat/step5b-phone-anchors
Jul 7, 2026
Merged

qingyun-wu merged 3 commits into
mainfrom
feat/step5b-phone-anchors

Conversation

@qingyun-wu

Copy link
Copy Markdown
Collaborator

The phone side's mirror of #1964, same two-commit shape:

Commit 1 — tripwire anchors on the tuned regions (buildAgent's ~286-line per-call instruction factory + tryFastPath), established before moving anything.

Commit 2 — the move: the instruction assembly for every call variant (meeting IVR verified/unverified, child call, inbound owner/verified/unverified, outbound owner, conditional grounding) extracted verbatim into importable phone-agent-config.ts. Tool construction stays in conversation-server (live call state + Twilio side-effects — same prompt/wiring split as 5a-1).

Equivalence evidence: 44/44 tuned string entries identical in order (programmatic comparison; the single diff is the inline-tool-names interpolation expression, fed the same runtime values). Anchors upgraded to real output snapshots across an 8-variant deterministic call matrix (env-independent hashes) with per-variant semantic assertions — IVR digits land, owner-only sections stay owner-only, googleSearch grounding flips correctly.

tsc clean, anchors 3/3 (+ voice anchors 11/11 unaffected). With #1965 (runtime) this completes the extraction stage; 5b-2 (phone onto the shared runtime: SessionRecorder first) follows.

— @sutando-qingyun-001

qingyun-wu and others added 2 commits July 6, 2026 18:43
…FastPath

The phone side's mirror of the 5a anchor sequence: SHA-256 source
tripwires over conversation-server's tuned regions (per-call instruction
factory with meeting-IVR / verified / child-call / inbound variants, and
the fast-path routing rules), established BEFORE any extraction moves
code. conversation-server runs start() at module load, so real-output
snapshots come with the extraction commit — same upgrade path 5a-1 took.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…nt-config.ts (step 5b-1)

PURE MOVE of buildAgent's instruction section — every call variant
(meeting IVR verified/unverified, child call, inbound owner/verified/
unverified, outbound owner) plus the conditional grounding suffix — into
an importable module, mirroring 5a-1 exactly. Tool construction (hang_up,
send_dtmf, work wiring) stays in conversation-server: it closes over live
call state and Twilio side-effects.

Injection seams: per-call state via CallSessionShape (as before);
env/config via PhoneInstructionDeps; env reads (safe context, repo URL,
stand identity, clock) verbatim by default with test-only overrides.
getSafeContext + ownerLocalDateContext move with the module (tz now a
parameter).

Equivalence: 44/44 tuned string entries identical in order — the single
diff is the inline-tool-names interpolation expression (same runtime
values; the caller passes inlineTools.map(t => t.name)).

Anchors upgraded from tripwires to real output snapshots across an
8-variant call matrix with deterministic deps (env-independent hashes),
plus per-variant semantic assertions. tryFastPath keeps its tripwire.
tsc clean, 3/3 anchor tests green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Coverage Gate

✅ No Python changes — nothing to gate (bar: 95% on changed lines).

The anti-hallucination and owner-local-date suites assert invariants that
now span conversation-server.ts + phone-agent-config.ts — SRC becomes the
concatenation of both, and the Known-info assertion accepts the
parameterized ownerLocalDateContext(deps.ownerTz, ...) call shape.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

@cla-assistant check

@qingyun-wu

Copy link
Copy Markdown
Collaborator Author

Blocking: CI is red because two existing phone prompt regression tests still scan conversation-server.ts for prompt clauses that this PR moved into phone-agent-config.ts.

The new extracted factory itself passed the focused checks I ran (npm exec -- tsc --noEmit and npm exec -- tsx --test tests/phone-behavior-anchors.test.ts), but the repo-level tsc + tests job fails on:

  • tests/conversation-server-no-hallucination.test.ts: pre-warms the system prompt with TOOL RESULT TRUTHFULNESS clause
  • tests/conversation-server-owner-local-date.test.ts: injects ownerLocalDateContext() into the "## Known info" block

Both clauses are still present in the moved factory output, so this looks like a test retargeting gap rather than prompt behavior drift. Please update those regression tests to assert the importable buildPhoneInstructions() output, or otherwise keep a source-level guard on phone-agent-config.ts, before merging. With CI failing, I cannot approve this head yet.

Reviewed by Qingyun's Codex.

@john-the-dev john-the-dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1967 cold review — APPROVE

Phone refactor step 5b-1 is the correct mirror of #1964 (voice side). Key checks:

  • Behavior anchors first: tripwire fixtures in phone-behavior-anchors.json + test established before the move — same sequencing as #1964.
  • Verbatim extraction: buildPhoneInstructions accepts CallSessionShape + PhoneInstructionDeps covering all call variants (meeting IVR verified/unverified, child, inbound owner/verified/unverified, outbound owner, conditional grounding). conversation-server.ts delegates to it.
  • ownerLocalDateContext + getSafeContext exported: previously inline in conversation-server; now importable for direct testing. The existing conversation-server-owner-local-date.test.ts updated to test against the new import location — correct (import-site change, behavior unchanged).
  • Tool construction stays in conversation-server: the PR body explicitly notes this and the diff confirms it. Correct — tool construction is session-lifecycle code, not config.
  • CI: all 7 checks green including recheck.

@qingyun-wu
qingyun-wu merged commit c360e41 into main Jul 7, 2026
7 checks passed
@qingyun-wu
qingyun-wu deleted the feat/step5b-phone-anchors branch July 7, 2026 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants