Skip to content

feat: end-to-end WhatsApp death-certificate verification#45

Merged
kalanand merged 1 commit into
benevolentbandwidth:mainfrom
AlexanderGardiner:integration
Jul 12, 2026
Merged

feat: end-to-end WhatsApp death-certificate verification#45
kalanand merged 1 commit into
benevolentbandwidth:mainfrom
AlexanderGardiner:integration

Conversation

@AlexanderGardiner

Copy link
Copy Markdown
Contributor

Summary

  • Store inbound WhatsApp images in a transient per-session media store (session_media collection, 72h TTL, ~700 KB guard) so tools can retrieve the latest image by session_id.
  • Add context-aware tools: a tool marked needs_context: true is registered with a RunContext carrying SessionContext deps and pulls out-of-band state itself — the image never passes through the model.
  • Repoint the death-certificate tool to run the full reliability pipeline (document → authenticity → consistency → score) and hand off to GiveLight when the result clears the acceptance policy.
  • Handle image/document messages in POST /message; resolve the Meta media ID to bytes via whatsapp_media.download_media (WHATSAPP_TOKEN) and route bytes into chat().
  • On an image turn, save the bytes, route on the conversation narrative, and hand the model only a text notice.
  • Fix: the death-cert agent referenced a tool name that didn't resolve (raised on load); default VERTEX_LOCATION us-east1us-central1.

Notes

  • Deploy-config wiring for WHATSAPP_TOKEN and the local e2e driver scripts are intentionally out of scope of this PR.
  • WHATSAPP_TOKEN must be provisioned. This assumes the upstream webhook forwards raw Meta payloads (media IDs); if it pre-resolves media, only whatsapp_media.py and _extract_message change.

Validation

  • .venv/bin/python -m pytest tests/unit/test_api.py tests/unit/test_chat.py tests/unit/test_session_store.py tests/unit/test_verify_flow_integration.py tests/unit/tools/death_certificate_pipeline/test_verify.py passed: 34 tests.
  • End-to-end local run against real Gemini (Vertex): full flow reached score=96 band=high, gl.handoff_stub fired, agent confirmed the case was forwarded.
  • Compile/import check passed for src and the focused tests.

…handoff

Wire the full flow: an inbound WhatsApp image is stored in a transient media
store on arrival, the death-certificate agent invokes a context-aware verify
tool that pulls the image out of band (never through the model), runs the full
reliability pipeline (document, authenticity, consistency, score) and hands the
case off to GiveLight when it clears the acceptance policy.

- session_store: transient per-session media store (save/load latest image)
- orchestrator: SessionContext deps + context-aware tool registration; thread
  deps through Session/run_stream; default Vertex region -> us-central1
- verify tool: run_pipeline + build_handoff_payload + deliver_to_gl (stub),
  replacing the base64-image-as-tool-arg design that could not work via an LLM
- api: extract image/document messages; whatsapp_media.download_media resolves
  a Meta media ID to bytes (WHATSAPP_TOKEN); route bytes into chat()
- chat: store uploaded image, build SessionContext, route image turns on the
  conversation narrative; the model sees only a text notice, never the bytes
- fix: death-cert agent referenced a tool name that did not resolve
- tests: media store, context tools, verify tool, api image path, and a
  TestModel integration test driving the tool + deps + handoff end to end
@kalanand kalanand merged commit 6a06185 into benevolentbandwidth:main Jul 12, 2026
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