Agentic BodyMaps AI assistant: tool loop, self-capture, and document reading - #143
Merged
Conversation
| try: | ||
| manifest = bake_case_meshes(pants_id, seg_path, case_dir, route_base="cases") | ||
| except Exception as error: | ||
| return jsonify({"error": f"Mesh generation failed: {error}"}), 500 |
| try: | ||
| glb_bytes = generate_organ_glb_bytes(organ_key, seg_path) | ||
| except Exception as e: | ||
| return jsonify({"error": f"Error generating GLB: {str(e)}"}), 500 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends the BodyMaps AI sidebar from a single-shot chatbot into an assistant that investigates a case before answering, can see the viewer, and reads attached documents. Everything runs on the locally hosted Ollama models, so no case data leaves the machine.
What's new
Agentic investigation. For questions about the open case, the assistant runs a bounded tool loop instead of answering from a static payload. It can fetch an organ's measured volume, mean HU and reference percentile, list segmented structures, read patient demographics, isolate organs in the viewer, and change the CT window — observing each result before deciding its next step. Progress is streamed to the UI, viewer actions fire immediately, and rounds are capped.
Self-capture. When a question is about visual appearance, the assistant requests screenshots of the CT views; the browser captures them, attaches them to the conversation for transparency, and the turn continues through the vision model. Limited to one capture per turn.
Document reading. Attached PDFs are parsed in the browser and their text travels with the message, so the assistant can respond to document content and ask informed follow-ups.
Answer quality. Model reasoning can no longer leak into replies (including the orphan-
</think>shape some local models emit); answers are length calibrated; multi-turn context is preserved so follow-ups continue the conversation instead of being misrouted to case data; multi-part requests are answered part by part; the color-legend shortcut no longer hijacks long image prompts. The system prompt was also compressed ~46% with all behavior preserved, which measurably cuts response latency on CPU.Reliability. The dev server now runs threaded so long-running work cannot starve other requests, and the default CORS allowlist covers both localhost spellings.
Notes for reviewers
_ai_gate()is open and usage is recorded only for signed-in users. Flagging explicitly in case plan limits should be reinstated before production.pdfjs-dist.services/mesh_generation.pyis included becauseapi_blueprint.pyimportsbake_case_meshesfrom it; the 3D viewer changes themselves are not part of this PR.Testing
npm run build,npx tsc -b, andnpm test(193 tests) pass.python -m pytest tests/unitpasses with no new failures relative tomain.