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 66“React, Next.js, Node, PostgreSQL, LLMs, RAG, agents, and production AI apps”
Project 3: AI Agent for Business Operations
A Northwind support lead types, "Priya is stalled on pgvector.
Course progress0%
Focus
24 guided sections
Practice signal
Examples included
Career prep
Interview Q&A included
AI-Powered Full Stack Development · Lesson 66 · Production AI Products, Capstones and Career Readiness
Lesson Overview
A Northwind support lead types, "Priya is stalled on pgvector. Draft a reminder." The agent may look up stalled learners and may propose messaging.email.send. It may not send. A second sentence, "and refund her," may propose billing.refund.create only if that is the one write for the run. It may not do both writes. It may not put a Contoso learner id on the ticket. It may not keep calling tools after the proposal. When the lead has not approved, a resume returns awaiting_approval.
This capstone is ops-agent-v1. Lesson 47 was a fixed reminder workflow. This project is a bounded agent that chooses among an allow-list and still stops at a human for every write. The handbook assistant from Lesson 65 remains a read. The workspace from Lesson 64 remains the note editor. Neither is imported here.
The tests use scripted model turns. You do not need a payment processor or an inbox.
What is the AI Agent for Business Operations?
The ops agent is a loop that may call a small catalog of business tools for one workspace. Reads run immediately and return data to the next model turn. Writes become approval tickets and end the run in awaiting_approval. The capstone is runOpsAgent, the phase plan, and the tests that fail if the agent sends mail, refunds twice, or crosses a tenant.
The purpose is an operations product that is more flexible than Lesson 47's single template flow and stricter than a framework demo that executes every tool the model names. Support leads can ask for a lookup or a proposal in one box. The money and the mail still wait.
The industry name is "agent," and the failure mode is an agent that is a shell. Banks require a second person for a refund. Hospitals require a signed order. Amazon-style seller support and Microsoft 365 admin actions separate "the copilot drafted it" from "the admin committed it." TechLearningPro's version is one proposal per run, ids from the read, and Lesson 45 as the only executor.
Term
Meaning in this lesson
Run
One lead request, one runId
Step
One model turn plus at most one tool
Read tool
Executes and returns JSON to the model
Write tool
propose only, then stop
Allow-list
Four tool names
Proposal
A Lesson 45 ticket with idem_${runId}
Resume
Same run, no second propose
Budget
4 steps, 2 model calls, 3 tool calls
Why Do We Need It?
text
The model picks any tool and the SDK executes it
|
v
Cross-tenant ids, unapproved refunds, and loops that never stop
|
v
Allow-list, server-side ids, one proposal, step budget
|
v
A paused ticket or a read the audit can name
Benefits:
A new tool requires a catalog change and a test, not a prompt edit.
Writes have a person in the loop.
The run cannot propose a refund and an email together.
Duplicate clicks do not create a second ticket.
The handbook assistant and the workspace stay out of this process.
Real World Example
The lead's session workspace is northwind. The first model turn calls enrollment.lookup with { "lessonKey": "pgvector" }. The port returns ["lrn_priya"] and drops lrn_contoso because the adapter filters by workspace. The second turn calls messaging.email.send with a template id. The agent proposes a ticket whose learner ids are the lookup result, not a list the model added. The status is awaiting_approval. A later resume with ticketApproved: false does not propose again. After Lesson 45 shows the ticket approved, resume calls executeApproved once and stores the effect id.
If the model calls billing.refund.create and messaging.email.send in one payload, the result is invalid_tool_args and the propose count stays 0. If the model calls shell.exec, the result is tool_denied. If the model puts workspaceId: "contoso" on the lookup, the result is invalid_tool_args before the port.
A card-dispute desk, a marketplace refund desk, and an IT help desk that resets a token only after approval are the same shape. The agent can gather. A person releases the side effect. TechLearningPro gathers enrollment or an invoice and proposes one of two writes.
Internal Working
If featureEnabled is false, return disabled. Do not call the model. If a checkpoint already exists, leave it.
Empty workspace or user, or a role other than support_lead, returns unauthorized.
A terminal checkpoint returns the stored result.
A paused checkpoint with ticketApproved === false returns awaiting_approval and does not call the model.
A paused checkpoint with ticketApproved === true calls executeApproved for that ticket. Success stores the effect id. execution_unknown stays paused on the same ticket.
Start the loop with the user text. Each iteration calls the model unless the budgets are spent.
Budgets: more than 2 model calls or more than 4 steps returns budget_exceeded. More than 3 tool calls returns budget_exceeded before the extra call.
Parse one tool call. Unknown names are tool_denied. A workspaceId argument is invalid_tool_args. Two tool names in one object are invalid_tool_args.
Read tools execute with the session workspace and the allowed argument (lessonKey or invoiceId that the server will reload). The result is appended for the next turn. The model does not receive rows from another workspace.
Write tools require a prior successful read in this run. messaging.email.send copies learner ids from the last lookup. billing.refund.create copies the invoice id from the last invoice read. A model-supplied id list is invalid_tool_args.
Propose once with idem_${runId} and stop in awaiting_approval. A second write name in a later turn cannot happen because the loop already stopped. A payload that names two writes never proposes.
Traces store workspaceId, runId, reason, toolNames, modelCalls, and ticketId. They omit the user text, email addresses, and invoice amounts.
Architecture
sequenceDiagram
participant Lead as Support lead
participant Agent as runOpsAgent
participant Model as Model port
participant Read as Read tools
participant Appr as Approval port
Lead->>Agent: session workspace, run id, text
Agent->>Model: turn 1
Model-->>Agent: enrollment.lookup
Agent->>Read: lookup for northwind
Read-->>Agent: lrn_priya
Agent->>Model: turn 2 with lookup ids
Model-->>Agent: messaging.email.send
Agent->>Appr: propose idem_run id
Appr-->>Lead: awaiting_approval
Lead->>Agent: resume after approval
Agent->>Appr: executeApproved once
text
Flag, role, checkpoint
|
+--> disabled / unauthorized --> stop
+--> paused --> wait or executeApproved
|
v
Loop until budget, read result, or one proposal
|
+--> unknown tool --> tool_denied
+--> workspaceId arg --> invalid_tool_args
+--> two writes --> invalid_tool_args
+--> write without a prior read --> invalid_tool_args
Request flow executes reads only for the session workspace. Response flow to the lead is the agent result. The model does not talk to SMTP or the payment API.
Deep Dive
Catalog
Tool
Class
Arguments the server accepts
Effect
enrollment.lookup
read
lessonKey string, length 1..64
Returns learner ids for the session workspace
billing.invoice.read
read
invoiceId string matching inv_[a-z0-9]+
Returns status for that id if it is in the workspace
messaging.email.send
write
templateId must be cohort_reminder_v1
Proposes a send to the last lookup ids
billing.refund.create
write
reason must be goodwill or duplicate
Proposes a refund of the last invoice id
No other key is accepted. workspaceId, learnerIds, amount, and to are rejected. The template and the refund reason are constants so the ticket a human reads is boring on purpose. Lesson 47 already owns the template body. This agent does not invent a new email.
Product scope and non-goals
The agent can look up a lesson's stalled learners, read one invoice, and propose one of the two writes. It can resume after approval.
It does not answer handbook questions. Call Lesson 65 for that. It does not edit notes. It does not choose a refund amount. The amount lives on the invoice the read tool loaded, and Lesson 45's executor uses that stored amount. It does not run more than one write per runId. A lead who needs both a reminder and a refund starts a second run after the first ticket is understood.
Phased build plan
Phase
Build
Exit gate
0
Package, catalog types, CI, secret scan
Catalog has exactly four names
1
Role check, flag, checkpoint load
Learner role and disabled flag do no tool I/O
2
Read loop with budgets
Lookup is workspace-scoped, step cap fires
3
Propose one write from server-side ids
Model learnerIds do not reach propose
4
Resume and executeApproved
Double resume does not propose twice; execute once
5
Traces, readiness profile ops-agent-api, runbook line
Profile ready, flag versus approval route documented
Phase 2 is safe to demo to a lead because it cannot propose. Do not skip to phase 3 because the model "usually" only reads.
Acceptance criteria
Id
Behavior
Test name
C1
Role other than support_lead is unauthorized and does not call the model
lead_role_required
C2
Disabled flag performs no model or tool call
flag_stops_new_work
C3
shell.exec is tool_denied and does not propose
unknown_tool_denied
C4
workspaceId on a tool call is invalid_tool_args
model_cannot_set_workspace
C5
Lookup result omits lrn_contoso
lookup_is_workspace_scoped
C6
Email proposal uses lookup ids, not model ids
recipients_from_lookup
C7
A payload with two write names does not propose
one_write_per_payload
C8
A write without a prior read is invalid_tool_args
write_requires_read
C9
After propose, a second entry returns awaiting_approval and propose count stays 1
resume_does_not_repropose
C10
Approved resume executes once; a third call returns the effect
execute_once
C11
The third model call returns budget_exceeded
model_budget
C12
Trace has tool names and no user text
trace_omits_prompt
C13
Readiness profile passes
ops_profile_ready
C3, C4, C6, C7, and C9 are the merge blockers. They are the incidents: arbitrary tools, cross-tenant arguments, forged recipients, double actions, and double tickets.
Security gates
Allow-list is code, next to the parser.
Writes never execute inside the loop.
One write proposal per run.
Ids on the ticket come from the read port's last result.
Session workspace is the only workspace the ports receive.
ticketApproved is set by the route after it loads an approved ticket. The browser boolean is not evidence. The lab passes the flag so tests can simulate the lead.
Idempotency key is stable for the run.
The feature flag stops this function. Lesson 45 can still execute a ticket a person already approved. The runbook's first line says that, as in Lesson 47.
Traces omit prompts and amounts.
No payment or SMTP secret in the agent package. Those stay in the Lesson 45 adapters.
Test gates
Unit tests C1–C13 with scripted model turns and in-memory ports.
A test lookup fixture includes lrn_contoso and asserts propose never sees it.
A test model turn that returns both write names asserts proposeCount === 0.
A replay test calls runOpsAgent three times: propose, not approved, approved, then approved again. Propose count is 1. Execute count is 1.
Cost test: unauthorized, disabled, and tool_denied show zero model calls where the spec says they stop first. tool_denied may happen after a model call; the test asserts zero proposes.
CI runs readiness and the secret scan.
Playwright later: the panel shows "Waiting for approval" and does not render a Send button that calls SMTP.
Budgets and degrade
The step counter increments for each model turn. Tool calls increment a second counter. When the model returns a write, the loop ends even if budget remains. Ending early is the point. budget_exceeded is for a model that only reads and never stops. The lead sees a stopped run, not a partial refund.
Provider timeout during a turn is model_unavailable. Reads that already happened stay in the checkpoint as context so a retry of the same run can continue if you store them. This lab treats timeout before a proposal as terminal model_unavailable to keep the state machine small. A later version may resume the read context. It must still propose with the original runId key.
What the agent will not do
It will not send mail inside runOpsAgent. It will not set a refund amount. It will not call the knowledge assistant and paste the answer into the template. It will not run a fifth tool because the prompt said "be thorough." It will not look up Contoso because the user text named Contoso. The lookup port receives northwind from the session.
A read-only run that ends because the model stops is a reasonable later status (answered_read). This loop expects another tool until the budget. Phase 2 can add a { "done": true } parse if product wants a lookup with no follow-up write. Until then, a single lookup followed by a model timeout becomes model_unavailable on the next turn, and the lead can start a new run. Document that in the phase 2 README so you do not silently add a done-flag without a test.
exactKeys is what makes C4 and C6 structural. A lookup that also carries learnerIds or workspaceId never reaches ports.lookup. The email tool accepts tool and templateId only, so the proposal's learner ids are the array lookup returned for northwind. recipients_from_lookup covers that copy. model_cannot_set_workspace covers the extra key. Add one_write_per_payload by sending a second write field and asserting propose stays at 0, which exactKeys already rejects.
Architecture Diagram
text
Support session
|
v
runOpsAgent
|
+--> catalog parse
+--> read ports (workspace id from session)
+--> one propose
|
v
Lesson 45 ticket idem_${runId}
|
v
Human approval --> executeApproved once
text
Handbook assistant -- read, no import here
Workspace notes -- no import here
Lesson player -- no import here
Real-Time Enterprise Example
The support panel calls runOpsAgent with a scope built from the session. The enrollment adapter queries stalled learners WHERE workspace_id = northwind. Propose writes a Lesson 45 ticket. The lead approves in the queue UI. The route loads the ticket, checks approved, and calls the agent with ticketApproved: true. The mail adapter sends cohort_reminder_v1 to addresses it loads for lrn_priya. The agent trace shows the tool names. The audit shows the approver and eff_01.
A scripted probe sends shell.exec and expects zero proposes. Another sends both write names and expects zero proposes. Another includes lrn_contoso in the lookup table and expects the proposal to omit it.
Challenge: the model is down after a successful lookup, the lead double-clicks, and the flag is turned off after a ticket exists. Timeout returns model_unavailable if no ticket was saved yet. Double-click after propose does not create tkt_02. The flag stops a new run and leaves the existing checkpoint. The Lesson 45 route can still execute the approved ticket. The runbook says so. You do not add shell.exec to the catalog to "finish the refund manually" inside the agent.
Performance Optimization
The happy path is two model calls, one read, and one propose. The model sees ids, not a pasted roster of emails. Budgets stop a chatty model from turning one question into a dozen invoice reads. Resume does not repeat the lookup.
Do not hold the HTTP request open while the lead thinks. Return awaiting_approval. Execute is a later request. Interactive lookups use the provider and connector deadlines from Lesson 63. The agent process stays stateless apart from what the checkpoint store holds, so you can run more replicas without splitting the ticket.
Queue the execute side if the mail vendor is slow. The agent's request should return after executeApproved accepts the work or returns the effect id. It should not poll SMTP inside the loop. There is no loop on resume.
Security
Authentication. Empty identity fails. Session construction stays in Lesson 48.
Authorization. Only support_lead starts a run. Admins do not get a silent bypass in this package. Add them with a test if product requires it.
Tenant. Lookup, invoice read, propose, and execute receive the session workspace. A model workspaceId fails the parse.
Allow-list. Four names. shell.exec is tool_denied.
Arguments. Unexpected keys fail. Recipient ids are the lookup array.
Approval. The loop proposes. Lesson 45 executes. One write per run.
Idempotency.idem_${runId} for the life of the run, including execution_unknown.
Flag. This function stops. It does not delete tickets.
Secrets. The agent does not read SMTP_PASSWORD or a payment key. Adapters in Lesson 45 do, from the secret store.
OWASP. Broken access control is the role and the workspace. Injection is a tool name or an id in the model JSON. Unrestricted resource consumption is the step budget.
Common Mistakes
Executing the write in the loop. Symptom: mail leaves before approval. Cause: the write branch called SMTP. Fix: propose and awaiting_approval.
Trusting learnerIds from the model. Symptom: Contoso is on the ticket. Cause: the parser allowed the array. Fix: unexpected keys fail, and propose copies the lookup.
Allowing two writes in one run. Symptom: a refund and a mail from one sentence. Cause: the loop continued after propose. Fix: return on propose, and reject a payload that names two writes.
A second ticket on double-click. Symptom: two approvals. Cause: resume called the model again. Fix: a paused checkpoint returns immediately.
Rotating the idempotency key after execution_unknown. Symptom: two effects. Cause: a new key on retry. Fix: the same ticket and idem_${runId}.
Taking workspaceId from the tool JSON. Symptom: the lookup runs as Contoso. Cause: the port used the argument. Fix: invalid_tool_args, and pass the session id.
Letting an instructor start the run. Symptom: a teacher proposes a refund. Cause: the UI hid the button and the API did not check. Fix: support_lead only.
Adding tools by editing the prompt. Symptom: shell.exec starts working. Cause: the catalog was "whatever the model says." Fix: ALLOWED_TOOLS and tool_denied.
Putting the user text on the trace. Symptom: a learner's story is in the log vendor. Cause: trace(input). Fix: tool names and counts.
Importing the handbook assistant to write the email. Symptom: uncited prose in the template. Cause: scope creep. Fix: template id only.
Raising MAX_STEPS during an incident. Symptom: a runaway bill and a second write. Cause: the budget was treated as a bug. Fix: a new run, not a bigger loop.
Confusing the feature flag with "unsend." Symptom: on-call expects the flag to stop an approved execute on Lesson 45. Cause: the two switches were conflated. Fix: the runbook line from phase 5.
Best Practices
Keep four tools in the catalog until a review adds a fifth.
Parse with an exact key set per tool.
Deny unknown tool names.
Reject workspaceId, amounts, and recipient lists from the model.
Run reads with the session workspace.
Propose writes. Do not execute them here.
Allow one write per run.
Require a prior read before a write.
Use idem_${runId} for the ticket.
Stop the loop on propose.
Resume from the checkpoint.
Execute through Lesson 45 once.
Keep execution_unknown on the same ticket.
Enforce step, model, and tool budgets.
Restrict the role to support_lead.
Honor the feature flag without deleting tickets.
Trace tool names, not prompts.
Keep payment and SMTP secrets in the executor adapters.
Test Contoso filtering, unknown tools, double writes, and replay.
Ship the read-only phase before propose.
Document the flag versus the approval route.
Pass readiness-v1 for ops-agent-api.
Do not import the workspace or the handbook package.
Do not raise the budget to finish a stuck run.
Keep the lesson player off this endpoint.
Interview Questions & Answers
Beginner
What can this agent do by itself?
It can read enrollment or one invoice for the session workspace. It can propose one email or one refund. It cannot send or refund until a person approves the ticket.
Why is shell.exec denied?
It is not on ALLOWED_TOOLS. The parser returns tool_denied and does not call propose. Adding a tool is a code change with a test.
What is the idempotency key? idem_ plus the run id. Resume uses the same ticket. A second click does not create another key.
Intermediate
Where do reminder recipients come from?
From enrollment.lookup for the session workspace. The email tool accepts a template id only. A learnerIds array on the model JSON is invalid_tool_args.
What happens if the model asks for a refund and an email together?
The parser rejects the payload. Propose count stays 0. The lead starts a second run if both actions are really required.
What does resume do before approval?
It returns awaiting_approval and does not call the model, lookup, or propose. After the route has seen an approved ticket, resume calls executeApproved once.
Senior
How do you test this without SMTP or a card processor?
Script model with JSON strings. Script lookup to return Northwind ids only. Count propose and executeApproved. Assert Contoso never appears in the proposal. Contract-test the real adapters in Lesson 44 and Lesson 45 with fixture ids.
How is this different from Lesson 47?
Lesson 47 always looks up one lesson and proposes one template. This agent may choose lookup, invoice read, email, or refund, under a budget. The safety properties match: server-side ids, one ticket, human execute, stable idempotency key.
Architect
How do you add a tool?
Add the name to the catalog, the allowed keys, the port method, and tests for denial of extra keys and for tenant scope. A write tool proposes and stops. It does not get an execute branch in this file. Review the runbook and the readiness profile. A prompt-only change is a defect.
How do you roll this out?
Enable phase 2 reads for one support lead at Northwind. Watch tool names and tool_denied. Enable propose with the flag. Keep execute on the Lesson 45 route. The player, the workspace, and the handbook stay on their own deploys so an agent bug does not block reading.
What do you refuse in an incident?
You refuse to execute inside the loop, to accept model ids, to raise MAX_STEPS so a run can "finish," and to point the lookup at all workspaces because Northwind's query was empty. Empty lookup means there is nothing to propose.
Where should handbook prose live?
In Project 2, as a cited answer. If a reminder needs a sentence from the guide, that is a new template version a person approves. This agent still sends cohort_reminder_v1 or proposes a refund. It does not paste assistant text into the ticket body.
Knowledge Check
1. What problem does this capability solve?
It lets a support lead gather enrollment or invoice facts and propose one side effect, with an allow-list, a budget, and a human approval, without turning the model into a payment client.
2. What alternatives exist, and when would you choose each?
Lesson 47 is enough when the only job is the stalled-learner reminder. A form the lead fills by hand is enough when no model is required. This agent is the right product when the lead's words may map to more than one read and at most one write. The handbook assistant is the right product for policy questions.
3. Which data, identity, and trust boundaries matter?
The session supplies workspace and the support-lead role. Read ports supply ids. The model supplies a tool name and a small enum or key. Lesson 45 supplies approval and the effect. Traces do not store the prompt.
4. What can fail, and how should the system respond?
Disabled, unauthorized, unknown tools, bad arguments, missing prior reads, and budgets stop without a ticket. Propose pauses. Resume waits or executes once. Provider failure before a ticket is model_unavailable.
5. How would you test quality, security, performance, and cost?
C1–C13 cover role, flag, tools, tenants, replay, and budget. Security tests assert Contoso ids and shell.exec never propose. A performance test asserts resume does not call the model. A cost test asserts the disabled flag does not call the model.
Practical Exercise
Implement packages/ops-agent/src/ and tighten parseToolCall so each tool accepts only its allowed keys. Make recipients_from_lookup, unknown_tool_denied, and resume_does_not_repropose pass. Add one_write_per_payload. Write the runbook sentence that separates this feature flag from the Lesson 45 execute route.
Deliverable and Rubric
Submit the sequence diagram, the catalog table, the phase plan, the agent package, the test output, and the readiness profile.
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:
Only support_lead starts a run.
The catalog is four tools.
Unknown tools are denied.
The model cannot set workspace, recipients, or amount.
Reads use the session workspace.
One write is proposed and the loop stops.
The idempotency key is idem_${runId}.
Resume does not propose again.
Execute goes through Lesson 45 once.
Budgets are enforced.
Traces omit prompts and amounts.
The flag does not delete tickets.
ops-agent-api passes readiness-v1.
The player, workspace, and handbook do not import this loop.
Key Takeaways
ops-agent-v1 is a bounded loop, not an open shell.
Four tools are the catalog.
Reads execute. Writes propose.
One write ends the run.
Ids come from the read ports.
Extra JSON keys fail closed.
shell.exec never proposes.
Only a support lead can start the run.
idem_${runId} stays stable.
Resume waits or executes once.
Budgets stop a chatty model.
The feature flag stops new work and keeps tickets.
Traces store tool names.
Lesson 45 remains the executor.
The handbook and the workspace stay separate products.
Summary
Lesson 66 is the business-operations agent as a product with a short allow-list and a hard stop at approval. TechLearningPro support can look up who is stalled or which invoice is in dispute, and can propose one reminder or one refund. The agent does not get a payment credential, a shell, or a second write in the same run. Lesson 47's reminder is still the right tool when the path is fixed. This project is the right tool when the lead's request may be a read or a single proposal. The next capstone leaves operations and opens documents: images and files, with the same habit of tenant scope, explicit side effects, and a readiness gate.
Next Lesson Preview
Project 4: Multimodal Document Intelligence Platform takes PDFs and images through an ingest pipeline that extracts text a person can review. You will keep tenant isolation on every file, avoid sending a whole archive to a model in one request, and decide which extractions become handbook chunks for the assistant you just kept on the read path. The ops agent will not gain a file-delete tool in that project.