← AI-Hands-on Agent tooling · Part 4 of 7Công cụ cho agent · Phần 4/7

A2A lets agents talk. What lets an agent act on the system itself?A2A giúp agent nói chuyện. Vậy điều gì giúp agent thao tác lên hệ thống?

Talking to other agents solves half the problem. This walkthrough adds the Model Context Protocol (MCP) so the same Orchestrator can also read a file, query a database, or run a calculation directly — no other agent required.

Nói chuyện với agent khác chỉ giải quyết được một nửa vấn đề. Video này thêm Model Context Protocol (MCP) để chính Orchestrator có thể đọc file, truy vấn cơ sở dữ liệu, hay chạy phép tính trực tiếp — không cần agent nào khác.

Video demo: one Host Agent uses A2A for "ask the time" and MCP for "list local files" — same agent, two different tool types.

Video demo: một Host Agent dùng A2A để "hỏi giờ" và MCP để "liệt kê file cục bộ" — cùng một agent, hai loại công cụ khác nhau.

English

What problem does this solve?

A2A is good at one thing: letting an agent hand a task to another agent. It has no answer for a different, equally common need — an agent that must read a file, hit a database, or run a local calculation itself, without another agent in the loop. Building a bespoke integration for every such tool does not scale. This walkthrough continues studying the open-source theailanguage/a2a_samples reference implementation.

How the mechanism works

MCP standardizes exactly that: how an agent process loads external tools. An MCP server runs as a subprocess and communicates over stdio — standard input and output — so no extra network port has to be opened or secured. The Host Agent connects to it, asks for its list of available tools, and wraps each one as an async function Gemini can call like any other tool.

The result is a Host Agent with two categories of tool side by side: A2A tools (list agents, delegate a task) for talking to other agents, and MCP tools (read a file, query data) for acting on the system directly. Asking "what time is it" triggers the A2A path to TellTimeAgent; asking to "list the files in this folder" triggers the MCP path instead — the model picks the right category on its own.

Trade-offs and alternatives

The benefit is a clean separation of concerns: agent-to-agent communication and agent-to-system tool access use two purpose-built protocols instead of one protocol stretched to cover both. The trade-off is more moving parts to run and monitor — the Host Agent now manages an MCP subprocess lifecycle in addition to its A2A HTTP calls.

The alternative some teams try is exposing system operations as fake "agents" over A2A just to reuse one protocol everywhere. That avoids learning a second protocol, but it's a misuse of A2A's task model for something that was never meant to be a multi-turn conversation.

Conclusion

Two protocols, two jobs: A2A for agent-to-agent conversation, MCP for agent-to-tool access. Combined, they give one agent both a social life and hands to act with — which is what most real automation actually needs.

Tiếng Việt

Vấn đề gì đang được giải quyết?

A2A giỏi đúng một việc: giúp agent giao tác vụ cho agent khác. Nó không có câu trả lời cho một nhu cầu khác, cũng phổ biến không kém — một agent cần tự đọc file, truy vấn cơ sở dữ liệu, hay chạy một phép tính cục bộ, mà không cần agent nào khác tham gia. Xây tích hợp riêng cho từng công cụ như vậy thì không mở rộng được. Video này tiếp tục nghiên cứu bản triển khai tham chiếu mã nguồn mở theailanguage/a2a_samples.

Cơ chế hoạt động ra sao?

MCP chuẩn hóa đúng điều đó: cách một tiến trình agent nạp công cụ bên ngoài. Một máy chủ MCP chạy như một tiến trình con và giao tiếp qua stdio — luồng nhập/xuất chuẩn — nên không cần mở hay bảo mật thêm cổng mạng nào. Host Agent kết nối tới đó, hỏi danh sách công cụ sẵn có, rồi bọc từng công cụ thành một hàm bất đồng bộ mà Gemini gọi được như bất kỳ công cụ nào khác.

Kết quả là một Host Agent có hai nhóm công cụ song song: công cụ A2A (liệt kê agent, giao việc) để nói chuyện với agent khác, và công cụ MCP (đọc file, truy vấn dữ liệu) để thao tác trực tiếp lên hệ thống. Hỏi "mấy giờ rồi" sẽ kích hoạt đường A2A tới TellTimeAgent; yêu cầu "liệt kê file trong thư mục này" sẽ kích hoạt đường MCP — mô hình tự chọn đúng nhóm.

Đánh đổi và các hướng khác

Cái được là tách bạch rõ ràng: giao tiếp agent-với-agent và truy cập agent-với-hệ-thống dùng hai giao thức được thiết kế riêng thay vì kéo giãn một giao thức để phủ cả hai. Cái đánh đổi là nhiều phần chuyển động hơn để vận hành và giám sát — Host Agent giờ phải quản lý thêm vòng đời tiến trình con MCP bên cạnh các lệnh gọi HTTP A2A.

Hướng thay thế một số đội thử là giả lập thao tác hệ thống thành các "agent" ảo qua A2A chỉ để dùng một giao thức duy nhất khắp nơi. Cách đó tránh được việc học thêm giao thức thứ hai, nhưng là dùng sai mô hình tác vụ của A2A cho thứ vốn không được thiết kế để là một hội thoại nhiều lượt.

Kết luận

Hai giao thức, hai nhiệm vụ: A2A cho hội thoại agent-với-agent, MCP cho truy cập agent-với-công-cụ. Kết hợp lại, chúng cho một agent vừa có đời sống xã hội vừa có đôi tay để hành động — đó là điều hầu hết tự động hóa thật sự cần.