Skip to main content

C-09 Scheduler

Brick C: Agents, autonomy, execution. French version: C-09-scheduler

1. Role and responsibilities​

Starts runs from cron expressions (eai.schedules). The scheduler tick is run by the server worker python -m eai.worker: each due time creates a pending run that AgentLoop.serve() picks up. Temporal Schedules stays an optional adapter.

2. Position in the architecture and interactions​

  • API: GET/POST /v1/schedules, PATCH/DELETE /v1/schedules/{id}; execution: server worker then AgentLoop on the client side.

3. Open source component and developed part​

  • Engine: Navin architecture of the Python SDK, with no declared graph. enterprise_ai.loop.AgentLoop takes in messages, prepares the context, manages sessions, resumes a run after a crash, handles stop, cron and heartbeat, and exposes serve(); enterprise_ai.runtime.AgentRunner runs one turn; enterprise_ai.subagents.SubagentManager runs sub-agents in parallel; enterprise_ai.loop.plan.RunPlan carries the plan; enterprise_ai.runtime.bus.MessageBus links channels and engine.
  • Optional adapters: LangGraph (enterprise_ai.runtime.langgraph.build_graph) and Temporal (enterprise_ai.runtime.temporal.build_workflow) reuse the same steps; neither is required.
  • Server side, python -m eai.worker runs the periodic jobs: scheduler tick, event outbox drain, quota reservation expiry, stale heartbeat detection, retention.

4. Data model​

Tables (schema eai, tenant_id RLS):

  • eai.schedules

Common columns: id uuid, tenant_id uuid NOT NULL, created_at, updated_at; RLS policy current_setting('app.tenant_id', true)::uuid.

5. Contract​

  • Applied contract: agent-manifest
  • JSON Schema: contracts/v1/agent-manifest.schema.json
  • Key fields: spec.schedules[].cron, timezone, overlap_policy
  • Validation: POST /v1/contracts/{name}/validate; manifest apply: POST /v1/manifests/apply.

6. API endpoints​

  • GET /v1/schedules
  • POST /v1/schedules
  • PATCH /v1/schedules/{id}
  • DELETE /v1/schedules/{id}

Request POST /v1/schedules:

{
"agent_id": "agt_report",
"cron": "0 7 * * 1-5",
"timezone": "Europe/Paris",
"task": {
"input": "Daily report"
}
}

Response:

{
"id": "sch_3",
"next_run_at": "2025-01-13T06:00:00Z",
"status": "active"
}

7. SDK examples​

Python:

from enterprise_ai import EnterpriseAI

client = EnterpriseAI(base_url="<control-plane-url>", api_key="eai_xxx_secret")
client.schedules.create(agent_id="agt_report", cron="0 7 * * 1-5", timezone="Europe/Paris")

TypeScript:

import { EnterpriseAI } from "@enterprise-ai/sdk";

const client = new EnterpriseAI({ baseUrl: "<control-plane-url>", apiKey: process.env.EAI_API_KEY });
await client.schedules.create({ agent_id: "agt_report", cron: "0 7 * * 1-5", timezone: "Europe/Paris" });

Java:

EnterpriseAIClient client = EnterpriseAIClient.builder()
.baseUrl("<control-plane-url>")
.apiKey(System.getenv("EAI_API_KEY"))
.build();
client.schedules().create(Map.of("agent_id", "agt_report", "cron", "0 7 * * 1-5", "timezone", "Europe/Paris"));

Go:

c, _ := eai.NewClient(eai.WithBaseURL("<control-plane-url>"), eai.WithAPIKey(os.Getenv("EAI_API_KEY")))
c.Schedules.Create(ctx, map[string]any{"agent_id": "agt_report", "cron": "0 7 * * 1-5"})

8. Configuration​

  • Environment variables: EAI_DATABASE_URL, EAI_TEMPORAL_URL (optional adapter)
  • Helm keys: worker.enabled, worker.replicas, controlPlane.config

9. Security controls​

  • The scheduled run executes with the agent service identity
  • Every request carries the tenant resolved from the credential; PostgreSQL RLS
  • Every mutation and policy decision writes a hash-chained audit event

10. Observability​

  • Prometheus metrics: eai_schedule_fires_total, eai_schedule_missed_total
  • Traces: OpenTelemetry spans with GenAI semantic conventions (gen_ai.operation.name, gen_ai.agent.id, gen_ai.tool.name), attributes eai.tenant_id, eai.run_id, traceparent propagation.
  • Audit actions: schedule.create, run.create

11. FinOps units​

  • Scheduled run cost charged to agent and project.
  • Emitted as Usage Event (POST /v1/finops/usage) with tenant, project, agent and run.

12. Failure modes and resilience​

  • Worker stopped: no due time is lost, the next tick catches up the runs that are due
  • Several worker replicas: a PostgreSQL advisory lock keeps a single active instance

13. Standalone adoption (client of a client)​

  • enterprise_ai.scheduler + Control Plane + server worker (python -m eai.worker); optional Temporal.
  • SDK: enterprise_ai.agent (AgentsClient, RunsClient, SessionsClient)
  • Minimal deployment: Helm chart with controlPlane.enabled=true and PostgreSQL; disabled external components use their in-process fallback.

14. Acceptance tests​

  1. Invalid cron -> 422
  2. Suspended agent: no firing
  3. Cross-tenant access refused
  4. Error returned in fr with Accept-Language: fr