yf176 commited on
Commit ·
fbd3600
1
Parent(s): 7f3cd8e
fix: show v6 workflow in slack yolo ux
Browse files
src/polyhedra/agents/coordinator.py
CHANGED
|
@@ -17,11 +17,13 @@ from __future__ import annotations
|
|
| 17 |
|
| 18 |
import asyncio
|
| 19 |
import logging
|
|
|
|
| 20 |
import time
|
| 21 |
from dataclasses import dataclass, field
|
| 22 |
from typing import Any, Callable, Awaitable
|
| 23 |
|
| 24 |
from polyhedra.agents.base import Agent, AgentResponse, Mention
|
|
|
|
| 25 |
from polyhedra.core.agent_router import AgentRouter, QUANT_ROLES as _QUANT_ROLES, ALT_AGENT_MAP as _ALT_AGENT_MAP
|
| 26 |
from polyhedra.core.cache import SharedCache
|
| 27 |
from polyhedra.core.cost_gate import CostGate
|
|
@@ -68,6 +70,62 @@ _ROLE_LABELS: dict[str, str] = {
|
|
| 68 |
"publisher": "Finley",
|
| 69 |
}
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
class _CostRejected(Exception):
|
| 73 |
"""Sentinel raised when the user declines a cost-gated operation."""
|
|
@@ -283,12 +341,22 @@ class CoordinatorService:
|
|
| 283 |
if entry and role_name.lower() in held_roles:
|
| 284 |
self.session.registry.take_over(role_name, HELD_BY_HUMAN)
|
| 285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
welcome = [
|
| 287 |
"👋 **Polyhedra session started.**",
|
| 288 |
"",
|
| 289 |
f"**Goal:** {goal}",
|
| 290 |
-
f"**
|
|
|
|
| 291 |
]
|
|
|
|
|
|
|
| 292 |
if held_roles:
|
| 293 |
welcome.append(f"**Roles held by you:** {', '.join(held_roles)}")
|
| 294 |
welcome += [
|
|
@@ -561,7 +629,10 @@ class CoordinatorService:
|
|
| 561 |
"unusualeventdetector", "eventrouter", "btcanalyst", "spyanalyst",
|
| 562 |
"qqqanalyst", "gldanalyst",
|
| 563 |
}
|
| 564 |
-
|
|
|
|
|
|
|
|
|
|
| 565 |
asset_roles = [
|
| 566 |
role for role in ("btcanalyst", "spyanalyst", "qqqanalyst", "gldanalyst")
|
| 567 |
if role == latest_role or role in self._yolo_completed
|
|
@@ -597,11 +668,13 @@ class CoordinatorService:
|
|
| 597 |
if latest_role == "publisher" or "publisher" in self._yolo_completed:
|
| 598 |
return (
|
| 599 |
f"⚡ YOLO run complete — {self.session.goal}\n"
|
|
|
|
| 600 |
f" {steps}\n"
|
| 601 |
" Finley's post is ready below."
|
| 602 |
)
|
| 603 |
return (
|
| 604 |
f"⚡ YOLO run in progress — {self.session.goal}\n"
|
|
|
|
| 605 |
f" {steps}"
|
| 606 |
)
|
| 607 |
|
|
|
|
| 17 |
|
| 18 |
import asyncio
|
| 19 |
import logging
|
| 20 |
+
import re
|
| 21 |
import time
|
| 22 |
from dataclasses import dataclass, field
|
| 23 |
from typing import Any, Callable, Awaitable
|
| 24 |
|
| 25 |
from polyhedra.agents.base import Agent, AgentResponse, Mention
|
| 26 |
+
from polyhedra.agents.quant.market_scope import V6_MARKETS
|
| 27 |
from polyhedra.core.agent_router import AgentRouter, QUANT_ROLES as _QUANT_ROLES, ALT_AGENT_MAP as _ALT_AGENT_MAP
|
| 28 |
from polyhedra.core.cache import SharedCache
|
| 29 |
from polyhedra.core.cost_gate import CostGate
|
|
|
|
| 70 |
"publisher": "Finley",
|
| 71 |
}
|
| 72 |
|
| 73 |
+
_V5_QUANT_PATH: list[str] = [
|
| 74 |
+
"datafetcher",
|
| 75 |
+
"trendanalyst",
|
| 76 |
+
"sentimentanalyst",
|
| 77 |
+
"quantresearcher",
|
| 78 |
+
"backtester",
|
| 79 |
+
"riskanalyst",
|
| 80 |
+
"quantstrategist",
|
| 81 |
+
"publisher",
|
| 82 |
+
]
|
| 83 |
+
|
| 84 |
+
_V6_WATCHER_PATH: list[str] = [
|
| 85 |
+
"datafetcher",
|
| 86 |
+
"trendanalyst",
|
| 87 |
+
"marketeventwatcher",
|
| 88 |
+
"optionsflowwatcher",
|
| 89 |
+
"macrocontextwatcher",
|
| 90 |
+
"unusualeventdetector",
|
| 91 |
+
"eventrouter",
|
| 92 |
+
]
|
| 93 |
+
|
| 94 |
+
_V6_ASSET_ROLE: dict[str, str] = {
|
| 95 |
+
"BTC": "btcanalyst",
|
| 96 |
+
"SPY": "spyanalyst",
|
| 97 |
+
"QQQ": "qqqanalyst",
|
| 98 |
+
"GLD": "gldanalyst",
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
_V6_DOWNSTREAM_PATH: list[str] = [
|
| 102 |
+
"quantresearcher",
|
| 103 |
+
"backtester",
|
| 104 |
+
"riskanalyst",
|
| 105 |
+
"quantstrategist",
|
| 106 |
+
"publisher",
|
| 107 |
+
]
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def _extract_goal_tickers(text: str) -> list[str]:
|
| 111 |
+
"""Extract V6 market symbols from Slack-visible goals."""
|
| 112 |
+
tokens = re.findall(r"\b([A-Za-z]{1,5})\b", text)
|
| 113 |
+
seen: list[str] = []
|
| 114 |
+
for token in tokens:
|
| 115 |
+
normalized = token.upper()
|
| 116 |
+
if normalized in V6_MARKETS and normalized not in seen:
|
| 117 |
+
seen.append(normalized)
|
| 118 |
+
return seen
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def _planned_quant_path(goal: str) -> tuple[str, list[str]]:
|
| 122 |
+
"""Return the Slack-visible quant path implied by the current goal."""
|
| 123 |
+
v6_tickers = _extract_goal_tickers(goal)
|
| 124 |
+
if v6_tickers:
|
| 125 |
+
asset_roles = [_V6_ASSET_ROLE[ticker] for ticker in v6_tickers if ticker in _V6_ASSET_ROLE]
|
| 126 |
+
return "V6 specialized quant path", _V6_WATCHER_PATH + asset_roles + _V6_DOWNSTREAM_PATH
|
| 127 |
+
return "V5 general quant path", _V5_QUANT_PATH
|
| 128 |
+
|
| 129 |
|
| 130 |
class _CostRejected(Exception):
|
| 131 |
"""Sentinel raised when the user declines a cost-gated operation."""
|
|
|
|
| 341 |
if entry and role_name.lower() in held_roles:
|
| 342 |
self.session.registry.take_over(role_name, HELD_BY_HUMAN)
|
| 343 |
|
| 344 |
+
workflow_name, workflow_roles = _planned_quant_path(goal)
|
| 345 |
+
workflow_path = " → ".join(_ROLE_LABELS.get(role, role) for role in workflow_roles)
|
| 346 |
+
support_roles = [
|
| 347 |
+
role for role in selected_roles
|
| 348 |
+
if role not in set(workflow_roles) and role not in held_roles
|
| 349 |
+
]
|
| 350 |
+
|
| 351 |
welcome = [
|
| 352 |
"👋 **Polyhedra session started.**",
|
| 353 |
"",
|
| 354 |
f"**Goal:** {goal}",
|
| 355 |
+
f"**Workflow:** {workflow_name}",
|
| 356 |
+
f"**Path:** {workflow_path}",
|
| 357 |
]
|
| 358 |
+
if support_roles:
|
| 359 |
+
welcome.append(f"**Registered support agents:** {', '.join(support_roles)}")
|
| 360 |
if held_roles:
|
| 361 |
welcome.append(f"**Roles held by you:** {', '.join(held_roles)}")
|
| 362 |
welcome += [
|
|
|
|
| 629 |
"unusualeventdetector", "eventrouter", "btcanalyst", "spyanalyst",
|
| 630 |
"qqqanalyst", "gldanalyst",
|
| 631 |
}
|
| 632 |
+
workflow_name, planned_roles = _planned_quant_path(self.session.goal)
|
| 633 |
+
if workflow_name.startswith("V6"):
|
| 634 |
+
_PIPELINE = planned_roles
|
| 635 |
+
elif latest_role in v6_roles or any(role in v6_roles for role in self._yolo_completed):
|
| 636 |
asset_roles = [
|
| 637 |
role for role in ("btcanalyst", "spyanalyst", "qqqanalyst", "gldanalyst")
|
| 638 |
if role == latest_role or role in self._yolo_completed
|
|
|
|
| 668 |
if latest_role == "publisher" or "publisher" in self._yolo_completed:
|
| 669 |
return (
|
| 670 |
f"⚡ YOLO run complete — {self.session.goal}\n"
|
| 671 |
+
f" {workflow_name}\n"
|
| 672 |
f" {steps}\n"
|
| 673 |
" Finley's post is ready below."
|
| 674 |
)
|
| 675 |
return (
|
| 676 |
f"⚡ YOLO run in progress — {self.session.goal}\n"
|
| 677 |
+
f" {workflow_name}\n"
|
| 678 |
f" {steps}"
|
| 679 |
)
|
| 680 |
|
tests/test_quant_v6/test_scope_routing.py
CHANGED
|
@@ -2,10 +2,18 @@ from __future__ import annotations
|
|
| 2 |
|
| 3 |
from pathlib import Path
|
| 4 |
from types import SimpleNamespace
|
|
|
|
|
|
|
| 5 |
|
| 6 |
import pytest
|
| 7 |
|
| 8 |
from polyhedra.agents.base import Mention
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
from polyhedra.agents.quant import (
|
| 10 |
EventRouter,
|
| 11 |
MacroContextWatcher,
|
|
@@ -70,6 +78,25 @@ def test_split_v5_v6_markets() -> None:
|
|
| 70 |
)
|
| 71 |
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
@pytest.mark.asyncio
|
| 74 |
async def test_quant_command_routes_v6_markets_to_v6_agent_flow(tmp_path: Path) -> None:
|
| 75 |
integration = SlackIntegration.__new__(SlackIntegration)
|
|
|
|
| 2 |
|
| 3 |
from pathlib import Path
|
| 4 |
from types import SimpleNamespace
|
| 5 |
+
import sys
|
| 6 |
+
import types
|
| 7 |
|
| 8 |
import pytest
|
| 9 |
|
| 10 |
from polyhedra.agents.base import Mention
|
| 11 |
+
|
| 12 |
+
sentence_transformers_stub = types.ModuleType("sentence_transformers")
|
| 13 |
+
sentence_transformers_stub.SentenceTransformer = object
|
| 14 |
+
sys.modules.setdefault("sentence_transformers", sentence_transformers_stub)
|
| 15 |
+
|
| 16 |
+
from polyhedra.agents.coordinator import CoordinatorService
|
| 17 |
from polyhedra.agents.quant import (
|
| 18 |
EventRouter,
|
| 19 |
MacroContextWatcher,
|
|
|
|
| 78 |
)
|
| 79 |
|
| 80 |
|
| 81 |
+
def test_yolo_status_shows_v6_planned_path_for_v6_goal() -> None:
|
| 82 |
+
service = CoordinatorService.__new__(CoordinatorService)
|
| 83 |
+
service.session = SimpleNamespace(goal="SPY analysis")
|
| 84 |
+
service._yolo_completed = ["datafetcher"]
|
| 85 |
+
|
| 86 |
+
status = service._build_yolo_status("datafetcher", done=True)
|
| 87 |
+
|
| 88 |
+
assert "V6 specialized quant path" in status
|
| 89 |
+
assert "DataFetcher" in status
|
| 90 |
+
assert "TrendAnalyst" in status
|
| 91 |
+
assert "MarketEventWatcher" in status
|
| 92 |
+
assert "OptionsFlowWatcher" in status
|
| 93 |
+
assert "MacroContextWatcher" in status
|
| 94 |
+
assert "UnusualEventDetector" in status
|
| 95 |
+
assert "EventRouter" in status
|
| 96 |
+
assert "SPYAnalyst" in status
|
| 97 |
+
assert "SentimentAnalyst" not in status
|
| 98 |
+
|
| 99 |
+
|
| 100 |
@pytest.mark.asyncio
|
| 101 |
async def test_quant_command_routes_v6_markets_to_v6_agent_flow(tmp_path: Path) -> None:
|
| 102 |
integration = SlackIntegration.__new__(SlackIntegration)
|