Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A5c ai Babysitter defineTask

From Leeroopedia
Knowledge Sources
Domains Agent_Orchestration, Task_Definition
Last Updated 2026-10-23 00:00 GMT

Overview

Concrete tool for defining deterministic agent orchestration tasks provided by the Babysitter SDK.

Description

The defineTask function is the core process definition API in the Babysitter SDK. It registers a task with a unique identifier and a builder function, returning a frozen DefinedTask object that can later be invoked via ctx.task during orchestration execution. The task builder returns a TaskDef describing the effect to execute (agent call, breakpoint, shell command, etc.).

defineTask supports two call forms: a positional form defineTask(id, impl, options?) and a backward-compatible object form defineTask({ id, run, ... }) used by ~75 library processes.

Usage

  • Standard SFT-style processes: Call defineTask for each step in a process to register it before orchestration begins.
  • TDD convergence loops: Define planning, test-writing, implementation, quality-check, and scoring tasks.
  • Reusable library processes: Use the object form for processes authored against the earlier SDK API.

Code Reference

Source Location

  • Repository: Babysitter
  • File: packages/babysitter-sdk/src/tasks/defineTask.ts:L42-97

Signature

export interface DefineTaskOptions {
  description?: string;
  labels?: string[];
  kind?: string;
  source?: string;
  inputSchema?: Record<string, unknown>;
  outputSchema?: Record<string, unknown> | false | null;
}

export function defineTask<TArgs = unknown, TResult = unknown>(
  id: string,
  impl: TaskImpl<TArgs, TResult>,
  options?: DefineTaskOptions
): DefinedTask<TArgs, TResult>;

// Object form (backward-compatible)
export function defineTask<TArgs = unknown, TResult = unknown>(
  spec: DefineTaskObjectSpec<TArgs, TResult>
): DefinedTask<TArgs, TResult>;

// TaskImpl: (args: TArgs, ctx: TaskBuildContext) => TaskDef | Promise<TaskDef>
// DefinedTask: { id: string; build(args, ctx): Promise<TaskDef> } (frozen)

Import

import { defineTask } from "@a5c-ai/babysitter-sdk";

I/O Contract

Inputs

Name Type Required Description
id string Yes Unique task identifier
impl TaskImpl<TArgs, TResult> Yes (positional form) Builder function returning a TaskDef
options DefineTaskOptions No Optional metadata: description, labels, kind, schemas
spec DefineTaskObjectSpec Yes (object form) Single-object form with id/name, run, and metadata

Outputs

Name Type Description
return DefinedTask<TArgs, TResult> Frozen object with id and build(args, ctx) methods, registered in global task registry

Usage Examples

Basic Task Definition

import { defineTask } from "@a5c-ai/babysitter-sdk";

// Positional form
const myTask = defineTask("my-task", (args, ctx) => {
  return {
    kind: "agent",
    title: "Do something",
    agent: {
      name: "worker",
      adapter: "claude-code",
      prompt: { role: "user", task: args.feature },
    },
  };
}, {
  labels: ["core"],
  inputSchema: { type: "object", properties: { feature: { type: "string" } } },
});

Object Form (Legacy Compatible)

import { defineTask } from "@a5c-ai/babysitter-sdk";

const planningTask = defineTask({
  id: "agent-planner",
  run(args, ctx) {
    return {
      kind: "agent",
      title: "Plan feature implementation",
      agent: {
        name: "planner",
        adapter: "claude-code",
        prompt: { role: "user", task: `Plan: ${args.feature}` },
      },
    };
  },
  labels: ["planning"],
});

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment