MicroFish/backend/app/services
LoryGlory 00a2150365 feat(report): add POST /api/report/<id>/signal — extract miro_signal from simulation report
Adds a canonical machine-readable probability signal endpoint that distils
a completed simulation report into a structured prediction thesis.

New: backend/app/services/signal_extractor.py
- SignalExtractor.extract() calls chat_json() (3 attempts, temp 0.1, step 0.05)
  against the report markdown and returns a validated MiroSignal dataclass
- Validates and normalises all fields: p_yes clamped to [0.01, 0.99],
  confidence/action enums enforced, action recomputed from p_yes when invalid
- _trim_report() keeps the tail (conclusions) for long reports to stay within
  token limits
- _salvage() fallback_parser recovers a minimal signal from partial LLM output
  using regex probability extraction

New endpoint: POST /api/report/<report_id>/signal
- 404 if report not found
- 400 if report not yet completed or content is empty
- 422 if LLM fails after all retry attempts
- Returns canonical signal with thesis.{p_yes, confidence, action, regime,
  summary, drivers, invalidators} — schema_version 1.1

New: backend/tests/services/test_signal_extractor.py
- 27 tests covering happy path, field validation/normalisation, report
  trimming, _salvage fallback, and LLM failure propagation
- No real API calls — LLMClient fully mocked

Closes #277

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 16:18:50 +01:00
..
__init__.py Implement Interview feature for agent interactions in simulations 2025-12-08 15:55:39 +08:00
graph_builder.py feat(graph): implement pagination for fetching nodes and edges; add utility functions for streamlined data retrieval 2026-02-27 15:53:29 +08:00
oasis_profile_generator.py feat(llm): add structured output reliability to LLMClient and refactor services 2026-03-23 15:45:09 +01:00
ontology_generator.py Enhance backend startup logging and API endpoint display 2025-11-28 18:59:36 +08:00
report_agent.py fix(report_agent): refine tool call handling and response validation; enforce strict separation between tool calls and final answers 2026-02-24 17:47:44 +08:00
signal_extractor.py feat(report): add POST /api/report/<id>/signal — extract miro_signal from simulation report 2026-03-23 16:18:50 +01:00
simulation_config_generator.py feat(llm): add structured output reliability to LLMClient and refactor services 2026-03-23 15:45:09 +01:00
simulation_ipc.py Implement Interview feature for agent interactions in simulations 2025-12-08 15:55:39 +08:00
simulation_manager.py feat(history): 添加首页历史项目展示组件 2025-12-31 17:54:39 +08:00
simulation_runner.py Refactor process termination in SimulationRunner to support cross-platform handling and improve code clarity. Update development script to ensure concurrent processes are terminated correctly. 2025-12-30 17:45:27 +08:00
text_processor.py Introduce Project ID for context management, finalizing the stateful API pipeline from file submission to graph construction. 2025-11-28 17:21:08 +08:00
zep_entity_reader.py feat(graph): implement pagination for fetching nodes and edges; add utility functions for streamlined data retrieval 2026-02-27 15:53:29 +08:00
zep_graph_memory_updater.py feat(ZepGraphMemoryUpdater): add platform display name mapping and logging enhancements. 2026-01-16 09:00:10 +08:00
zep_tools.py feat(graph): implement pagination for fetching nodes and edges; add utility functions for streamlined data retrieval 2026-02-27 15:53:29 +08:00