Repository navigation
Contract Message Protocol
This is the logical turn protocol layered on Contract-WebSocket-API. A frontend agent should implement the frame shapes from the WebSocket contract and the lifecycle below together.
- Frontend sends
user_messagewith{ text, turnIndex, inputMethod }. - Agent may stream repeated
agent_tokenframes with{ turnIndex, token, isFinal: false }. - Agent sends one
agent_turn_completewith{ turnIndex, fullText, tokenCount, sessionTokenTotal, sessionTurnTotal }. - Frontend replaces progressive text with
fullText. - Frontend synthesizes voice via Contract-Polly-TTS.
- Frontend updates local counters and mouth animation.
| Moment | Required behavior |
|---|---|
session_start |
Select greeting from Contract-Greeting-Manifest, open WebSocket, send session_start, play pre-generated greeting immediately, show buffering until connection_ack. |
| user input | Client-side rate-limit check, increment turn index, send user_message, set “thinking” UI, watch latency timer. |
agent_token |
Append payload.token to current broadcast text and reset timeout. |
agent_turn_complete |
Replace progressive text with payload.fullText, trigger Polly audio/viseme requests, sync counters from payload. |
| interruption | Stop current audio immediately, clear/leave partial text per UX, send interrupt, then send new user_message with incremented turn index. |
session_state_change |
Transition frontend state unconditionally to payload.newState. |
| Frame | Required agent behavior |
|---|---|
session_start |
Create/load session, bind actorId, load memory namespace /max-height/{actorId}/, initialize personality prompt, send connection_ack with agentCoreSessionId. |
user_message |
Enforce 50 turns, 20,000 tokens, and 30 minutes; run Strands pipeline; call tools for news/weather/web search when needed; stream tokens; post-process personality/stutters; send agent_turn_complete. This is the contract, not the live HTTP behavior (#42, #45, #55). |
interrupt |
Cancel current generation if possible and remember interruption context for the next response. |
| caps/rate/budget | Send in-character final/error text, then session_state_change to ENDED, RATE_LIMITED, or BUDGET_CAPPED. |
Tool results are not separate wire-frame types. News, weather, and web-search data are agent-internal tool results woven into ordinary agent_token and agent_turn_complete output.
| System | Trigger | Limit | Content source |
|---|---|---|---|
| Post-greeting nudge | Visitor silent 4-10 seconds after greeting | exactly one per session | LLM-generated today; may become pre-recorded |
| Mid-session re-engagement | Visitor silent 90-120 seconds during active conversation | up to 2 per idle stretch | Contract-Re-Engagement-Manifest static pool |
The post-greeting nudge and mid-session re-engagement systems are independent; the first does not count toward the second.
Voice input is press-and-hold only. While pressed, the UI shows “ON AIR” and Web Speech API collection runs. On release, final transcript is sent as user_message with inputMethod: 'voice'. If speech recognition fails, show in-character “bad signal” copy and keep text input available.
Optional enhancements: recognition.processLocally = true where supported; contextual SpeechRecognitionPhrase biasing for Max-specific terms where the browser supports it.
packages/frontend/src/App.tsx currently sends text user_message frames through useWebSocket; useWebSocket.ts consumes connection_ack, agent_token, agent_turn_complete, session_state_change, and error frames according to the typed contract. The agent HTTP runtime in packages/agent/src/index.ts checks session caps and returns complete-text server-sent events from /invocations, not incremental tokens or the full WebSocket frame protocol. It calls neither personality-check nor stutter-injection helpers, and a fresh caller-chosen sessionId evades the cap. The WebSocket Lambda handler is the integration point that must still bridge this contract to the agent. See Contract-WebSocket-API, Component-Agent-Runtime and Feature-Max-Height-Core.
- Concept-Cloud-Only-Inference
- Concept-Budget-Ceiling
- Concept-Personality-Gate
- Concept-IP-And-Legal-Posture
- Concept-Supply-Chain-Discipline
- Concept-Graceful-Degradation
- Concept-Observability
- Concept-Testing-And-TDD
- Concept-Credential-Hygiene
Editing in the browser? Wiki edits are live and bypass wiki:lint. Read
Guide-Wiki-Contributing first.