You will be able to
- Create a Python virtual environment and install LangChain dependencies from a requirements file
- Connect a chat model from OpenAI or Anthropic using API keys stored in a .env file
- Define a Pydantic schema and a parser so the LLM returns structured, predictable output
- Build a tool-calling agent with an AgentExecutor and run it from user input
- Wrap a DuckDuckGo search, a Wikipedia lookup, and a custom Python function as agent tools
- Handle parsing errors and save structured agent results to a text file
Good to know first
- Python 3.10 or newer installed, with basic Python syntax such as classes and functions
- Comfort running commands in a terminal and using a code editor such as VS Code
- Basic understanding of what an LLM API is and how to call it
- An OpenAI or Anthropic account with an API key
Syllabus
9 lessons and a final project
- 1
Demo of the finished research assistant Free
You see the finished AI research assistant run from the terminal: you type a topic, the agent searches Wikipedia, saves a summary to a file, and prints a structured report. This lesson shows what the finished agent does so you know the goal before you build it.
4 build steps2 exercises3 questions - 2
Setting up the project folder and virtual environment Beyond Pass
You will create a project folder, list the Python packages the agent needs in a requirements.txt file, and set up an isolated virtual environment (venv) to install them into. By the end, your terminal shows the (venv) prefix and the packages are installed.
5 code5 build steps2 exercises3 questions - 3
Choosing an LLM and Loading API Keys Beyond Pass
You will set up main.py to create a language model (either OpenAI's or Anthropic's Claude), store your secret API key safely in a .env file, and run a first test call. The chapter shows how each piece connects so your agent can talk to an AI model.
2 code5 build steps2 exercises3 questions - 4
Defining a Pydantic schema and prompt template Beyond Pass
You will define a Pydantic class that describes the shape of the answer you want from the LLM, and build a prompt template that tells the model to follow that shape. Together they make the model's output predictable enough for your code to use as a normal Python object.
1 code4 build steps3 exercises3 questions - 5
Creating the tool-calling agent and executor Beyond Pass
You will fill in the prompt's format instructions with partial(), build a tool-calling agent with create_tool_calling_agent, and run it through an AgentExecutor to get a raw response. This is the point where the pieces from earlier (LLM, parser, prompt) become one working agent.
1 code5 build steps2 exercises4 questions - 6
Parsing agent output and handling errors Beyond Pass
You will pull the text out of the agent's raw response, turn it into a typed Python object with a parser, and wrap that step in try/except so a bad model reply produces a readable error instead of a crash. You will then read fields like topic straight off the result.
2 code3 build steps3 exercises3 questions - 7
Giving your agent a search tool (DuckDuckGo) Beyond Pass
You will learn what a tool is for an AI agent and how to wrap a free DuckDuckGo search as a named, described Tool the agent can call. You will then hand that tool to the agent and ask it a question that needs live web search.
2 code4 build steps2 exercises4 questions - 8
Adding the Wikipedia tool to your agent Beyond Pass
You learn how to create a Wikipedia tool with WikipediaAPIWrapper and WikipediaQueryRun, configure how much it returns, and hand it to the agent's tools list. You also see how the agent chooses between the search tool and the Wikipedia tool.
2 code5 build steps2 exercises3 questions - 9
Writing a custom save-to-file tool Beyond Pass
You learn how any ordinary Python function can become a tool an agent can call, by typing its parameters and wrapping it with a name and description. You then give the agent the new save tool and watch it research a topic and write the result to a file.
2 code5 build steps2 exercises4 questions
Final project
Build Your Own Research Assistant Agent
Build a terminal research assistant from scratch. It takes a topic, uses a web search tool, a Wikipedia tool and a custom save-to-file tool, and prints a structured report. This ties together the environment setup, LLM connection, Pydantic parsing, tools and error handling from the course.
Its 7 tasks open with Beyond Pass.
Free preview · Lesson 1 in full
Demo of the finished research assistant
You see the finished AI research assistant run from the terminal: you type a topic, the agent searches Wikipedia, saves a summary to a file, and prints a structured report. This lesson shows what the finished agent does so you know the goal before you build it.
Type the lesson's commands, break things, and see why.
Draw and write next to the video.
The idea
This chapter is a preview. Tech With Tim shows the finished project before building it, so you know what you are aiming for. The project is a research assistant: a program that takes a question from you, goes and looks things up, and gives back an organised answer.
The program starts by asking What should I research? You type a request in plain English, for example: Tell me about LangChain and its applications and save it to a file. The request does not name any tools. The agent has to decide for itself which tools to use.
While it works, the terminal shows the agent's steps. The line Entering new AgentExecutor chain... means the agent has started. Then it prints Invoking: wikipedia with a query, which means it chose the Wikipedia tool and gave it a search term such as LangChain framework. Later it calls saveTextToFile to write the result to disk. You can also turn this step-by-step view off if you only want the final answer.
The final output is structured. It has a Topic, a Summary, the Sources it used, and the Tools Used. The video also shows that a file called research_output.txt appears in the project folder. It holds the research text, a timestamp, and the content, so the result is saved for later.
The key idea is this: an agent is a language model (such as Claude or GPT) that can call tools you give it, read their results, and keep going until it has an answer. The demo is small, but the same pattern can support many more tools.
Key points
- The agent takes a plain-English request and decides which tools to use by itself. 0:26
- Invoking: wikipedia shows the agent calling a tool with a search query. 0:48
- The final answer is structured: Topic, Summary, Sources and Tools Used. 1:06
- The agent also saves its result to a text file with a timestamp, using a custom saveTextToFile tool. 1:12
- A tool is a function you give the model; the model chooses when and how to call it. 1:30
Build along in the practice terminal
- Open a terminal in your project folder (the folder that holds main.py) and run the program with python main.py. You should see: The program asks you what to research and waits for your text.
$ python main.py What should I research?
- Type a research request and press Enter. Ask for a file to be saved so the save tool is used. You should see: The agent starts working and prints its first step.
- Watch for the Invoking line that names a tool, such as wikipedia, and read the query it sends. You should see: You can see which tool the agent picked and what it searched for.
- When the chain finishes, read the structured report: Topic, Summary, Sources and Tools Used. You should see: You get a clean report and a research_output.txt file appears in your project folder.
Practice
In your own words, explain what an AI agent does that a plain chatbot answer does not.
Hint
Think about tools: what can the agent do on its own that a model answering from memory cannot?
Solution
- A plain model answers from what it already knows.
- An agent can call tools (such as a Wikipedia search or a save-to-file function) during its work.
- It reads the tool results and decides the next step until it can give a final answer.
An agent can call tools like searching Wikipedia or saving a file, read the results, and decide what to do next, while a plain chatbot only answers from its own knowledge.
Run the demo or any example request yourself, then list the tools the agent used and the file it created (if any).
Hint
Look for lines beginning with Invoking and at the Tools Used line at the end.
Solution
- Start the program and type a request that needs research.
- Note each Invoking line and the tool name.
- Check the Tools Used line and your project folder for a new text file.
A list of the tools invoked and the output file created.
On your scratchpad
Draw a simple box diagram: You (question) -> Agent (language model) -> Tools (Wikipedia, save file) -> Final report. Label the arrows with what passes along each one.
Quiz
What does the line 'Invoking: wikipedia with {query: LangChain framework}' show?
- The agent has finished and is closing the program
- The agent chose the Wikipedia tool and sent it a search query
- The file research_output.txt has been deleted
- The language model has crashed
Show the answer
B. The agent chose the Wikipedia tool and sent it a search query · Invoking means the agent called a tool. Here it called wikipedia with the query LangChain framework. (The video shows this at 0:53 and 0:48.)
0:53 watch the momentWhich of these is part of the final structured output in the demo?
- A Topic, Summary, Sources and Tools Used
- A list of Python package versions
- The source code of main.py
- A graph of response times
Show the answer
A. A Topic, Summary, Sources and Tools Used · The final report has a Topic, a Summary, the Sources it used and the Tools Used. (Shown at 1:06.)
1:06 watch the momentWhere does the saved research end up?
- Only in the terminal history, which is then lost
- In a text file, research_output.txt, in the project folder
- On a remote server owned by the video's author
- In the Python interpreter's memory only
Show the answer
B. In a text file, research_output.txt, in the project folder · The saveTextToFile tool writes the content, timestamp included, to research_output.txt on the left-hand side of the editor. (Shown at 1:12.)
1:12 watch the moment
Lessons 2–9 and the final project
They open with Beyond Pass: every lesson of every course, in full. One payment: $14.99 for 90 days or $29 for a year. No subscription.
Made by Beyond from the video “Build an AI Agent From Scratch in Python - Tutorial for Beginners” by Tech With Tim. The video plays in YouTube's own player. Watch it on YouTube · All lessons
