شعار 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 يُحمّله النموذج عند الحاجة، فلا يستهلك توكنات إلا عندما يَرِد طلب ذو صلة فعلًا.

  • تعمل مع أي نموذج لغوي كبير

    مهارات الذكاء الاصطناعي مكتوبة بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا تعمل مع GPT أو Claude أو Gemini أو Grok أو نموذج محلي.

  • مكتفية بذاتها

    كل ما يحتاجه النموذج موجود في التعليمات — لا ملفات إضافية لمزامنتها.

  • مفتوحة المصدر

    نشرها vstorm-co على GitHub. اطّلع على المصدر قبل تثبيتها.

التثبيت

ثبّت مهارة الذكاء الاصطناعي Background Task في TypingMind لاستخدامها مع أي نموذج لغوي كبير، أو أضفها إلى وكيل ذكاء اصطناعي آخر يقرأ SKILL.md.

1

التثبيت في TypingMind

يُثبّت TypingMind المهارة مباشرةً من مجلدها على GitHub — فيقرأ SKILL.md، ويجمع ملفات الموارد في حزمة، ويحفظ النتيجة محليًا.

  1. افتح التطبيق وانتقل إلى «الإضافات» ثم «المهارات».
  2. اختر «تثبيت من GitHub».
  3. الصق رابط مجلد المهارة الموضّح أدناه وأكّد التثبيت.
    https://github.com/vstorm-co/agenticos/tree/main/.claude/skills/background-task
  4. فعّل المهارة في كل محادثة تريد إتاحتها فيها.
الإضافات ← المهارات ← إضافة مهارة ← من رابط GitHub، ثم الصق رابط المجلد واضغط على «متابعة».
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

فعّل Background Task في أي محادثة على TypingMind وسيتولى النموذج الباقي. تتضمن مطالبة النظام اسمها ووصفها، وبمجرد ورود طلب ذي صلة، يُحمّل النموذج التعليمات الكاملة تلقائيًا — فلا تحتاج إلى استدعائها يدويًا، ولا تستهلك أي توكنات حتى تُستخدم فعليًا.

يُحمّل النموذج مهارة Background Task تلقائيًا بمجرد ورود طلب ذي صلة بها.

تعمل مع أي نموذج ذكاء اصطناعي

مهارات الذكاء الاصطناعي هي تعليمات بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا لا ترتبط Background Task بالنموذج الذي كُتبت له. ثبّتها مرة واحدة في TypingMind واستخدمها مع GPT-5 أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو نموذج محلي تشغّله بنفسك — كل ذلك باستخدام مفاتيح API الخاصة بك.

  • تُحمَّل عند الحاجة فقط

    تتضمن مطالبة النظام الاسم والوصف فقط. وتُجلب التعليمات عند أول طلب ذي صلة، لذا لا تستهلك تعليمات المهارة أي توكنات ما دامت المهارة غير مستخدمة.

  • بدّل النماذج أثناء المحادثة

    لأن المهارة تعليمات وليست شيفرة، فإن تغيير النموذج لا يعطّلها — فالنموذج التالي يقرأ ملف 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؟

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).

لماذا تستخدم Background Task على TypingMind؟

لأنك تثبّتها مرة واحدة وتستخدمها مع أي نموذج. مهارة Background Task عبارة عن نص Markdown وليست شيفرة خاصة بمزود بعينه، لذا تعمل المهارة نفسها مع GPT-5 أو Claude أو Gemini أو Grok أو نموذج محلي، ويمكنك تبديل النموذج أثناء المحادثة دون تعطّل المهارة. يعمل TypingMind بمفاتيح API الخاصة بك، فتدفع للمزودين مباشرةً بدلًا من اشتراك لكل مقعد، وتبقى مهاراتك ومحادثاتك في مساحة التخزين الخاصة بك.

كيف أثبّت Background Task في TypingMind؟

في TypingMind، افتح «الإضافات»، ثم «المهارات»، ثم اختر «التثبيت من GitHub» والصق https://github.com/vstorm-co/agenticos/tree/main/.claude/skills/background-task. يقرأ TypingMind ملف SKILL.md الخاص بالمهارة ويثبّتها كمهارة يمكنك تفعيلها لكل محادثة على حدة.

ما نماذج الذكاء الاصطناعي التي يمكنها استخدام Background Task؟

أي نموذج تربطه في TypingMind. مهارات الذكاء الاصطناعي عبارة عن تعليمات Markdown وليست شيفرة خاصة بمزود بعينه، لذا يمكن لكل من GPT وClaude وGemini وGrok والنماذج المحلية تحميل هذه المهارة عندما يتوافق الطلب معها.

كم نموذج ذكاء اصطناعي يمكنني استخدامه مع Background Task؟

أي عدد تريده. ما دام النموذج يدعم المهارات، يمكنك استخدام Background Task معه، سواء كان GPT أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو غيرها، وكل ذلك على TypingMind باستخدام مفاتيح API الخاصة بك.

هل مهارة الذكاء الاصطناعي Background Task مجانية؟

نعم. نشرها vstorm-co على GitHub بموجب ترخيص Apache-2.0. لا تدفع إلا لمزود الذكاء الاصطناعي الخاص بك مقابل التوكنات التي تستخدمها.

ما هي مهارات الذكاء الاصطناعي؟

مهارة الذكاء الاصطناعي حزمة تعليمات قابلة لإعادة الاستخدام تعلّم نموذج الذكاء الاصطناعي كيفية تنفيذ مهمة محددة. وتتبع تنسيق Agent Skills المفتوح: ملف SKILL.md يتضمن اسمًا ووصفًا، إلى جانب أي نصوص برمجية أو قوالب أو ملفات مرجعية قد يحتاج إليها النموذج. لا يقرأ النموذج التعليمات إلا عندما يتوافق طلبك مع المهارة، لذا لا تترتب على المهارة المثبتة أي تكلفة حتى تُستخدم.

كيف تختلف مهارات الذكاء الاصطناعي عن الإضافات أو موصلات MCP؟

تمنح الإضافة أو موصل MCP النموذج أدوات جديدة يمكنه استدعاؤها، وهي شيفرة تُنفَّذ في مكان ما وتُرجع نتيجة. أما مهارة الذكاء الاصطناعي فتزوّد النموذج بالمعرفة ومنهجية العمل: كيفية التعامل مع مهمة، والخطوات التي ينبغي اتباعها، وما ينبغي أن تكون عليه المخرجات الجيدة. المهارات عبارة عن نصوص Markdown، لذا لا تحتاج إلى خادم أو مفتاح API أو بيئة تشغيل، وتعمل مع أي نموذج.

عرض الكل

أنشئ مساحة عملك للذكاء الاصطناعي الآن

اشترك في نشرتنا الإخبارية لتصلك أخبار الميزات الجديدة والهدايا القادمة 👇