yf176 commited on
Commit ·
22f2abd
1
Parent(s): 2cb8257
fix: keep prompt-only options counts non-citable
Browse files
src/polyhedra/agents/quant/io_registry.py
CHANGED
|
@@ -45,7 +45,8 @@ _ASSET_ROUTE_RULE = (
|
|
| 45 |
_OPTIONS_SUMMARY_RULE = (
|
| 46 |
" The prompt may omit raw option contract rows after preserving their count, aggregated "
|
| 47 |
"market context, flow candidates, unusual flows, capabilities, and artifact identity. "
|
| 48 |
-
"Use those retained fields rather than treating prompt projection as a data gap."
|
|
|
|
| 49 |
)
|
| 50 |
|
| 51 |
|
|
@@ -199,6 +200,7 @@ _TASKS: dict[AgentName, str] = {
|
|
| 199 |
def _project_options_summary(inputs: BaseModel) -> dict[str, Any]:
|
| 200 |
"""Keep downstream options reasoning bounded without changing the stored artifact."""
|
| 201 |
projected = inputs.model_dump(mode="json")
|
|
|
|
| 202 |
for container_name in ("dependencies", "optional_context"):
|
| 203 |
container = projected.get(container_name)
|
| 204 |
if not isinstance(container, dict):
|
|
@@ -211,14 +213,14 @@ def _project_options_summary(inputs: BaseModel) -> dict[str, Any]:
|
|
| 211 |
continue
|
| 212 |
for result in payload.get("ticker_results") or []:
|
| 213 |
contracts = result.pop("contracts", [])
|
|
|
|
| 214 |
for collection in ("flow_candidates", "unusual_flows"):
|
| 215 |
for record in result.get(collection) or []:
|
| 216 |
record.pop("evidence_refs", None)
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
}
|
| 222 |
return projected
|
| 223 |
|
| 224 |
|
|
|
|
| 45 |
_OPTIONS_SUMMARY_RULE = (
|
| 46 |
" The prompt may omit raw option contract rows after preserving their count, aggregated "
|
| 47 |
"market context, flow candidates, unusual flows, capabilities, and artifact identity. "
|
| 48 |
+
"Use those retained fields rather than treating prompt projection as a data gap. "
|
| 49 |
+
"Prompt-only omission counts are not artifact fields and must never be cited."
|
| 50 |
)
|
| 51 |
|
| 52 |
|
|
|
|
| 200 |
def _project_options_summary(inputs: BaseModel) -> dict[str, Any]:
|
| 201 |
"""Keep downstream options reasoning bounded without changing the stored artifact."""
|
| 202 |
projected = inputs.model_dump(mode="json")
|
| 203 |
+
omitted_counts: dict[str, int] = {}
|
| 204 |
for container_name in ("dependencies", "optional_context"):
|
| 205 |
container = projected.get(container_name)
|
| 206 |
if not isinstance(container, dict):
|
|
|
|
| 213 |
continue
|
| 214 |
for result in payload.get("ticker_results") or []:
|
| 215 |
contracts = result.pop("contracts", [])
|
| 216 |
+
omitted_counts[result["ticker"]] = len(contracts)
|
| 217 |
for collection in ("flow_candidates", "unusual_flows"):
|
| 218 |
for record in result.get(collection) or []:
|
| 219 |
record.pop("evidence_refs", None)
|
| 220 |
+
if omitted_counts:
|
| 221 |
+
projected["prompt_only"] = {
|
| 222 |
+
"non_citable_options_contract_counts": omitted_counts,
|
| 223 |
+
}
|
|
|
|
| 224 |
return projected
|
| 225 |
|
| 226 |
|
tests/test_quant_io_registry.py
CHANGED
|
@@ -11,7 +11,8 @@ from polyhedra.agents.quant.asset_contracts import (
|
|
| 11 |
)
|
| 12 |
from polyhedra.agents.quant.decision_contracts import QuantStrategistLLMPayload
|
| 13 |
from polyhedra.agents.quant.io_registry import (
|
| 14 |
-
QUANT_IO_REGISTRY,
|
|
|
|
| 15 |
_project_trend_input, quant_artifact_schema, quant_io_binding,
|
| 16 |
)
|
| 17 |
from polyhedra.agents.quant.market_data_contracts import DataFetcherInput
|
|
@@ -177,12 +178,10 @@ def test_registry_is_read_only_and_rejects_unknown_name():
|
|
| 177 |
|
| 178 |
|
| 179 |
def test_downstream_options_projection_omits_only_raw_contract_rows():
|
| 180 |
-
|
| 181 |
-
"MacroContextWatcher", "UnusualEventDetector", "EventRouter",
|
| 182 |
-
"SPYAnalyst", "QQQAnalyst", "GLDAnalyst",
|
| 183 |
-
)
|
| 184 |
-
for agent in projected_agents:
|
| 185 |
assert quant_io_binding(agent).prompt_projector is _project_options_summary
|
|
|
|
|
|
|
| 186 |
assert quant_io_binding("OptionsFlowWatcher").prompt_projector is None
|
| 187 |
|
| 188 |
source = ProjectionInput(dependencies={"options_flow": {
|
|
@@ -204,10 +203,9 @@ def test_downstream_options_projection_omits_only_raw_contract_rows():
|
|
| 204 |
result = projected["dependencies"]["options_flow"]["payload"]["ticker_results"][0]
|
| 205 |
|
| 206 |
assert "contracts" not in result
|
| 207 |
-
assert
|
| 208 |
-
|
| 209 |
-
"
|
| 210 |
-
"source": "full OptionsFlowWatcher artifact",
|
| 211 |
}
|
| 212 |
assert result["market_context"] == {"contracts_sampled": 1}
|
| 213 |
assert result["flow_candidates"] == [{"candidate_id": "candidate-1"}]
|
|
@@ -256,6 +254,7 @@ def test_specialized_options_projection_reads_optional_context():
|
|
| 256 |
result = projected["optional_context"]["options_flow"]["payload"]["ticker_results"][0]
|
| 257 |
|
| 258 |
assert "contracts" not in result
|
| 259 |
-
assert
|
|
|
|
| 260 |
assert result["market_context"] == {"contracts_sampled": 100}
|
| 261 |
assert source.optional_context["options_flow"]["payload"]["ticker_results"][0]["contracts"]
|
|
|
|
| 11 |
)
|
| 12 |
from polyhedra.agents.quant.decision_contracts import QuantStrategistLLMPayload
|
| 13 |
from polyhedra.agents.quant.io_registry import (
|
| 14 |
+
QUANT_IO_REGISTRY, _project_asset_input, _project_options_summary,
|
| 15 |
+
_project_quantstrategist_input,
|
| 16 |
_project_trend_input, quant_artifact_schema, quant_io_binding,
|
| 17 |
)
|
| 18 |
from polyhedra.agents.quant.market_data_contracts import DataFetcherInput
|
|
|
|
| 178 |
|
| 179 |
|
| 180 |
def test_downstream_options_projection_omits_only_raw_contract_rows():
|
| 181 |
+
for agent in ("MacroContextWatcher", "UnusualEventDetector", "EventRouter"):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
assert quant_io_binding(agent).prompt_projector is _project_options_summary
|
| 183 |
+
for agent in ("SPYAnalyst", "QQQAnalyst", "GLDAnalyst"):
|
| 184 |
+
assert quant_io_binding(agent).prompt_projector is _project_asset_input
|
| 185 |
assert quant_io_binding("OptionsFlowWatcher").prompt_projector is None
|
| 186 |
|
| 187 |
source = ProjectionInput(dependencies={"options_flow": {
|
|
|
|
| 203 |
result = projected["dependencies"]["options_flow"]["payload"]["ticker_results"][0]
|
| 204 |
|
| 205 |
assert "contracts" not in result
|
| 206 |
+
assert "raw_contracts" not in result
|
| 207 |
+
assert projected["prompt_only"] == {
|
| 208 |
+
"non_citable_options_contract_counts": {"SPY": 1},
|
|
|
|
| 209 |
}
|
| 210 |
assert result["market_context"] == {"contracts_sampled": 1}
|
| 211 |
assert result["flow_candidates"] == [{"candidate_id": "candidate-1"}]
|
|
|
|
| 254 |
result = projected["optional_context"]["options_flow"]["payload"]["ticker_results"][0]
|
| 255 |
|
| 256 |
assert "contracts" not in result
|
| 257 |
+
assert "raw_contracts" not in result
|
| 258 |
+
assert projected["prompt_only"]["non_citable_options_contract_counts"]["SPY"] == 100
|
| 259 |
assert result["market_context"] == {"contracts_sampled": 100}
|
| 260 |
assert source.optional_context["options_flow"]["payload"]["ticker_results"][0]["contracts"]
|