HTMLCSSJAVASCRIPTANGULARINTERVIEW QUESTIONSSQLPYTHONJAVAPHPHOW TOW3.CSSCC++C#BOOTSTRAPREACTNEXTJSMYSQLJQUERYEXCELXMLDJANGONUMPYPANDASNODEJSDSATYPESCRIPTANGULARJSGITPOSTGRESQLMONGODBASPAIRGOKOTLINSWIFTSASSVUEGEN AIAGENTIC AIPROMPT ENGINEERINGDOCKERKUBERNETESSPRINGSPRING BOOTUNIXSCIPYAWSCYBERSECURITYDATA SCIENCEINTRO TO PROGRAMMINGINTRO TO HTML & CSSBASHRUSTTOOLS
AI-Powered Full Stack Tutorial 0/70 lessons ~6 min read Lesson 47“React, Next.js, Node, PostgreSQL, LLMs, RAG, agents, and production AI apps”
AI Workflow Automation Capstone
The TechLearningPro operations workflow is where Module 4's pieces meet.
Course progress0%
Focus
24 guided sections
Practice signal
Examples included
Career prep
Interview Q&A included
AI-Powered Full Stack Development · Lesson 47 · AI Agents, Workflow Automation and Integrations
Lesson Overview
The TechLearningPro operations workflow is where Module 4's pieces meet. An instructor at Northwind asks for a reminder to learners who have not finished the pgvector lesson. The model must not invent learner ids, must not call a URL, must not send mail before a support lead approves, and must not send it twice when the panel is double-clicked. Lessons 36 through 46 built tool boundaries, state, orchestration, optional framework adapters, streaming UI, MCP, business connectors, approval, and guardrails. This lesson composes them into one function, runCohortReminderWorkflow.
The function is deliberately small. It checks a feature flag, loads a checkpoint, asks the enrollment connector for stalled learner ids inside the session tenant, asks the model for a template id only, proposes messaging.email.send with those server-side ids, and returns awaiting_approval. A later call with the same run id does not propose again. A call with an approved ticket executes once through the Lesson 45 port. A Contoso learner id never enters the recipient list. A refund tool in the model output is tool_denied and sends nothing.
This is the write path the knowledge assistant refused to become. The assistant remains available as a read. This reminder does not need it. The copy is template cohort_reminder_v1, filled by the mail adapter from ids. The model does not write the email body.
Planning assumptions:
Ports in the lab are in-memory fakes. The composition root wires Lessons 44, 45, and 46.
Workflow version is cohort-reminder-v1. It uses catalog business-connectors-v1, approval policy ops-approval-v1, and guardrails agent-guardrails-v1.
Illustrative limits match Lesson 46: 6 steps, 2 model calls, 4 connector calls, 20 seconds. The draft port owns the single repair. Revisit the numbers with finance before production.
Fixtures use synthetic learner ids. No secrets, no live vendor URL, and no real inbox.
The lesson player does not call this function. The operations panel does.
Module 5 starts at authentication and authorization. This capstone assumes a session already exists and shows every place that session must be the only source of tenant and role.
Learning Objectives
By the end of this lesson you will be able to:
Draw the reminder path from session scope through lookup, draft, approval, and one send.
Implement runCohortReminderWorkflow against ports so tests can force each failure.
Refuse a disabled flag, an empty tenant, and a learner role before any connector call.
Leave an existing ticket in place when the flag is off, and refuse to execute it from this function until the flag is on.
Load stalled learners only through the enrollment connector with the session tenant.
Keep recipient ids equal to that connector result, and stop when the list exceeds 50.
Accept only { "templateId": "cohort_reminder_v1" } from the model.
Deny a refund tool and any extra JSON key, including a model-supplied learnerIds array.
Propose mail once and pause on awaiting_approval.
Resume a paused run without a second ticket when the lead has not approved.
Execute an approved ticket once, and return the stored effect on replay.
Skip the model when the stalled list is empty or the lookup fails.
Write a trace of run id, ticket id, recipient count, and reason, without emails or prompts.
State which Module 4 lesson sits behind each port.
Leave sign-in, session issuance, and role storage to Module 5.
You can run Node's test runner. You do not need a provider key, a billing key, or an SMTP credential.
What is the AI Workflow Automation Capstone?
The workflow is the TechLearningPro operations job that reminds a tenant's stalled learners using a fixed template, after a person approves the recipient set. The capstone is the orchestrator that makes that job one code path. Earlier lessons remain the authority for their rules. The orchestrator does not reimplement HTTP clients, audit tables, or backoff math. It calls ports and enforces the order of the steps.
The purpose is regression control. A route that "adds an agent" tends to pass the model's learner list to the mailer, skip approval in the demo, and retry the send with a new idempotency key when the worker times out. A single function with a test for each of those failures is how the module ships.
Historically, workflow engines ran deterministic graphs, and chat bots ran open loops. This product is a short graph with one probabilistic step, and that step may only name a template. The orchestrator is the junction you can disable with a flag when spend or an incident requires it, without undeploying the lesson player.
Term
Meaning in this lesson
Orchestrator
runCohortReminderWorkflow
Run id
Id for one reminder job. The route mints it.
Stalled set
Learner ids the enrollment port returns for this tenant
Template
cohort_reminder_v1, a constant the mail adapter owns
Pause
awaiting_approval with a ticket id
Resume
The same run id continues at the checkpoint
Trace
Run id, ticket id, recipient count, reason, model flag
Why Do We Need It?
text
Each lesson works in its own package
|
v
The route lets the model pick recipients and calls SMTP
|
v
Cross-tenant ids, unapproved sends, and double mail regress
|
v
One orchestrator, ports, and a test per failure
|
v
A paused ticket or one send the audit can name
Benefits:
The order of checks is visible in one function and in one sequence diagram.
A kill switch on this function spends neither the model nor the mail vendor.
The recipient list is the connector's list.
Double-submits do not create a second ticket or a second effect.
Module 5 can replace how the session is built without rewriting the workflow.
Real World Example
An instructor signed in at Northwind asks for reminders on the pgvector lesson. The session tenant is Northwind. The enrollment port returns lrn_priya and lrn_omar. A Contoso id is absent from that result. The model responds { "templateId": "cohort_reminder_v1" }. The workflow proposes messaging.email.send with those two ids and idempotency key idem_run_01. The panel shows "Waiting for approval" and the count 2. A support lead approves the ticket in Lesson 45. The route then calls this function with ticketApproved: true only after it has read that status. Resume executes once. A second resume returns effect id msg_01 and does not call commit again.
If the model returns { "tool": "billing.refund.create" }, the run stops with tool_denied and the propose count stays zero. If the model returns the template plus a learnerIds array, the run stops with invalid_model_output. Recipients are not merged. Contoso never receives Northwind's reminder.
The same shape is how a bank batches a notice from accounts the officer can already open, how a hospital sends a portal reminder from the panel the clinician can see, and how Amazon-style and Shopify-style shops email the customers on that merchant's order list. Microsoft 365 and Google Workspace send as the tenant the admin signed into. Netflix-style lifecycle mail goes to the subscriber the account system returned. TechLearningPro's version is the stalled-learner set and a template.
Internal Working
If featureEnabled is false, return disabled and do not call lookup, draft, propose, or execute. If a paused checkpoint already exists, leave it saved so the ticket id remains. Lesson 45's route may still execute an approved ticket. This function will not, while the flag is off.
If tenantId or userId is empty, or the role is learner, return unauthorized before lookup.
Load the checkpoint for (tenant, runId). A terminal row returns the stored result and does not call ports again.
A paused row with ticketApproved === false returns awaiting_approval and does not call the model or propose.
A paused row with ticketApproved === true calls executeApproved for that ticket. Success stores effectId, sets sent, and returns. execution_unknown stays paused with that reason and the same ticket id.
Call lookupStalled(tenantId, "pgvector"). The adapter applies the tenant filter and Lesson 46's read retry. Failure returns lookup_failed and does not call the model.
An empty list returns nothing_to_send and does not call the model. A list longer than 50 returns too_many and does not call the model.
Call draftTemplate once. The port may do Lesson 46's single repair internally. A timeout returns model_unavailable.
parseTemplate accepts only { "templateId": "cohort_reminder_v1" }. A tool field is tool_denied. Any other shape is invalid_model_output.
Propose messaging.email.send with the stalled ids, the template id, and idempotency key idem_${runId}. A rejected propose returns propose_failed and does not invent a second key. Save paused on success and trace the recipient count.
If execute returns anything other than success or execution_unknown, return not_approved and leave the checkpoint paused. The route's boolean was not enough.
Trace tenantId, runId, reason, recipientCount, modelCalled, and ticketId when one exists. Omit prompts, email addresses, and secret handles.
Architecture
sequenceDiagram
participant Panel as Operations panel
participant Flow as runCohortReminderWorkflow
participant Enroll as Enrollment port
participant Model as Model port
participant Appr as Approval port
participant Mail as Mail commit port
Panel->>Flow: session tenant and run id
Flow->>Enroll: stalled learners for pgvector
Enroll-->>Flow: Northwind ids only
Flow->>Model: template request
Model-->>Flow: cohort_reminder_v1
Flow->>Appr: propose messaging.email.send
Appr-->>Panel: awaiting_approval
Panel->>Flow: resume after the lead approves
Flow->>Mail: executeApproved with the same key
Mail-->>Panel: effect id once
text
Session scope + runId
|
v
Flag, role, checkpoint
|
+--> disabled --> stop, keep any existing ticket row
+--> terminal --> stored result
+--> paused, not approved --> awaiting_approval
+--> paused, approved --> executeApproved once
|
v
lookupStalled for the session tenant
|
+--> empty --> nothing_to_send, no model
+--> over 50 --> too_many, no model
+--> error --> lookup_failed, no model
|
v
Model returns the template object only
|
+--> tool field --> tool_denied
+--> extra keys --> invalid_model_output
|
v
propose with server ids --> paused
|
v
Lesson 45 approval, then one commit
Request flow never sends the mail vendor a recipient the enrollment port did not return. Response flow to the panel is the orchestrator result, not the model JSON and not the SMTP body.
Deep Dive
Ports, not a new framework
ReminderPorts is the seam.
lookupStalled is Lesson 44's read path for one query. It applies tenantId and Lesson 46's retry inside the adapter. This function calls it once and treats a remaining error as terminal for the run.
draftTemplate is the model port. One repair lives inside that port, under agent-guardrails-v1. The orchestrator does not loop.
propose and executeApproved are Lesson 45. Audit rows are written there. This file does not insert them.
load and save are the Lesson 46 checkpoint, narrowed to this workflow's fields.
trace is an operations counter. It is not the financial audit.
A vendor SDK import in workflow.ts is a review failure. A LangGraph node from Lesson 41 may call this function. It should not own a second recipient list. An MCP tool from Lesson 43 may start a run. It should not hold the mail credential.
The prompt and the parser
SYSTEM_PROMPT is a constant in template.ts. It tells the model to return JSON with templateId set to cohort_reminder_v1 and to leave ids, addresses, and tool names out. The draft port receives the stalled count, not a blob of addresses. parseTemplate accepts one key. A tool key is tool_denied even if templateId is also present. A learnerIds key is invalid_model_output. The run allow-list enrollment.lookup and messaging.email.send is documented beside the parser so a refund tool cannot be added by editing the prompt.
Streaming UI from Lesson 42 may show "Looking up learners" and then "Waiting for approval." It must not stream a partial recipient list into a send button. Buffer the template JSON, build recipients from the connector, propose, then render the pause.
Recipients and the cap
recipientsFrom returns the stalled array only after the template parses. It does not read ids from the model. The cap is 50, the same number Lesson 44 validates on messaging.email.send. A larger cohort is a paged set of run ids, not a quiet raise of the cap in the route. The check happens before the model call so an oversized list does not spend a generation.
Approval is a pause
This function cannot mark a ticket approved. ticketApproved is a route concern: the handler loads the ticket for the session tenant, checks status approved, and only then passes true. A boolean in the browser body is not evidence. The lab passes the flag so tests can simulate the lead.
The idempotency key is idem_${runId} at propose time. Execute uses the ticket Lesson 45 stored. Resume does not create idem_${runId}_2.
When execute returns execution_unknown, the checkpoint stays paused with that reason and the same ticketId. The next approved resume calls executeApproved again. Lesson 45 deduplicates on the original key. This orchestrator does not propose a replacement ticket.
Empty, denied, and disabled paths
An empty stalled list does not call the model. A denied tool does not call propose. A disabled flag does not call lookup. Those tests are the cost and safety contract. A lookup failure does not fall through to "remind everyone in the tenant."
The kill switch and Lesson 45 stay split, as in Lesson 46. This function stops. The approval route can still commit a ticket a lead already approved, using the write credential. The runbook should say that in the first line so on-call does not expect the flag to unsend mail or to freeze a decided refund. The flag does stop this workflow from being the caller.
Traces and audit
The workflow trace answers whether the run paused and how many recipients it counted. The approval audit answers who approved and which effect id came back. Do not copy audit events into the trace, and do not copy the trace into the audit. The template body stays in the mail service as a constant. It does not need to be in either store.
What the orchestrator will not do
It will not issue a certificate, post a refund, or mark a lesson complete. It will not read another tenant because the prompt named one. It will not send when the lead has not approved. It will not invent reminder copy. It will not call the knowledge assistant to rewrite the email. If product later wants a grounded sentence, add a read port that returns passage text and keep that text out of the send until a person approves a new template version. A free-form body argument is a different, riskier workflow.
Session assumptions Module 5 will replace
The scope object is an argument. The route builds it from the session. This lesson does not verify passwords, issue cookies, or store roles. Those are Authentication and Authorization for SaaS Applications. What this lesson insists on is smaller: empty identity fails, a learner role fails, and the tenant on the scope is the tenant on the lookup, the ticket, and the checkpoint.
Code Examples
Place the orchestrator in packages/workflows/src/reminder/. The composition root wires real ports.
Simple example: template parsing
packages/workflows/src/reminder/template.ts
typescript
exportconstWORKFLOW_VERSION="cohort-reminder-v1";
exportconstTEMPLATE_ID="cohort_reminder_v1";
exportconstLESSON_KEY="pgvector";
exportconstMAX_RECIPIENTS=50;
/** Documented allow-list. Refund is intentionally absent. */
ALLOWED_TOOLS is the review artifact. The parser is the enforcement for this workflow's single model step. recipientsFrom copies stalled and does not read the model for ids.
executeApproved has no args parameter. The ticket Lesson 45 froze is the payload. draftTemplate receives a count so the adapter can avoid putting a list of names in the prompt.
propose_failed means the approval port rejected the ticket insert. The run does not mint a new idempotency key to try again inside this call. not_approved means execute was asked before Lesson 45 had an approved ticket.
The Contoso id is removed inside lookupStalled before propose, which is the adapter contract from Lesson 44. The extra learnerIds key fails closed. The approved resume calls execute once because the second call reads a terminal checkpoint. The trace assertion checks that an email-shaped string was not written. These fixtures have no addresses to leak.
No test reads an API key. The ports never open a socket.
Architecture Diagram
text
Operations panel
|
v
POST /ops/reminders/runs
|
v
runCohortReminderWorkflow
|
+--> feature flag (Lesson 46 kill switch for this caller)
+--> session scope (Module 5 will issue it)
+--> checkpoint load
+--> lookupStalled (Lessons 44 and 46)
+--> draftTemplate, one repair inside the port (Lesson 46)
+--> parseTemplate
+--> propose (Lesson 45) --> awaiting_approval
+--> executeApproved (Lesson 45) after the route sees approved
|
v
Checkpoint + trace counts
|
v
Audit remains in the approval package
Version pins:
text
cohort-reminder-v1
business-connectors-v1
ops-approval-v1
agent-guardrails-v1
Real-Time Enterprise Example
In production the API process constructs ReminderPorts once. Northwind's instructor starts a run. The enrollment adapter queries stalled pgvector learners with tenant_id = northwind. The model port is allow-listed to the tenant's providers from Lesson 23 and is asked only for the template id. Propose writes a Lesson 45 ticket. The lead approves in the queue. The route loads that ticket, then calls the workflow with ticketApproved: true. The mail adapter sends template cohort_reminder_v1 to the addresses it loads for those learner ids. The workflow trace stores the count. The audit stores the approver and msg_01.
A synthetic probe includes lrn_contoso in the fixture table and expects propose's id list to omit it. A second probe posts a refund-shaped model payload and expects zero proposes.
Challenge: the model provider is down, the stalled list is large, and the instructor double-clicks. An empty or failed lookup never reaches the model. A list over 50 returns too_many without a draft. A paused checkpoint absorbs the second click and does not propose again. You do not widen the query to "all learners" when lookup times out. You do not put a second vendor on the timeout path unless that vendor is already in allowedProviderIds. You do not rotate idem_run_01 after execution_unknown. If the feature flag is off, this function stops calling ports. A ticket the lead already approved can still be executed on the Lesson 45 route, and the runbook says so.
Performance Optimization
The happy path is one lookup, one model call, one propose, and later one execute. The model sees a count, not a pasted roster, so the prompt stays small when the cap is 50. Oversized cohorts stop before the model. Resume of a pause does not repeat lookup or draft. That skip is both a safety control and the latency control during an outage.
Do not hold the HTTP request open while the lead decides. Return awaiting_approval and let the panel poll or subscribe. Execute is a second request. Wall-clock budget from Lesson 46 applies inside the draft and lookup adapters. This orchestrator does not add a retry loop around them.
The lesson player must not call this endpoint. A reminder incident should not take down reading. Cache nothing about stalled learners on a shared key. The set changes when someone finishes the lesson, and a cache without tenant id would be the cross-tenant bug from Lesson 44.
Security
Authentication. Empty identity returns unauthorized. How the session was issued is Module 5.
Authorization. Learners cannot start the run. Leads approve on Lesson 45. ticketApproved is set by the route after a ticket read, not by the browser alone.
Tenant. Lookup, checkpoint, propose, and execute all receive the session tenant. A Contoso id in a fixture is filtered by the adapter.
Recipient integrity. The model cannot add ids. Extra keys fail the parse.
Tool integrity. A tool field is tool_denied before propose. Refund is not on ALLOWED_TOOLS.
Idempotency. The key is idem_${runId} for the life of the run.
Kill switch. This function stops. It does not delete tickets.
Secrets. No handle is accepted from the model or written to the trace.
Injection. The system prompt is constant. The user message is a count.
OWASP. The relevant issues are broken access control, mass assignment of recipients, and unrestricted resource consumption. The controls are the role check, the parser, the cap, and the pause.
Common Mistakes
Mailing the model's id list. Symptom: Contoso gets Northwind's reminder. Cause: learnerIds in the JSON was trusted. Fix: parse only templateId, and copy the connector's array.
Sending before approval. Symptom: mail leaves when the instructor clicks once. Cause: propose and execute ran in one step. Fix: pause on the ticket. The route executes after Lesson 45 says approved.
A second ticket on double-click. Symptom: two approvals for one cohort. Cause: resume called propose again. Fix: a paused checkpoint returns immediately.
A second send on replay. Symptom: duplicate mail. Cause: execute ran even when status was sent. Fix: terminal checkpoints return the stored effect id.
Rotating the idempotency key after a timeout. Symptom: two sends and one audit line. Cause: execution_unknown minted idem_run_01_b. Fix: call executeApproved again on the same ticket.
Calling the model when nobody is stalled. Symptom: spend on an empty cohort. Cause: draft ran before the length check. Fix: return nothing_to_send first.
Reminding the whole tenant when lookup fails. Symptom: a timeout becomes a broadcast. Cause: the catch block dropped the filter. Fix: lookup_failed and stop.
Letting a learner start the run. Symptom: a student triggers mail to peers. Cause: the role check was only in the UI. Fix: unauthorized for role learner.
Putting addresses on the trace. Symptom: inboxes in the log vendor. Cause: the trace copied learnerIds. Fix: store the count. Ids live on the ticket under Lesson 45's hash.
Streaming a send button from partial tokens. Symptom: the panel sends before the JSON is valid. Cause: SSE was wired to the model. Fix: buffer, parse, propose, then render the pause.
Treating the feature flag as a void of approved mail. Symptom: on-call thinks a decided send will not happen, and the Lesson 45 route still sends. Cause: the two switches were conflated. Fix: document the split in the runbook.
Importing the mail SDK into the orchestrator. Symptom: a prompt argument becomes a host. Cause: the framework node called SMTP itself. Fix: the node calls this function. The adapter holds the host.
Best Practices
Keep one orchestrator the route calls.
Depend on the connector, approval, and guardrail ports.
Pin cohort-reminder-v1 on the checkpoint.
Check the feature flag first, and do not erase an existing ticket.
Reject learners and empty identity before lookup.
Scope lookup by the session tenant.
Stop on empty, over-cap, and lookup errors before the model.
Ask the model for a template id, not a body and not a recipient list.
Fail closed on extra JSON keys and on tool fields.
Document ALLOWED_TOOLS next to the parser.
Propose once with idem_${runId}.
Pause for a human. Do not approve inside this function.
Let the route set ticketApproved only after reading the ticket.
Execute through Lesson 45 so the audit stays there.
Replay terminal successes without a second commit.
Keep execution_unknown on the same ticket.
Trace counts and reasons, not prompts or addresses.
Leave retries and the single repair inside the ports.
Keep the lesson player off this endpoint.
Test Contoso filtering, refund denial, extra keys, empty cohorts, replay, learners, and the flag.
Do not add a free-form email body without a new template version and a new approval.
Page large cohorts as separate run ids.
Write the runbook line about the flag versus the approval route.
Interview Questions & Answers
Beginner
What does this capstone function return before anyone approves? awaiting_approval, with a ticket id and a recipient count. Mail has not been sent. The model has only been allowed to name cohort_reminder_v1.
Why can't the model choose the recipients?
The model can be prompted into adding an id from another tenant or an attacker-supplied inbox. The enrollment connector returns the stalled set for the session tenant. The parser rejects any learnerIds field.
What is the idempotency key? idem_ plus the run id. Propose stores it on the ticket. Execute reuses it. A second click does not create a new key.
Intermediate
What happens on a double-click after the ticket exists?
The checkpoint is paused. The function returns awaiting_approval and does not call lookup, the model, or propose. After a real approval, the first execute sets sent. The next call returns that checkpoint and does not execute again.
How does Contoso stay out of the mail? lookupStalled filters by tenant before this function builds args. The test fixture includes lrn_contoso and asserts propose never sees it. A model field that tries to add the id fails the parser instead of being merged.
Why is the email body a template id?
Free-form body text is a place for the model to put the wrong policy or a phishing line, and it is harder to approve. The mail service owns cohort_reminder_v1. The lead approves who receives that template, which is a reviewable set of ids.
Senior
How do you test this without SMTP or a model account?
Fake the five ports. Script lookup to filter Contoso. Script the model with strings: a valid template, a refund tool, an extra key. Assert propose counts, execute counts, empty-list model counts, and the learner-role path. Contract-test the real adapters separately, with fixture learners.
Where is the audit, if the trace only has a count?
Lesson 45 appends propose, approve, and execute events with the argument hash and the effect id. This workflow trace is for on-call dashboards. Splitting them keeps finance records free of prompt text and keeps metrics free of the full id list when a count is enough.
Architect
How do you roll this out beside the lesson player?
Ship the route dark behind the feature flag. The player does not call it. Enable it for Northwind, watch lookup_failed, tool_denied, awaiting_approval age, and execute errors. A template change is cohort_reminder_v2 plus a parser change, not an edit to historical checkpoints. Old runs keep the version they stored.
What should Module 5 change, and what should it leave alone?
Module 5 should own how WorkflowScope is built: session cookie, role claim, tenant membership. It should not let the client post a tenant id that overrides the session. The workflow's checks stay: empty identity, learner rejection, and tenant threaded into every port. Replacing the session library should not require a new recipient rule.
How would you add a grounded sentence from the knowledge assistant?
Add an optional read port that returns passage text under Lesson 35's rules. Store that text on a new template version and send the lead the exact body on the ticket. Do not append the assistant's draft to cohort_reminder_v1 in this function. A new body is a new approval.
What is the failure you refuse to "fix" during an outage?
You refuse to drop the tenant filter, to skip approval, or to rotate the idempotency key. Lookup failure stays lookup_failed. Provider failure stays model_unavailable unless a second provider is already allow-listed. The honest degraded mode is a paused or stopped run, not a broader email.
Knowledge Check
1. What problem does this capability solve?
It turns the module's connector, approval, and guardrail rules into one reminder workflow with tests for the failures that become incidents: foreign recipients, unapproved sends, duplicate mail, empty-cohort spend, and tool calls that move money.
2. What alternatives exist, and when would you choose each?
A staff form that posts ids to a mail route is enough when a person already selected the rows, and it should still write an audit event. This orchestrator is what you want when a model is in the loop. A general planner that picks any tool fits a research notebook and does not fit this template. The knowledge assistant fits questions about the lesson, not the send.
3. Which data, identity, and trust boundaries matter?
The server supplies scope, the flag, and ticketApproved after a ticket read. Lookup supplies recipients. The model supplies a template id or the run stops. Approval and audit live in Lesson 45. Traces store counts. Module 5 will own session issuance and must keep the tenant on the session.
4. What can fail, and how should the system respond?
Disabled, unauthorized, lookup failure, empty sets, over-cap lists, model outages, bad JSON, denied tools, and propose failures stop without a send. Pause waits for a person. Execute unknown keeps the ticket. Replay of a sent run does not commit again.
5. How would you test quality, security, performance, and cost?
Unit tests cover the matrix above and assert port call counts. Security tests assert Contoso ids and refund tools never propose. Performance tests assert pause and terminal replays skip lookup and the model. Cost tests assert an empty cohort and a disabled flag do not call the model.
Practical Exercise
Implement packages/workflows/src/reminder/ and run the tests. Add a case where lookupStalled returns 51 ids and assert reason too_many with zero drafts. Write three sentences on how the route will set ticketApproved from the Lesson 45 ticket row and ignore a boolean in the JSON body.
Deliverable and Rubric
Submit the sequence diagram, the reminder package, the test output, a runbook note for the feature flag versus the approval route, and a list of side effects you left in Lessons 44–46.
Area
Weight
Conceptual accuracy and architecture
20%
Working implementation and code quality
25%
Security, privacy, and responsible AI
20%
Testing, reliability, and observability
20%
Documentation and decision rationale
15%
Production checklist:
Scope comes from the session.
Learners cannot start a run.
The feature flag short-circuits new port calls and keeps an existing ticket.
Lookup is tenant-scoped.
Empty and over-cap lists do not call the model.
The model may only return cohort_reminder_v1.
Tool payloads and extra keys do not propose.
Propose uses idem_${runId} once.
Execute happens after an approved ticket and happens once.
execution_unknown reuses the ticket.
Traces omit addresses and prompts.
The lesson player does not depend on this route.
Audit remains in the approval package.
Key Takeaways
The capstone is one orchestrator over the ports Module 4 already defined.
The workflow version is cohort-reminder-v1.
Recipients come from enrollment, scoped to the session tenant.
The model names a template. It does not name inboxes or tools.
Extra JSON keys and refund tools stop the run before propose.
Empty cohorts do not spend a model call.
Lists over 50 stop before the model call.
The run pauses on a Lesson 45 ticket.
The same run id does not propose twice.
An approved execute commits once and replays the effect id.
Idempotency stays idem_${runId}.
Traces store counts and reasons.
The kill switch stops this caller and does not delete tickets.
The knowledge assistant stays a read path.
Module 5 owns how the session is built. This function owns what it does with that session.
Summary
Lesson 47 closes AI Agents, Workflow Automation and Integrations by shipping a TechLearningPro reminder as a single, testable workflow. Connectors supply tenant-scoped ids, the model may only select a template, guardrails bound the draft, and a human approval is the only way mail leaves. Replays, empty cohorts, and denied tools are ordinary results with tests, not surprises blamed on the model. The lesson player keeps working when the workflow is flagged off. Nothing in this function is permission to refund, to certify, or to choose another tenant.
Next Lesson Preview
Module 5 opens with Authentication and Authorization for SaaS Applications. You will build the session this workflow already assumes: who the user is, which tenant they belong to, and which role may start a reminder or approve one. The orchestrator stays the same. The difference is that the scope object will come from a real sign-in, a real membership check, and a server-side role, so a request body cannot appoint itself support lead.