Day 4 - Start the Digital Twin: Read a PDF and Master System Prompts
Week 1 · Day 4 · Lecture 19. Lab file: 1_foundations/3_lab3.ipynb. This starts a two-day lab where you hand-crank your own agent loop from scratch, with no agent framework. First comes the groundwork for a project that will become a digital twin of yourself, plus a quick refresher on system prompts, conversation history and the illusion of memory.
The project: a digital twin of yourself
Over today and tomorrow you build something with real value by the end of the week: a digital twin that could ultimately be deployed as a career twin, able to answer questions from employers or clients about you and your skills. The instructor calls it the resume of the future, and invites you to take it in your own direction and make it personal.
Prepare two files in the twin folder
Inside the 1_foundations folder there is a subfolder called twin. Put two files in it:
linkedin.pdf- a PDF of your own LinkedIn profile. On LinkedIn, click your name to open your profile, use the three-dots button and choose "Save to PDF". If you do not have that option (different plan, type of LinkedIn or region), print the profile to PDF, use any resume PDF, or write notes about yourself and save them as a PDF. A PDF is not strictly required because the lab could read a text file, but it is a nice one to try out.summary.txt- a short couple of sentences about yourself. The instructor's version starts with his name and mentions he dislikes cheese. Edit the provided file so it reflects you.
Use all-lowercase file names. Windows and Mac are case-insensitive, so it seems not to matter, but later in the course you will deploy this to a free Linux box, and Linux file systems are case-sensitive. People have hit sneaky problems when linkedin.pdf was not spelled in lowercase. All files in this folder should be lowercase.
Packages and setup
- Gradio - a package for user interfaces, used here without much explanation (the instructor covers it in the core track).
- pypdf - reads PDF files.
How were these picked, and how do you decide which packages a new project needs? The instructor answers that thoroughly in question 37 of the LinkedIn FAQ; the short answer is that you have to put in the work. The notebook then runs its imports, loads your .env variables and creates the OpenAI Python client. If you want a different LLM, use the instructions in guide 9, which you should know well by now.
Reading the PDF into text
The code is short enough that a coding agent would write it for you in a heartbeat: create a PDF reader pointed at linkedin.pdf, loop over the pages and call page.extract_text() to pull out the raw text. An illustrative sketch of what the cell does:
from pypdf import PdfReader
reader = PdfReader("twin/linkedin.pdf")
linkedin = ""
for page in reader.pages:
text = page.extract_text()
if text:
linkedin += text
print(linkedin)
Printing the result shows all the text from the profile, but unstructured: skills mixed in with jobs and summaries. That does not matter, because LLMs are fantastic at handling unstructured data and interpreting it intelligently. The notebook then reads summary.txt the same way and prints it to check that it came through.
Sidebar: three foundational ideas
If you took the core track, you can zoom through this. If not, take time to experiment, and look at the first week or two of the core track to go deeper.
1. The system prompt
The text sent to an LLM can be structured. The API takes a list of dictionaries, each one a different section of the input sequence. The first is often the system prompt: it sets the overall framing and role the LLM plays, the style it should take, and any background information that helps it generate tokens. The LLM was trained on data organised this way, so it learned to treat the part marked as "system" as the overall context for how to reply to the user's message.
2. Conversation history
After the system prompt comes a series of messages: user, then the assistant's reply, then the next user message and reply, ending with the final user message the LLM should answer. That series is the conversation history. So far the course has only sent a single user message.
3. The illusion of memory
Every call to an LLM is stateless: the model does not know it was called before. The trick is that you always include the full conversation so far in the input, so the reply takes it all into account and appears to remember. This is why you can refer back to something in ChatGPT and the conversation carries on. Yes, you pay for those input tokens every time, but that is what you want: calculations over everything said so far. You could send only the last message, but the conversation would be weird. Tools like ChatGPT also have other forms of memory, which just means extra information from earlier conversations added into the system prompt, and so still part of the input sequence.
Demonstrating it in the notebook
- Basic call. messages is a list of dicts: a system message "You're a helpful assistant" and a user message "Hi, my name is Ed". Call
openai.chat.completions.createwith model gpt-5.4-nano and printresponse.choices[0].message.content. The reply is a polite hello to Ed. - Change the system prompt. Same user message, but the system message is now "You are a snarky, witty assistant". The reply turns snarky.
- Test statelessness. Keep the snarky system prompt but ask only "What's my name?". The model says it does not know: this chat has not given it a name. It does not remember the earlier call.
- Add conversation history. Send a longer list: the snarky system message, user "Hi, my name is Ed", assistant "Well hi there Ed, it's nice to meet you", then user "What's my name?". Now it answers correctly. The assistant message does not need to be what GPT really said; you could put anything there and it would work.
A Jupyter tip from the demo: re-running a cell redefines its variable, and what matters is which cell you executed last. If you forget to re-run the cell that defines messages, it still holds the previous version.
If this is your first time with these ideas, iterate: ask different questions, experiment with the system prompt, and play with the user, assistant, user conversation-history pattern until you have a good feel for it.
What you should now understand
- You need two lowercase files in the twin folder:
linkedin.pdfandsummary.txt, because the deployment target is case-sensitive. - pypdf extracts raw text from a PDF; the LLM can make sense of unstructured text.
- The system prompt sets the role, style and background; the conversation history is the series of user and assistant messages.
- An LLM is stateless: the memory you see is you sending the whole history on every call.
Resource links
Next
On to the main plot: a Gradio chat UI and defining your first agent tool.