Background Task 标志

Background Task

组织
vstorm-co
background-task

Add or change work that runs outside the request/response cycle — document ingestion, syncs, trigger fires, reports, cleanups, scheduled jobs — or debug a job that died, looped or never ran. Use when something is slow or must survive a restart, when adding a periodic job, when touching app/worker/, and before reaching for asyncio.create_task (which drops work silently in this codebase's exact failure mode).

Add to TypingMind

概览

发布者vstorm-co
代码仓库agenticos
技能名称background-task
星标数
137
复刻数
27
附带文件
仅含指令
许可协议Apache-2.0
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 指令自成一体

    模型所需的一切都包含在指令中,无需同步额外文件。

  • 开源

    由 vstorm-co 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Background Task AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/vstorm-co/agenticos/tree/main/.claude/skills/background-task
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/vstorm-co/agenticos.git /tmp/agenticos
mkdir -p .claude/skills
cp -r /tmp/agenticos/.claude/skills/background-task .claude/skills/background-task
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Background Task,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Background Task。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Background Task 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Background work — the job queue, and one in-process handoff

Read docs/howto/add-background-task.md. Jobs are rows in background_jobs (PostgreSQL); python -m app.worker claims and runs them. Kinds are declared in app/worker/jobs.py, handlers live in app/worker/tasks/ and are bound in app/worker/handlers.py, schedules are in app/worker/schedules.py. docs/configuration.md#background-work has the settings and the memory model.

Pick the right one

Use forSurvives a restart
A job (enqueue)Ingestion, syncs, fires, reports, anything scheduled, retryable or longYes
spawn_after_commit() from app/core/background.pyShort best-effort work on the API's loop that reads a row this unit of work wroteNo
spawn(), same moduleThe same, when it reads nothing the request wroteNo
InlineFast, transactional work the response depends onn/a
python
# AgentTriggerService.queue_fire, as it is
from app.services.background_jobs import enqueue
from app.worker.jobs import FIRE_TRIGGER, FireTrigger

await enqueue(
    self.db,
    FIRE_TRIGGER,
    FireTrigger(trigger_id=trigger_id, event_context=event_context, claimed_at=claimed_at),
    organization_id=organization_id,
)

Queue in the caller's transaction, from a service. The job row commits with the rows it names and NOTIFY fires only on commit, so the #417 race (a task that started before the commit and could not see its row) cannot happen. spawn_after_commit is still right for work that may be lost on a restart without harm; anything that must happen is a job.

Never bare asyncio.create_task. The event loop holds it only weakly, and an exception in a discarded task is never retrieved. app/core/background.py fixes both; drain(timeout=30.0) is its shutdown counterpart, and a CLI command that spawns work must call it before returning.

app/worker/background/channel.py is the older in-process fallback for channel work, dispatched with fire_and_forget(coro, *, label=...): no retry, no persistence. Do not add to it.

Add a job kind

  1. Declare a Payload and a Task in app/worker/jobs.py — pool, attempts, timeout, priority. Attempts follow one rule: 3 by default, 2 for ingestion, 1 for a scheduled sweep (its next tick is its retry) and for an API run.
  2. Write the handler in app/worker/tasks/<area>_tasks.py; it opens its own session (get_worker_db_context) and may return a Pydantic model as the job's result.
  3. Bind it in production() in app/worker/handlers.py. A sweep that takes no payload is wrapped with _each_tick.
  4. Queue it from a service with enqueue, or add a Schedule to SCHEDULES. test_every_declared_schedule_names_a_task_the_worker_knows fails a schedule with no handler.

Pick the pool by what the job spends: agent for model-bound runs, ingest for parsing and embedding (each job in a child process under a memory watchdog), system for short sweeps.

Rules

  • The attempt is spent at the claim. A job that kills its process - OOM, SIGKILL - has used one, so it cannot loop. Never move the increment out of the claim (_CLAIM in app/repositories/background_job.py). This is a hard requirement, measured against five other engines in #2219.
  • Fence every write. A job is settled with the attempts it was claimed with; a worker whose lease was taken over writes nothing and the takeover is counted as lease_lost. Handlers that charge money or send mail must be safe to run twice anyway: a lost lease means it may have.
  • Serializable payloads only — ids and primitives, never ORM objects. The handler re-reads the row and re-establishes authority (ApiKeyService.context_for_key for a key, active membership for a person): by then it may be gone.
  • Heavy imports inside the handler module, not in jobs.py, so the API that queues never imports the parser that runs.
  • Record what was spent even when the job fails. Embedding spend goes to ingestion_spend; a cost that lands only on success is a budget with a hole.
  • No ambient tenant in a worker. A job that touches an org-scoped resource carries the organization id in its payload; organization_id on enqueue is only for the panel's filter.
  • dedupe_key / dedupe_active / concurrency_key instead of checking for a running job by hand - the partial unique indexes make them race-free.

Debugging

  • Admin → Background jobs shows every job's attempts and last error, the workers alive, the paused kinds and the schedules. agenticos cmd doctor fails when no worker has beaten for two minutes, a minute schedule stopped firing, or a kind is paused.
  • A kind paused by the breaker (WORKER_BREAKER_DEATHS worker deaths in a row) stays paused until an owner resumes it; fix the cause first.
  • Tests: tests/integration/test_background_job_queue.py, tests/integration/test_worker_runtime.py (real kills), tests/test_worker_child_pool.py; misbehaving test kinds are in tests/worker_handlers.py. See docs/testing.md#the-workers-tests.

常见问题

Background Task AI 技能有什么作用?

Add or change work that runs outside the request/response cycle — document ingestion, syncs, trigger fires, reports, cleanups, scheduled jobs — or debug a job that died, looped or never ran. Use when something is slow or must survive a restart, when adding a periodic job, when touching app/worker/, and before reaching for asyncio.create_task (which drops work silently in this codebase's exact failure mode).

为什么在 TypingMind 中使用 Background Task?

因为您只需安装一次,就能搭配任何模型使用。Background Task 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Background Task?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/vstorm-co/agenticos/tree/main/.claude/skills/background-task。TypingMind 会读取其中的 SKILL.md,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Background Task?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Background Task 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Background Task 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Background Task AI 技能免费吗?

是的。vstorm-co 已在 GitHub 上根据 Apache-2.0 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇