← Về thư mục
📄 / / var / lib / containerd / io.containerd.snapshotter.v1.overlayfs / snapshots / 271 / fs / skills / openmaic / references / generate-flow.md

Generate Flow

Preconditions

Live Demo mode: If using the OpenMAIC Live Demo (open.maic.chat), all preconditions (repo, startup, provider keys) are already satisfied. Include Authorization: Bearer <access-code> header on all requests below. See live-demo.md for details.

Requirement-Only Generation

If the user has already clearly asked to generate the classroom and the preconditions are satisfied, submit the generation job immediately. Do not ask for a second confirmation just before calling /api/generate-classroom.

Submit the job with:

POST {url}/api/generate-classroom

Request body:

{
  "requirement": "Create an introductory classroom on quantum mechanics for high school students"
}

Only send supported content fields:

All optional boolean fields default to false when omitted. Omitting them preserves backward compatibility.

Feature Detection

Before sending optional feature flags, query GET {url}/api/health and check the capabilities object:

{
  "status": "ok",
  "version": "...",
  "capabilities": {
    "webSearch": true,
    "imageGeneration": false,
    "videoGeneration": false,
    "tts": true
  }
}

Only set a feature flag to true if the corresponding capability is true. If the server does not return capabilities (older version), do not send the new fields.

Do not rely on request-time model or provider override parameters.

Treat the POST response as job submission only. Expect fields such as:

{
  "success": true,
  "jobId": "abc123",
  "status": "queued",
  "step": "queued",
  "pollUrl": "http://localhost:3000/api/generate-classroom/abc123",
  "pollIntervalMs": 5000
}

PDF-Based Generation

  1. Resolve the absolute path to the PDF.
  2. Confirm before reading the file.
  3. Parse the PDF first:
POST {url}/api/parse-pdf
  1. Then send requirement plus pdfContent to:
POST {url}/api/generate-classroom

Polling Loop

After the job is submitted:

  1. Save jobId, pollUrl, and pollIntervalMs.
  2. Do not submit another generation job while this one is still queued or running.
  3. Poll:
GET {pollUrl}
  1. Prefer a conservative polling cadence of about 60 seconds between polls for classroom generation jobs, even if pollIntervalMs is shorter.
  2. Treat queued and running as in-progress states.
  3. Stop only when status becomes succeeded or failed.

Reliability Rules

If The Loop Ends First

If the job is still running when you stop active polling for this turn, tell the user that the classroom generation is still running in the background and invite them to come back a little later to continue checking the same job.

Use natural phrasing such as:

The classroom generation is still running in the background.
Job ID: abc123

Check back with me in a little while and I can continue tracking this same job without starting over.

What To Return

Return the generated classroom ID plus a directly clickable classroom URL.

Output the URL as a raw absolute URL on its own line.

Do not wrap the URL in:

Use a compact format like:

Classroom ID: Uyh82Y32ZK
Classroom URL:
http://localhost:3001/classroom/Uyh82Y32ZK

If the job fails, return the job ID plus the server error.

If generation fails, surface the server error directly instead of paraphrasing it away.

If the error suggests a provider or model configuration problem, explicitly tell the user to update .env.local or server-providers.yml instead of attempting a runtime override.

Confirmation Requirements