The Most Complete AI Agent Tutorial on Bilibili: From Function Calling to MCP and A2A

MCP is built on Function Calling—master the five-step function calling flow before learning about agents.
Starting from a Bilibili creator's tutorial, the article points out that MCP is essentially a standardized protocol for tool invocation built on Function Calling, so learning about agents should begin with function calling. It breaks down the five steps of Function Calling—defining the function, model inference, generating the call instruction, executing the function, and returning the result—and explains Python code line by line using a weather query example, emphasizing that tool_calls are only call instructions, not the final answer. It also distinguishes agents from Function Calling: agents need multi-step plans and memory, while function calling only decides a single call and has no memory by default. Finally, it recommends a learning path: write low-level code by hand first, then progress through Function Calling, MCP, workflows, and A2A.
Why Start with Function Calling?
Many tutorials jump straight into MCP and agents, but the Bilibili creator repeatedly emphasizes in this tutorial: MCP is essentially a standardized protocol for tool invocation, and the foundation of tool invocation is Function Calling. Without first understanding Function Calling, learning MCP and A2A (Agent to Agent) later becomes mere rote memorization.
According to the creator, Function Calling was promoted by companies like OpenAI, allowing large models to connect to external tools and convert natural language into API calls. This solves a key problem: a large model's knowledge stops updating once training ends, but by calling external functions, the model can gain additional capabilities or real-time data. Among current mainstream large models, the vast majority already support Function Calling—the GPT series, Gemini, and Claude all support it, as does the domestic Doubao (pronounced as in the original) V3 version, but R1 and some other models do not.
Function Calling is a capability of large models: when generating a response, the model can output a structured "call intent"—specifying the tool name and parameters to invoke—rather than directly giving a natural-language answer. The model itself does not execute any code; it only generates a call request that conforms to a predefined JSON Schema, which an external program parses and actually executes. This mechanism gives statically trained large models the ability to access real-time data and perform side-effect operations, and it is the common foundation for plugins, tool invocation, MCP, and other higher-level capabilities. Interface forms differ slightly across vendors (e.g., OpenAI's tools/tool_calls, Anthropic's tool_use blocks), but the core logic is the same: the model handles "decision and parameter filling," while the runtime handles "execution and return."
The Five-Step Working Principle of Function Calling
The creator breaks Function Calling down into five clear steps, using weather queries as a running example:
- Define the function: describe the function name, comments, parameters, and types.
- Model inference: the model determines whether a function needs to be called.
- Generate the call instruction: the model generates a Function Call, the core of which is preparing the call parameters.
- Execute the function: the developer actually executes the function based on the model's output.
- Return the result: send the execution result back to the model, which generates the final answer.
These five steps map perfectly onto the code. In the video, the creator annotates line by line: defining the function includes both the real function and the Tool dictionary (function name, description, parameters, and types); line 47 completes model inference and returns a "function call instruction"; the function is only actually executed after the conditional check on line 61; finally, the result is passed back to the model a second time.
Code Walkthrough: The Complete Weather Query Flow
The creator uses Python and the OpenAI API to demonstrate the entire flow. First, create a new project and a Function Calling package, and define a getWeather function to simulate a weather query:

Next, build the message array, with the user input fixed as "today's weather in Beijing":

When calling chat.completions.create, pass in the tools parameter, which includes the function name, description, and parameter schema, and set tool_choice to auto so the model decides on its own. The response object returned after running contains a tool_calls array. The creator reminds us: what you get here is a call instruction, not the final answer.

Extract the function name and parameters (location=Beijing) from tool_calls, then execute the function and convert the result to JSON:

Finally, add the tool execution result to the message list and call the model a second time to get a complete answer like "Today's weather in Beijing is sunny, with the following temperature and wind speed." The creator admits this code is "very complex" and that no one would write it this way in real development—it is purely teaching code for understanding the underlying mechanism.
JSON Schema is a standard for describing the structure of JSON data. Here it is used to declare the parameter contract of a function to the model: parameter names, types (string/number/object, etc.), whether they are required, enum values, and descriptions. The clearer the schema, the more accurately the model fills in parameters; vague descriptions or missing types are common root causes of tool invocation failures and parameter parsing errors. The tool_choice parameter controls the invocation strategy: when set to auto, the model decides whether to call; when set to required, it can be forced to call; and you can also specify a particular function. Understanding these two parameters is the first step in troubleshooting issues like "the model doesn't call the tool" or "it calls the wrong tool."
The Essential Difference Between Agents and Function Calling
This is the most valuable distinction in the entire tutorial. The creator points out that when making decisions, an agent also needs to generate a plan—whether to call function one or function two first, and which one to call afterward—whereas Function Calling only decides "whether to call this function" and has no planning capability. In addition, Function Calling by default has no memory, unless it is added separately.
This distinction directly points to the subsequent content: MCP establishes a recognized protocol on top of tool invocation, workflows orchestrate multiple calls, and A2A enables agents to collaborate with one another. Once you understand this foundation, you won't confuse the higher-level architectures.
Agent usually refers to a system with a large model as its decision core that can autonomously plan multi-step actions and invoke tools in a loop. Compared with a single Function Calling, it has several key components: task planning (breaking goals into sub-steps), state and memory (saving historical observations and intermediate results), reflection and error correction (adjusting the next step based on tool returns), and termination condition judgment. The ReAct pattern (reason—act—observe loop) commonly discussed in the industry is a typical implementation. Therefore, Function Calling can be seen as an agent's "atomic capability," while an agent is a "composite system" that layers a control loop and memory on top of it.
Practical Advice for Developers
The creator ends with a thought-provoking judgment: writing Function Calling code by hand from the lowest level, as in the video, is something "people might still have done in 2013, but not now"; in real development, "at the very least you should write an Agent."
This means the learning path should be: first understand the request-response loop of Function Calling and the essence of call instructions by writing code by hand, then transition to framework encapsulation. Skipping the fundamentals and going straight to frameworks leaves you helpless when tool calls fail or parameter parsing goes wrong. The value of this tutorial lies precisely in explaining the driest low-level details thoroughly with runnable code.
For developers who want to build their own custom agents, the recommended order is "Function Calling → MCP protocol → workflow orchestration → A2A," running a minimal example by hand at each step. This yields greater long-term benefits than directly copying framework code.
One-line Summary
MCP is built on Function Calling—understand the five-step function calling flow before learning about agents.
Paragraph Summary
Starting from a Bilibili creator's tutorial, the article points out that MCP is essentially a standardized protocol for tool invocation, whose foundation is Function Calling, so learning about agents should begin with mastering function calling. The article breaks down the five steps of Function Calling: defining the function, model inference, generating the call instruction, executing the function, and returning the result. Using a weather query as an example, it explains the Python code line by line, emphasizing that the tool_calls returned by the model are only call instructions rather than the final answer, and must be executed by the developer and passed back a second time. The article also distinguishes agents from Function Calling: agents need to generate multi-step plans and have memory, whereas function calling only decides whether to call once and has no memory by default. Finally, it recommends a learning path: first write low-level code by hand to understand the request-response loop, then proceed in the order of Function Calling, MCP, workflows, and A2A.
Related articles

Give Your Kid a "Weird" Name: A Vergecast Host's Guide to Digital Identity and SEO Parenting
Vergecast host David Pierce shares a unique parenting tip: give your child a weird name for better online SEO. The show also covers combined-surname domains and names as digital assets.

Sanders Declares AI a "National Emergency," Calls on Congress to Avert Human Catastrophe
Senator Bernie Sanders calls AI a "national emergency" and urges Congress to legislate against human catastrophe. This article examines his claims, Jensen Huang's congressional testimony, and the deeper signals in the AI governance battle.

OpenAI Launches Dot: From Writing Code to Managing Workflows, AI Becomes the Work Orchestration Layer
OpenAI launches personal AI assistant Dot as a work orchestration layer coordinating tasks and tools. This article analyzes Dot's core capabilities, real-world cases, and differences from traditional AI assistants, exploring AI's potential as an orchestration layer.