tools.redirect_task module
Wire a backgrounded task’s output to any channel on any platform.
When the task finishes (success or failure), its result is automatically delivered to the target channel — no polling required.
Works cross-platform: specify a platform name to target a different
platform than the one the command was issued from.
- async tools.redirect_task.run(task_id, channel_id='', platform='', max_chars=0, ctx=None)[source]
Wire a backgrounded task’s eventual output to a target channel/platform.
This is the entry point invoked by the tool loader (the module-level
runcallable discovered viagetattr(module, "run")intool_loader.py) when the model calls theredirect_tasktool. It resolves the destination channel and platform, looks up the matching platform adapter, and registers an output redirect on the task manager so that when the named background task finishes (success or failure) its result is delivered to that channel without any polling.The target channel and platform default to the originating ones taken from
ctx.channel_idandctx.platform. The destination adapter is found by calling_resolve_adapter(), which scansctx.all_adaptersfor aProxyPlatformAdapterwhosenamematches target_platform; because any running adapter may be selected, the redirect works cross-platform (e.g. a task started from Discord can be delivered into a Matrix room). The actual wiring is performed byctx.task_manager.set_output_redirect, which records the channel, platform, adapter, andmax_charscap against the task; the eventual delivery is driven by the task manager / event-bus machinery, not by this function. No Redis keys, knowledge-graph entries, LLM calls, or HTTP requests are made here directly.- Parameters:
task_id (
str) – The identifier returned by an earlier backgrounded tool call whose output should be redirected. Required; an empty value yields a failure response.channel_id (
str) – Target channel/room ID for delivery. Defaults to the current channel (ctx.channel_id) when empty.platform (
str) – Target platform name (e.g."discord","matrix"). Defaults to the current platform (ctx.platform) when empty.max_chars (
int) – Maximum characters of output to deliver.0defers to the task manager’s default cap (about 9000, roughly five messages).ctx (
ToolContext|None) – The tool execution context, providingtask_manager,channel_id,platform, andall_adapters. Required for the tool to operate.
- Returns:
A JSON document. On success it includes
success: trueplus the resolvedtask_id,redirect_channel,redirect_platform,max_chars, and a human-readablemessage. On failure it includessuccess: falseand anerrordescribing the missing task manager, missingtask_id, missing target channel, unresolved platform adapter (with the list of available adapter names), or an error string propagated fromset_output_redirect.- Return type:
No internal callers were found; this function is dispatched dynamically by the tool-loading machinery rather than invoked by name elsewhere.