mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-12 03:42:08 +00:00
feat(cron): routing intent — deliver=all fans out to every connected channel (#21495)
Adds one reserved token to the cron `deliver` field: - `all` — expand to every platform with a configured home channel Resolves at fire time, not create time, so a job created before Telegram was wired up picks it up once `TELEGRAM_HOME_CHANNEL` is set. Composes with existing targets: `origin,all`, `all,telegram:-100:17`. Inspired by Vellum Assistant's reminder routing-intent system. ## Changes - cron/scheduler.py: _expand_routing_tokens + integrate into _resolve_delivery_targets - tools/cronjob_tools.py: schema description updated - tests/cron/test_scheduler.py: TestRoutingIntents (5 cases) - website/docs/user-guide/features/cron.md: docs + table rows ## Validation - tests/cron/test_scheduler.py -k 'Routing or Deliver' → 57 passed
This commit is contained in:
parent
81928f03ab
commit
486b14b423
4 changed files with 143 additions and 3 deletions
|
|
@ -360,12 +360,52 @@ def _normalize_deliver_value(deliver) -> str:
|
|||
return str(deliver)
|
||||
|
||||
|
||||
# Routing intent tokens — resolved at fire time, not create time, so a
|
||||
# job created before Telegram was wired up will pick up Telegram once it
|
||||
# comes online. ``all`` expands into the set of connected platforms
|
||||
# (those with a configured home chat_id) in _expand_routing_tokens.
|
||||
_ROUTING_TOKENS = frozenset({"all"})
|
||||
|
||||
|
||||
def _expand_routing_tokens(part: str) -> List[str]:
|
||||
"""Expand a routing-intent token to concrete platform names.
|
||||
|
||||
``all`` expands to every platform in ``_iter_home_target_platforms()``
|
||||
that has a configured home chat_id right now. Unknown / non-token
|
||||
values pass through unchanged as a single-element list, so the caller
|
||||
can treat every token uniformly.
|
||||
"""
|
||||
token = part.lower()
|
||||
if token not in _ROUTING_TOKENS:
|
||||
return [part]
|
||||
expanded: List[str] = []
|
||||
for platform_name in _iter_home_target_platforms():
|
||||
if _get_home_target_chat_id(platform_name):
|
||||
expanded.append(platform_name)
|
||||
return expanded
|
||||
|
||||
|
||||
def _resolve_delivery_targets(job: dict) -> List[dict]:
|
||||
"""Resolve all concrete auto-delivery targets for a cron job (supports comma-separated deliver)."""
|
||||
"""Resolve all concrete auto-delivery targets for a cron job.
|
||||
|
||||
Accepts the legacy comma-separated ``deliver`` string plus the
|
||||
``all`` routing-intent token, which expands to every platform with
|
||||
a configured home channel. Tokens may be combined with explicit
|
||||
targets: ``origin,all`` and ``all,telegram:-100:17`` both work.
|
||||
Duplicate (platform, chat_id, thread_id) tuples are collapsed by the
|
||||
existing dedup pass.
|
||||
"""
|
||||
deliver = _normalize_deliver_value(job.get("deliver", "local"))
|
||||
if deliver == "local":
|
||||
return []
|
||||
parts = [p.strip() for p in deliver.split(",") if p.strip()]
|
||||
|
||||
raw_parts = [p.strip() for p in deliver.split(",") if p.strip()]
|
||||
|
||||
# Expand routing intents.
|
||||
parts: List[str] = []
|
||||
for raw in raw_parts:
|
||||
parts.extend(_expand_routing_tokens(raw))
|
||||
|
||||
seen = set()
|
||||
targets = []
|
||||
for part in parts:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue