{"record":{"id":"d829cb65c924e648","repo":"langchain-ai/deepagents","slug":"cron-tools-must-be-called-from-within-a-talon-conv","errorCode":null,"errorMessage":"cron tools must be called from within a Talon conversation","messagePattern":"cron tools must be called from within a Talon conversation","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"libs/talon/deepagents_talon/runtime.py","lineNumber":838,"sourceCode":"        if isinstance(profile, dict)\n        else {\"max_input_tokens\": context_size}\n    )\n    try:\n        cast(\"Any\", model).profile = merged\n    except (AttributeError, TypeError, ValueError) as exc:\n        msg = f\"Could not apply {CONTEXT_SIZE_ENV_KEY} to model profile\"\n        raise ValueError(msg) from exc\n\n\ndef _is_openai_model(model: str) -> bool:\n    return model.startswith(\"openai:\")\n\n\ndef _current_cron_origin() -> CronOrigin:\n    origin = _CRON_ORIGIN.get()\n    if origin is None:\n        msg = \"cron tools must be called from within a Talon conversation\"\n        raise RuntimeError(msg)\n    return origin\n\n\ndef _cron_origin_from_request(request: AgentRequest) -> CronOrigin:\n    channel = request.metadata.get(\"channel\")\n    message_id = request.metadata.get(\"message_id\")\n    origin_conversation_id = request.metadata.get(\"origin_conversation_id\")\n    return CronOrigin(\n        conversation_id=(\n            origin_conversation_id\n            if isinstance(origin_conversation_id, str) and origin_conversation_id\n            else request.conversation_id\n        ),\n        channel=channel if isinstance(channel, str) else None,\n        message_id=message_id if isinstance(message_id, str) else None,\n    )\n\n","sourceCodeStart":820,"sourceCodeEnd":856,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/talon/deepagents_talon/runtime.py#L820-L856","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Call the cron tool from within a Talon conversation/agent turn so `_CRON_ORIGIN` is populated","In tests, set the context var or use the runtime's request machinery to establish an origin","Pass explicit origin/channel metadata through the normal AgentRequest flow instead of calling internals directly"],"exampleFix":"# before\nschedule_cron(...)  # called from a standalone script -> RuntimeError\n# after\nruntime.run(AgentRequest(..., metadata={\"channel\": \"cli\", \"message_id\": msg_id}))  # tool called inside the turn","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    origin = cron_tool_schedule(...)\nexcept RuntimeError as exc:\n    if \"cron tools must be called from within a Talon conversation\" in str(exc):\n        raise RuntimeError(\"call cron tools via the Talon runtime, not standalone\") from exc\n    raise","preventionTips":["Only invoke cron tools through agent tool calls inside a Talon conversation","In tests, run through the runtime or set the origin context var explicitly","Never call cron tool implementations from background threads outside the conversation context"],"tags":["runtime","context","cron","misuse"],"backgroundTag":"missing-contextvar-value","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}