langchain-ai/deepagents · error · RuntimeError

cron tools must be called from within a Talon conversation

Error message

cron tools must be called from within a Talon conversation

What it means

Cron tools need to know which conversation/channel spawned them. Talon stores a `CronOrigin` in a ContextVar (`_CRON_ORIGIN`) that is only set while a Talon conversation is running. Calling a cron tool outside that context finds no origin and raises this RuntimeError.

Source

Thrown at libs/talon/deepagents_talon/runtime.py:838

        if isinstance(profile, dict)
        else {"max_input_tokens": context_size}
    )
    try:
        cast("Any", model).profile = merged
    except (AttributeError, TypeError, ValueError) as exc:
        msg = f"Could not apply {CONTEXT_SIZE_ENV_KEY} to model profile"
        raise ValueError(msg) from exc


def _is_openai_model(model: str) -> bool:
    return model.startswith("openai:")


def _current_cron_origin() -> CronOrigin:
    origin = _CRON_ORIGIN.get()
    if origin is None:
        msg = "cron tools must be called from within a Talon conversation"
        raise RuntimeError(msg)
    return origin


def _cron_origin_from_request(request: AgentRequest) -> CronOrigin:
    channel = request.metadata.get("channel")
    message_id = request.metadata.get("message_id")
    origin_conversation_id = request.metadata.get("origin_conversation_id")
    return CronOrigin(
        conversation_id=(
            origin_conversation_id
            if isinstance(origin_conversation_id, str) and origin_conversation_id
            else request.conversation_id
        ),
        channel=channel if isinstance(channel, str) else None,
        message_id=message_id if isinstance(message_id, str) else None,
    )

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Call the cron tool from within a Talon conversation/agent turn so `_CRON_ORIGIN` is populated
  2. In tests, set the context var or use the runtime's request machinery to establish an origin
  3. Pass explicit origin/channel metadata through the normal AgentRequest flow instead of calling internals directly

Example fix

# before
schedule_cron(...)  # called from a standalone script -> RuntimeError
# after
runtime.run(AgentRequest(..., metadata={"channel": "cli", "message_id": msg_id}))  # tool called inside the turn
Defensive patterns

Strategy: try-catch

Try / catch

try:
    origin = cron_tool_schedule(...)
except RuntimeError as exc:
    if "cron tools must be called from within a Talon conversation" in str(exc):
        raise RuntimeError("call cron tools via the Talon runtime, not standalone") from exc
    raise

Prevention

When it happens

Trigger: Invoking a cron scheduling tool from a bare script, a test, a background thread, or any code path that runs outside a Talon agent turn where `_CRON_ORIGIN` was never set.

Common situations: Unit-testing cron tools directly without the Talon runtime; calling cron helpers from a scheduler worker outside the conversation context; refactoring that moved tool code off the conversation call stack.

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/d829cb65c924e648. Report an issue: GitHub.