Part 1
The situation
Stackademy is an online code academy. It offers 48 computer science courses, from CS101 Introduction to Computer Science to CS408 Professional Practice: web development, databases, cloud architecture, machine learning, even quantum computing. Each course has a code, a short description, a price between $450 and $1,000, and usually a prerequisite. You take CS301 Machine Learning after CS210 Artificial Intelligence, which you take after CS107 Algorithms.
Every day, prospective students ask the same kinds of questions:
- “Do you offer any courses on AI?”
- “My budget is $1,000. What courses can I take?”
- “I want to study programming. Where should I start?”
Stackademy wants an assistant on its web site that answers them accurately, at any hour. That sounds like the easiest AI project there is. It isn’t, and the reason why is the subject of this case.
Part 2
The problem: the answers are in a private database
An AI model, however capable, knows only what was in its training data: a snapshot of the public internet. Stackademy’s catalogue was never in it. It lives in Stackademy’s own database, behind a password, like most of the data that any organization runs on: products, prices, inventory, policies, customers.
So a model asked about Stackademy’s courses can do one of two things. It can say that it doesn’t know, which helps nobody. Or it can make something up: a plausible course, at a plausible price, that doesn’t exist.
Better instructions can’t fix this, because the knowledge isn’t in the model. Pasting the whole catalogue into the prompt doesn’t scale either: real catalogues are large, they change, and every token of a prompt is paid for on every turn. A prompt that’s out of date is just a slower way to be wrong. The model has to be able to ask the database.
Part 3
Tool calling: how a model asks the database
Modern AI models can do something better than guess: they can ask for help. The application tells the model which tools it may use, and what each one does. When a question needs one, the model doesn’t answer. It asks the application to run the tool, and says with which values. The application runs it, and hands the result back, and the model answers from those facts.
Student
Stanley
Smarter LLMClient
AI model
e.g. OpenAI
Course database
private
- 1My budget is $1,000. Which AI courses can I take?
- 2the question, and the description of the course search tool
- 3call the course search tool, with description = AI, max_cost = 1000
- 4SELECT … WHERE description LIKE '%AI%' AND cost <= 1000
- 5CS210 Artificial Intelligence, $700, …
- 6the rows that the tool found
- 7an answer, written from those rows
- 8You can take CS210 Artificial Intelligence, for $700…
- 1
StudentStanley
My budget is $1,000. Which AI courses can I take? - 2
StanleyAI model
the question, and the description of the course search tool - 3
AI modelStanley
call the course search tool, with description = AI, max_cost = 1000 - 4
StanleyCourse database
SELECT … WHERE description LIKE '%AI%' AND cost <= 1000 - 5
Course databaseStanley
CS210 Artificial Intelligence, $700, … - 6
StanleyAI model
the rows that the tool found - 7
AI modelStanley
an answer, written from those rows - 8
StanleyStudent
You can take CS210 Artificial Intelligence, for $700…
Part 4
Why connecting a private database is hard
Figure 1 looks simple. Building it isn’t. Every arrow is code that someone has to write, secure and maintain, and it’s different for every database, every web API and every AI provider:
Describing the tool
Each query must be described as a function with typed parameters, in the format that each AI provider expects. They all differ a little.
Making the model’s values safe
The model chooses the values from whatever the user typed. Pasted carelessly into SQL, they let a user rewrite the query: SQL injection.
Reaching the database
A private database needs a network route, a driver, a pool of connections and timeouts, sometimes a tunnel or a proxy.
Keeping the credentials secret
The password must be stored encrypted, and never reach the model, the prompt, the chat or the logs.
Running the conversation
Send the question and the tools, receive the call, run it, trim the rows to fit, send them back, repeat until the model answers.
Operating it
Log every call, cache repeated queries, control costs, and change any of it without breaking the assistant people depend on.
It’s a software project in its own right. That’s why most teams that want an AI assistant over their own data never finish one.
Part 5
The solution: plugins, described instead of coded
Smarter’s plugin architecture does every step above. You describe what you want, in short YAML text files called manifests, and the platform does the rest:
| Manifest | What you write | What Smarter does with it |
|---|---|---|
| Secret | the database password | Stores it encrypted. Nothing else ever spells it out, and the model never sees it. |
| SqlConnection | the database’s address and user, and the Secret’s name | Connects securely, with a pool of connections and timeouts. |
| SqlPlugin | the SQL query, and its parameters described in plain words | Describes the tool to the model, puts the model’s values into the query safely, runs it and returns the rows. |
| LLMClient | the AI model, its instructions, and the plugins it may use | Runs the whole conversation with the AI provider, tool calls included, and serves the chat. |
The same holds for a web API, with an ApiConnection and an ApiPlugin. Stackademy’s catalogue lives in both places, as data often does: in the registrar’s database, and behind the catalogue’s web API. These are the two most common uses of tool calling, so the project builds its advisor, Stanley, twice, once over each, so that you can compare them. Neither needed a line of code.
Part 6
Lab 1: Talk to Stanley
Both advisors below are live. They are the same Stanley, with the same instructions, except for the tool each may use. Work through the experiments in both chats, and compare what you see.
Stanley, over the database
SqlPlugin · stackademy-sql.yaml
Stackademy SQL
Built and run on Smarter
Try asking
- Do you offer any courses on AI?
- My budget is $1,000. What courses can I take?
- I want to study programming. What do you suggest?
Needs a ubc.smarter.sh login. Or run it yourself.
Stanley, over the web API
ApiPlugin · stackademy-api.yaml
Stackademy API
Built and run on Smarter
Try asking
- Do you offer any courses on AI?
- My budget is $1,000. What courses can I take?
- What is the capital of France?
Needs a ubc.smarter.sh login. Or run it yourself.
Experiments
1Ask: “My budget is $1,000. Which AI courses can I take?”
Observe. Both advisors list the same four courses, CS210, CS316, CS319 and CS405, with real prices. The model chose max_cost = 1000 and description = AI from your sentence.
2Ask: “What are the prerequisites for those courses?”
Observe. Compare the two. The SQL query joins the course table to itself, so the SQL advisor receives each prerequisite’s name. The web API returns only a prerequisite_id number, so the API advisor may not be able to name them. What a tool returns limits what the assistant can say.
3Ask: “Do you offer a course on COBOL?”
Observe. COBOL isn’t one of the values the tool allows, so the model searches without that filter, reads the catalogue, and reports that there’s no such course, instead of inventing one.
4Ask: “What is the capital of France?”
Observe. Stanley declines. His plugin’s instructions confine him to Stackademy’s courses: an assistant’s scope is part of its design.
In the Smarter web console, the same advisors open in the Prompt Engineer’s Workbench, whose console shows each tool call: the values the model chose and the rows that came back. Every Smarter platform loads this project, so they’re in yours too. Install Smarter to look inside.
Part 7
Anatomy of the project
Neither advisor is one thing. Each is built from several resources, each with one job, and each of which depends on others. Every resource is described by its own manifest, in the smarter-sh/stackademy repository on GitHub.
The database advisor
The web API advisor
5. Budget, applied last
A spare Secret
- A Secret keeps a password or key, encrypted, so that nothing else has to spell it out.
- A Connection says how to reach a data source, and which Secret holds its password.
- A Plugin is a tool the model may call: what it does, in words the model understands, the filters it takes, and the Connection it uses.
- An LLMClient is the assistant itself: its model, instructions, personality, tools, and the look of its chat.
- A Budget limits what the resources it lists may spend.
Part 8
How to read a manifest
Every Smarter manifest, of every kind, has the same five sections. Learn them once and you can read any of the ten files, or the hundreds in a larger project. Open stackademy-sql.yaml beside this list.
- apiVersion
- The version of the manifest format, always smarter.sh/v1 today. It lets the format change one day without breaking the files you have.
- kind
- The kind of resource: Secret, SqlConnection, SqlPlugin, LLMClient, Budget… The kind decides what the spec may contain.
- metadata
- What the resource is called and what it’s about: its name, which other manifests use to refer to it, a description, a version, tags and annotations.
- spec
- The specification: what the resource should be. It’s the heart of the manifest, and different for every kind.
- status
- What the resource is right now: when it was created, whether it’s deployed. The platform writes it; you never do, so no file in the repository has one.
Annotations, in metadata, deserve a note. Smarter stores them exactly as written and never interprets them. They’re how a team connects its own systems, a billing cost center, an on-call owner, a compliance review date, to a resource, as Kubernetes annotations do for operators. Because they live in the manifest, they are reviewed in the same pull request as the prompt.
Part 9
Close reading: the SqlPlugin
stackademy-sql.yaml is where tool calling happens, and it rewards a careful reading. Its sqlData holds the query:
SELECT c.course_code, c.course_name, c.description, c.cost,prerequisite.course_code AS prerequisite_course_code,prerequisite.course_name AS prerequisite_course_nameFROM courses cLEFT JOIN courses prerequisite ON c.prerequisite_id = prerequisite.course_idWHERE ((c.description LIKE CONCAT('%', {description}, '%')) OR ({description} IS NULL))AND (c.cost <= {max_cost} OR {max_cost} IS NULL)ORDER BY c.prerequisite_id;
The model never sees this query. It sees the parameters, each with a description in plain words, and decides from them, and from the student’s question, what to fill in. “My budget is $1,000” becomes max_cost: 1000. Writing those descriptions well is prompt engineering too. The SqlPlugin is one of six off-the-shelf plugins; see them all, and a 60-second video of this one, on the plugins page.
Two safety mechanisms
Parameterized values. Smarter inserts each value into its {placeholder} as a quoted, escaped literal. Whatever a student types, it can only ever be a value, never more SQL. That closes the door on SQL injection, one of the oldest and most damaging attacks on the web.
An enum of allowed values. The description parameter may only be one of AI, mobile, web, database, network or neural networks: the keywords the course descriptions actually use. The model can’t invent a filter that matches nothing. You saw the consequence in Lab 1: asked about COBOL, Stanley searched without a filter and reported honestly that there was no such course.
The same tool, over a web API
stackademy-api.yaml declares the same two parameters, but its apiData names an endpoint and a method instead of a query: the model’s values become the request’s query string, ?max_cost=1000&description=AI. Same question, same model, a different contract with the data. As Lab 1’s second experiment showed, what the tool returns sets the ceiling on what the assistant can say.
Part 10
Lab 2: The manifest editor
Here are all ten manifests, read live from GitHub. Change anything. As you type, the editor checks the YAML, then validates it against the JSON Schema that the Smarter platform publishes for its kind: the very check that runs on every pull request to the repository. Hover over any key for an explanation.
Exercises
- aHover to learn. Open llm-clients/stackademy-sql.yaml, and hover over defaultSystemRole, allowedOrigins and plugins. Each explanation comes from the LLMClient JSON Schema, the same one the VS Code extension uses.
- bBreak a type. Change defaultTemperature: 1.0 to defaultTemperature: warm. The check fails, names the key, and says what it must be.
- cRemove something required. Delete the description line under metadata. Which section reports the problem, and why there?
- dAdd your own annotation. Add - example.edu/course/section: "AI-101" under annotations. It stays valid: annotations are yours, and Smarter stores them without interpreting them.
- eFollow a reference. In plugins/sql/stackademy-sql.yaml, find connection. Then open the manifest that it names. What would happen if the names didn’t match?
Part 11
Governing the project with git
A prompt is code. A one-word change to Stanley’s instructions can change every answer he gives. Yet prompts are often edited in place, in a web form, with no record of who changed what, or why, and no way back. Ten resources are already more than one person should keep in their head; real projects have hundreds, changed by many people over months.
Keeping the manifests in GitHub gives an AI project the habits that software teams depend on:
History
Every change is recorded: what, who, when and why. When an assistant starts answering differently, you can see exactly what changed.
Undo
Any earlier version of any file can be brought back, even months later.
Review
Changes are proposed, discussed and approved before they reach users, like Suggesting mode in a shared document, for the whole project at once.
Safe experiments
Try a new prompt on a branch, a copy of the project, without touching the version in use.
Automatic checks
Every proposed change is validated against its kind’s schema before anyone reviews it.
One source of truth
The repository is the complete description of the project. Any Smarter platform can rebuild it from these files alone.
A change, the GitHub way
- 1Open the manifest on GitHub, and choose the pencil icon. GitHub offers to fork the repository if you can’t edit it.
- 2Change a line, e.g. Stanley’s appWelcomeMessage.
- 3Commit the change to a new branch, with a message that says what and why.
- 4Open a pull request, which shows the change line by line.
- 5The automated checks run: the schema check you tried in Lab 2, plus YAML style, typos and leaked private keys.
- 6A reviewer comments, approves and merges. The change is now part of main, ready to apply.
Spending is governed too. stackademy-project.yaml caps the database advisor at $2,500 a month and $10,000 over the project’s six months, warns at 80%, and then refuses further requests. Only a platform administrator may apply a Budget: the people who build assistants aren’t the ones who set their limits.
Part 12
Discussion questions
For a classroom, a study group, or your own notes.
- Q1
Stackademy’s catalogue changes every term. Why is tool calling a better design than putting the catalogue in the system prompt? When might the prompt be the better choice?
- Q2
The SQL advisor receives each prerequisite’s name; the API advisor receives only its id. Who should decide what a tool returns: the database team, the API team or the prompt engineer? What does that imply for how teams collaborate?
- Q3
The description parameter’s enum lists six keywords. What does the enum prevent? What does it cost the student who asks about a topic that isn’t on the list?
- Q4
Names are references: the LLMClient names its plugin, the plugin its connection, the connection its Secret. What breaks if someone renames a resource in the web console but not in the repository?
- Q5
Budgets can only be applied by a platform administrator. Why might an organization want spending limits governed separately from the assistants themselves?
- Q6
A prompt engineer edits Stanley in the web console and it works. Why should the change still go through a pull request?
Part 13