Skip to content

feat: cron context-inject button for Telegram deliveries - #26206

Closed
ryan-prayoga wants to merge 1 commit into
NousResearch:mainfrom
ryan-prayoga:feat/cron-context-inject-button
Closed

ryan-prayoga wants to merge 1 commit into
NousResearch:mainfrom
ryan-prayoga:feat/cron-context-inject-button

Conversation

@ryan-prayoga

Copy link
Copy Markdown

Summary

Add offer_context_inject flag to cron jobs. When True and deliver targets Telegram, the delivery message includes two inline buttons:

  • 📌 Add to session — injects the raw cron output into the currently active session as a user message so the agent can respond to it
  • 💬 New session — seeds a fresh session with the cron output

If no active session exists, the inject button falls back to new-session behavior automatically. Token expires after 24 h.

Changes

  • cron/jobs.pyoffer_context_inject field in create_job()
  • cron/scheduler.py_ci_store (in-memory, TTL 24 h), ci_store_pop(), inject cron_context_inject_token into Telegram delivery metadata
  • gateway/mirror.pyhas_active_session() helper, role param in mirror_to_session()
  • gateway/platforms/telegram.pyInlineKeyboardMarkup on last chunk, ci:inject/ci:new callback handler
  • tools/cronjob_tools.pyoffer_context_inject in schema, signature, and handler lambda

Testing

  • 400 tests pass (0 failures)
  • 16 new test cases in tests/cron/test_cron_context_inject.py covering ci_store round-trip, TTL expiry, flag persistence, mirror role param, and has_active_session helper
  • Manually tested end-to-end on Telegram: buttons appear on cron delivery, inject and new-session flows both work

Notes

  • Only supported via the live adapter path (gateway running). Standalone delivery silently skips the button.
  • Token is in-memory only — gateway restart clears pending tokens (24 h TTL mitigates this for normal use).

Copilot AI review requested due to automatic review settings May 15, 2026 07:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds an opt-in "context inject" feature for cron job deliveries on Telegram: when enabled, the delivery message includes inline buttons that let the user push the cron output into the active session (or open a new session) so the agent can react to it.

Changes:

  • New offer_context_inject flag plumbed through cronjob tool, create_job, and persisted on the job record.
  • Token-keyed in-memory ci_store in cron/scheduler.py with 24h TTL, populated in _deliver_result and consumed by the Telegram callback handler.
  • Telegram adapter attaches an InlineKeyboardMarkup to the last delivery chunk and handles new ci:inject:* / ci:new:* callbacks; mirror_to_session gains a role parameter and a new has_active_session helper.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tools/cronjob_tools.py Exposes offer_context_inject arg in the unified cronjob tool and its schema.
cron/jobs.py Persists the new flag on the job record via create_job.
cron/scheduler.py Adds the _ci_store / ci_store_pop token registry and stores the cron output on Telegram delivery.
gateway/mirror.py Adds role parameter and has_active_session helper.
gateway/platforms/telegram.py Builds the inline keyboard on the last chunk and handles ci:* callbacks.
tests/cron/test_cron_context_inject.py Tests for store, flag plumbing, mirror role, and has_active_session.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cron/scheduler.py Outdated
Comment thread tools/cronjob_tools.py Outdated
Comment thread tests/cron/test_cron_context_inject.py Outdated
Comment thread gateway/platforms/telegram.py Outdated
Comment thread gateway/platforms/telegram.py Outdated
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/cron Cron scheduler and job management comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter labels May 15, 2026
Add offer_context_inject flag to cron jobs. When True and deliver
targets Telegram, the delivery message includes two inline buttons:

- 📌 Tambahkan ke sesi ini — injects cron output into the active
  session as a user message so the agent can respond to it
- 💬 Mulai sesi baru — seeds a fresh session with the output

If no active session exists, inject falls back to new-session
behavior automatically. Token expires after 24 h.

Changes:
- cron/jobs.py: offer_context_inject field in create_job()
- cron/scheduler.py: _ci_store (in-memory, TTL 24h), inject
  cron_context_inject_token into Telegram delivery metadata
- gateway/mirror.py: has_active_session() helper, role param
  in mirror_to_session()
- gateway/platforms/telegram.py: InlineKeyboardMarkup on last
  chunk, ci:inject/ci:new callback handler
- tools/cronjob_tools.py: offer_context_inject in schema,
  signature, and handler lambda
@ryan-prayoga
ryan-prayoga force-pushed the feat/cron-context-inject-button branch from f6c425e to 18eba79 Compare May 15, 2026 07:53
NishantEC

This comment was marked as outdated.

@teknium1

Copy link
Copy Markdown
Collaborator

Thanks for the contribution. The cron-delivery follow-up workflow is now implemented on main through the continuable-cron path, so this Telegram callback implementation is superseded.

  • tools/cronjob_tools.py:1084 exposes per-job attach_to_session; the global opt-in is cron.mirror_delivery.
  • cron/scheduler.py:15881624 opens a dedicated thread for an eligible origin delivery, and cron/scheduler.py:18541877 seeds its session only after delivery succeeds.
  • website/docs/user-guide/features/cron.md:301 documents replying to a delivered brief with its context preserved.
  • The alternation-safe continuation behavior shipped in b177d4ee4891aeb3bf8a908f6e5def846a55c180 and is included in v2026.7.1.

This is an automated hermes-sweeper review.

@teknium1 teknium1 closed this Jul 13, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 13, 2026
@ryan-prayoga
ryan-prayoga deleted the feat/cron-context-inject-button branch July 13, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cron Cron scheduler and job management comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have platform/telegram Telegram bot adapter sweeper:implemented-on-main Sweeper: behavior already present on current main type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants