Compiled on: 2026-10-22 — printable version
AI algorithms capable of automatically generating content, e.g.:
Natural language helps people communicate
It can be used to express complex or abstract concepts
It can be used to reason about problems and solutions
Natural language allows LLMs to use intuition in reasoning, like humans do
(thus making mistakes like humans do)
$\implies$ LLMs can be very confident in themselves, while saying incorrect, imprecise, or made-up things
better would be to combine LLMs with symbolic AI tools, to get the best of both worlds
(cf. Thinking, Fast and Slow)
Cost models:
Consumption is measured based on the computational effort required to serve the request:
Generation should be considered a stochastic process by construction
- The quality of the service is subject to randomness and fluctuations due to:
- service load
- model choice, and its related updates
- service limits possibly reached in the current time window
- chance
- But also: data leave your premises, costs scale, provider lock-in, GDPR and AI Act apply (cf. on-premise models, and the governance lecture)
Sampling bias: GenAI knows only what it has been trained on + the pious hope that it learns to generalize
Learning uses data taken from the Web + possible provider-owned company data
- Niche information may not be learned correctly (or at all)
- It is essential to avoid sharing sensitive, confidential, or copyrighted information
Learning cycles are extremely expensive in terms of money and computational resources…
… performed periodically (weeks? months?) to improve the quality of the service
- Recent information may not have been learned yet
- There is a risk of receiving outdated or incomplete answers from GenAI
- GenAI gives the impression of learning during the conversation, but its weights are only updated offline
- within a conversation, it just re-reads the whole history at each turn (cf. stateless APIs)
- “memory” features of chat apps store notes about the user, and put them back into the context of later conversations
(cf. regulation in the governance lecture)
Non-exhaustive list!
from openai import OpenAI
client = OpenAI() # reads the API key from the OPENAI_API_KEY env variable
stream = client.chat.completions.create(
model="gpt-5-mini",
messages=[
dict(role="user", content="European countries, one by line")
],
stream=True, # receive the response token by token
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")
Output (excerpt, may vary):
Albania
Andorra
Austria
Belarus
Belgium
...
Programming language interacting with AI
The interaction remains of the request-response type
openai library: chat.completions.create(...) sends the messages of a chat (each with a role and a content) to a modelstream=True), each carrying a piece (delta) of the generated textParametric prompts, responses processed automatically
list of LOCALITIES in AREA, one by line
LOCALITIES $\in$ {cities, regions, states}AREA $\in$ {Europe, Asia, Africa, America, Oceania}Writing software that uses AI as a service
GenAI integrated into desktop or web applications
support for an internal conversational interface
AI automates complex operations (within the app)
One-shot interaction to generate content
The interface then allows
| Vendor | Front-ends | Models | License | |
|---|---|---|---|---|
| Claude Code | Anthropic | CLI, IDE, desktop, web | Claude | proprietary |
| Codex | OpenAI | CLI, IDE, desktop, web | GPT | Apache-2.0 (CLI) |
| OpenClaw | OpenClaw Foundation | self-hosted, messaging apps (WhatsApp, Telegram, Slack, …) | any (hosted or local) | MIT |
| Cursor, Copilot (agent mode) | Anysphere, GitHub | IDE | various | proprietary |
CLAUDE.md, AGENTS.md)These are themselves LLM-based agentic software: the kind of system this module teaches you to build
Why do people care about software in the first place? (cf. Introduction to Software Engineering)
Most people do not care about algorithms, software, or agents per se…
… they care about automating the solutions to their problems
Classic software automates problems which are repetitive and structured enough to be coded
GenAI widens the set of automatable problems
Not mutually exclusive!
(1) only: coding an ordinary Web application (no AI inside) with the help of Claude Code
(2) only: a script which extracts structured data from recommendation letters
(3) only: a customer-support chatbot which decides which tools to call (e.g. look up orders, open tickets)
| Combination | Example |
|---|---|
| (1) + (2) | the letter-extraction script, written with a coding assistant |
| (2) + (3) | an agent whose tools are themselves LLM-based workflows (e.g. the tender example) |
| (1) + (3) | an agentic product built with a coding agent |
| (1) + (2) + (3) | an assistant for a PhD admission committee (our running example): workflows to extract data from candidates’ documents, an agent to answer the committee’s questions, all coded with a coding agent |
An LLM produces text, not action
Book the train to Lisbon is just text…Are LLMs agents? Not really, not fully, not by themselves
In both (2) and (3), the “agent” is mostly the surrounding software
get approval, then submit hides who approves, how approval is checked, and what submission changesCombine prompts, tools, vector stores, and agents to constrain and govern the behavior of pre-trained (foundation) models, in order to:
write an evaluation paragraph for each student's work)find the parties involved in this contract)plan a vacation itinerary based on user preferences)Foundation models (FM, always pre-trained): large neural-networks trained on massive datasets to learn general skills (e.g. ‘understanding’ and generating text, images, code), most commonly accessed as-a-Service via API, as provided by third-party companies
Prompts: carefully crafted textual inputs that guide some FM to produce desired outputs
Write a summary of the following article: {article_text}Tools: external software components (e.g. WebAPIs, databases, search engines) that FMs can ask to invoke (the invocation is performed by the surrounding software), to perform specific tasks or retrieve information
Vector stores: specialized databases that store and retrieve high-dimensional vectors (embeddings) for the sake of information retrieval via similarity search
Agents: software systems that orchestrate the interaction between FMs and tools, enabling dynamic decision-making and task execution based on the context and user input
(i.e. a product exploiting GenAI as per dimensions (2) and (3))
FM are commonly not produced in-house, but rather accessed via APIs… yet the choice of what model(s) to use is crucial
InferenceClient, etc. (or local runtimes, e.g. Ollama, Transformers, cf. LLM-as-a-Service)A set of prompt templates (text files, or code snippets) that are known to work well for the tasks at hand (cf. prompting)
A set of tools that FMs can ask the application to invoke
A set of agents, implementing the logic to orchestrate the interaction between FMs and tools
A set of vector stores (if needed), populated with relevant data, and accessible by the agents
Evaluations (deterministic scorers + LLM-as-a-Judge) to assess the quality of the outputs produced by the system, and to guide the improvement of prompts, tools, and agents
A set of workflows (if needed): code-controlled flows (state machines) whose steps call FMs, for procedures that must be reliable
A set of skills (if needed): packaged instructions and scripts that agents load on demand
Governance decisions: where models run (cloud vs. on-premise), at which cost, and under which regulations (e.g. the AI Act)
| Component | Lecture |
|---|---|
| FMs, as-a-Service or on-premise; client libraries | LLM-as-a-Service (+ free access) |
| Prompts, prompt templates, structured outputs | Prompt engineering |
| Evaluations | Validating generative software |
| Tools, MCP servers, agents | Tools and agents |
| Vector stores | Retrieval-Augmented Generation |
| Skills | Agentic skills |
| Workflows, multi-agent systems | Workflows |
| Model selection, deployment, regulation | AI governance |
| Technique | Pattern template | Description |
|---|---|---|
| Role playing | You are an expert in {field} known for {key adjective}. Help me {task}. |
telling the AI to act as a famous expert or celebrity |
| Style unbundling | Describe the key elements of {expert}'s style/skill in bullet points. Do {task} in the following style: {style}. |
describe what you like about a style, rather than copying it directly |
| Emotion prompting | Help me {task}. Please make sure {attribute}. This task is very important for my career. |
use emotional pressure and persuasion with the AI |
| Few-shot learning | Here are some examples of {task}. Generate a {task} for {new context}. |
add examples of the completed task to the prompt |
| Synthetic bootstrap | Generate ten examples of {examples} for {context}. Here are the inputs: {inputs}. Generate {task} using {examples}. |
use AI to generate good examples of the completed task |
(source: Lenny’s Newsletter)
{placeholders} are filled with actual data at runtime $\rightarrow$ prompt templates (cf. prompting)(more on this in the validating lecture)
(The lifecycle of engineering products as per dimensions (2) and (3). Similar to the ML lifecycle in the sense that the goal is to process data, but different in many details: e.g. training is optional, and commonly not performed in-house, as pre-trained FMs are exploited)
Foundation model selection: choose the most suitable FM(s) based on task requirements, performance, cost, data protection, and availability
Prompt engineering: design, test, and refine prompt templates to elicit the desired responses
Evaluations: establish assertions and metrics to assess FM responses to prompts (attained by instantiating templates over actual data)
Tracking the data-flow between components (agents, FM, tools, vector stores) to monitor costs, latency, and to debug unexpected behaviors
Support public officers in managing tenders through a GenAI assistant that understands and compares procurement decisions transparently.
Scope
Problem Framing:
Data Collection: past tenders’ technical specifications and acts; regulatory documents; previous evaluations (with the officers’ scores)
Data Preparation:
Select
Adapt and align
Vector stores: embeddings for tender documents & specs, legal texts & guidelines, previous evaluations, templates
Prompt Engineering: templates for check-list extraction, justification, and Q&A
You are a procurement evaluator…), placeholders for retrieved chunks, iterate on manual testsEvaluations: past tenders (with the officers’ scores) as validation set
Application integration
Tools: regulation lookup API, tender database query API, report generation out of document templates
Workflow + Agent:
Tracking & Oversight:
Answer in your own words, motivating your conclusions and using examples where useful.
Questions asking whether something is possible or desirable require more than a yes/no answer.
Implementation questions can be answered with an explanation or pseudocode unless executable code is explicitly requested.
Labels identify the primary learning target:
Practical answers should identify the technology used, without requiring memorisation of product-specific details (model names, prices, API signatures, versions, limits).
[notions, theoretical] What is generative AI? How are foundation models, large language models, and multimodal models related?
[notions, theoretical] How does an LLM generate text? What roles do tokens, context, and temperature play?
[reasoning, theoretical] How does the training of a foundation model affect what it can and cannot do? Why might it perform poorly on recent or uncommon information?
[reasoning, theoretical] If a chatbot remembers what you told it, has it learned something? Discuss the possible meanings of “learning” in this case.
[reasoning, theoretical] Why can an LLM produce a convincing but incorrect answer? Would making its output deterministic solve the problem?
[reasoning, theoretical] What are the benefits and limitations of combining language-based reasoning with symbolic computation? How does this relate to the distinction between intuitive and deliberate thinking?
[know-how, practical] What kinds of interfaces to generative AI systems are available? Choose examples of existing applications and explain what tasks you would use them for.
[reasoning, practical] What is the difference between a language model and an application built around it? Using an application you know, discuss which capabilities require more than text generation.
[reasoning, theoretical] How can generative AI be used in software engineering? Distinguish its use in developing a product from its use within the product.
[know-how, theoretical] Give an example of a task for which generative AI is useful and another for which ordinary software is preferable. What makes the difference?
[reasoning, theoretical] Can an AI-text detector establish whether a student wrote an assignment? What would make its result convincing or unconvincing evidence?
[notions, theoretical] What activities does engineering a generative AI application involve? How does its lifecycle differ from that of ordinary software and of classic machine-learning projects?
Compiled on: 2026-10-22 — printable version