Skip to content
Linkdrop
Links

S02E04 · Multi-Agent Collaboration: MEGA lesson video by Angie Jones

Angie Jones demonstrates how retail agents can discover and delegate work to external agents using AI Catalogs and A2A, and how to use subagents to assess product fit. The lesson compares agent delegation with MCP tools and discusses validating external results in application code.

videoAngie Jones · hq.mega.dev · Saved Nov 19, 2026

mega course, multi-agent systems, agent orchestration, model context protocol, agent-to-agent commerce

Transcript of the lesson video for S02E04 of the MEGA.dev course, by Angie Jones. Agenda: Subagents · A2A · Agent Card · Discovery · Delegation · Orchestration. The video plays on the lesson page in MEGA Student HQ (needs a login).

0:05 Alex ordered a pair of shoes for an upcoming wedding. The tracking says that they've been delivered, but Alex hasn't received them, so he asked our retail agent for help. Now, the agent says that they were delivered to reception, but Alex doesn't have a reception area. And unfortunately, our agent doesn't have any more information because the delivery was handled by an external shipping company. Until now, everything that our agent has needed has been in our database, right? And now we need to investigate something that's happening in an external third-party system. If only there were a way to publish and discover agent capabilities that companies offer. AI Catalog is an emergent standard that specifies a simple way for companies to disclose MCP servers, skills, agents, or even other catalogs that they offer to interact with their services.

Catalogs are published via an AI catalog JSON file that's reachable at the company's website under the .well-known. This is a conventional location, so developers and applications have a predictable place to check. To discover what the shipping company offers, we can look in its AI catalog. So it seems that they have an agent that does delivery investigations, and it tells us where we can find more information about that agent. Let's go there to learn what that service accepts and how we can connect to it. Now, this document is called an agent card, and it's essentially a way for a business to advertise an agent as a service. So the skills that are listed here describe the work that the agent accepts, but note that these are not the same as agent skills.

They just happen to use the same term. Confusing, I know. But anyway, given this, our retail agent can get this external agent to go figure out what happened to our customer's delivery. Now, given that this is an external agent, how do we actually communicate with this agent? How do we delegate work to it? How do we get the results back, you know? Especially when we don't know much about what type of agent this is, meaning, like, what model it's using or what framework that it was developed with. Well, it does include an endpoint, and this tells our application how to connect using A2A, which is the agent-to-agent protocol. And A2A gives the agents a shared format for exchanging requests and results.

I've developed an A2A client class to interface with remote agents. So it retrieves a service's agent card, and it checks that it offers the skill that we need. I also created a new tool specifically to allow our agent to request an investigation. So the investigation tool uses our A2A client to send the investigation request to the shipping company's agent, and this send message call carries that request to the agent, who then decides how to investigate using its own evidence and its own tools. Once an investigation starts, our client waits for the shipping company's response. Our application then saves the task status and any question or findings that it returns. Then this get resolution tool lets our retail agent read that saved record for the current customer conversation.

Okay, now let's make our two new tools available to the retail agent. So within our agent definition, we can add these two new tools, and with this, the model can now request an investigation, and it can read the saved progress. Let's try these out in the chat. Now, this is our first delegated request, and we can see that the retail agent called the investigate missing delivery tool, and inside of this tool, our application sent an A2A request to the shipping company's agent. And then the shipping company agent examined the evidence, and it returned a question for the customer. See how this is not like a delegate and done situation, right? The investigation continues across multiple messages.

So A2A represents that work as a task, and the status tells us what our agent needs to do next. In this case, input required means that we need to get the customer's answer. So our retail agent presents the question to the customer. So the shipping agent returned a task ID for this investigation and a context ID for its conversation. We save both on our end, and now we're going to add a tool that sends the customer's answers with those IDs so that the shipping company can continue the same investigation. So this tool reads the customer's latest message directly from the conversation. If the customer says that they don't know or something like that, then we want the shipping company to receive that uncertainty, not the model's rewritten version of that.

Here, we load the saved case, and we check that an investigation is waiting for an answer. Then we pass that case and the customer's answer back into the investigation method, which sends the reply with the saved task and the context IDs. Now let's add this tool to our agent definition so that our agent can actually use it. So the customer lets the agent know that there is no reception desk, and our retail agent uses the clarification tool to send that answer back to the shipping company along with a saved ID so that it can pick up the investigation where it left off. If the response were to contain another question, we could use this same tool to send the customer's next answer.

Okay, let's look at the outcome. We see the findings here. Uh, the investigation is complete, but the recovery would be too late for the wedding. So our retail agent needs to decide, what do we do next? So the original shoes won't arrive in time, but the customer is open to another pair. So let's see if the store has the same shoes in stock. So there's no local stock of the original shoes, which means that our agent needs to look beyond this store. Our store works with a supplier, which is a separate business that provides stock from its warehouse. Pop quiz. We need something from another business. Where do we look? That's right. Let's check out their AI catalog to see what's available for us.

Now, I'm showing this on screen just so that you can see it, but of course, you would discover these things programmatically, right? You're not going to be digging through the JSON. Now, within their AI catalog, they have an inventory MCP server, they have a delivery MCP server, and then they also have an agent that helps to source products. Now, people often ask, "What's the difference between MCP and A2A?" Here is a very clear example. We could use the tools from the supplier's MCP servers to search their stock and their delivery options, but then our retail agent would have to piece together these results and control this entire flow. But if we use the agent that they have available, it'll take care of the search.

It'll work through the options, and then it'll return the products that fit the customer's needs. So what we're doing is essentially delegating the entire task to another agent who has access to the data as well as the tools to be able to take actions. And we let the agent know the goal and the constraints, which are find shoes in a size nine within this total budget that can arrive before the deadline, and that agent handles it. So here's the tool that sends the customer's requirements to the supplier's agents and returns the offers that it finds. Let's add this tool to our agent definition. Okay, let's try this again now that we have a tool to delegate to the sourcing agent.

All right. And we can see which products the agent checked and whether our store can order them and what the delivery options could cost. So the supplier has worked out the options, but before our agent is allowed to show them to the customer, we have code that ensures that they match the requirements. So here's another example of where we're taking control as engineers, right? We're not just leaving things up to the model. We got these results from an external agent. We don't know what kind of logic that agent is using or what checks it has in place. Since we are the ones who are responsible for what we present to the customer, we have to do our due diligence to check it.

Okay, now we have offers that meet the delivery and the price requirements, but we need to do one more check to make sure that it suits the customer's preferences, which is a bit trickier to do. Now, the checks that our code performs answer specific questions. Is the size right? Is the price within the customer's budget? Is the estimated arrival before the deadline? These are all things that we can compare directly. So code handles that. Now, we're asking how well each shoe suits the customer. So Alex wants formal black shoes with cushioning, but he's open to something similar, right? Product descriptions don't always use the same words or include every detail. So just saying that it has a flexible sole, this is not going to tell us whether there's cushioning, for example, right?

So we need a model to interpret the descriptions against what the customer asked for. Our retail agent could do this itself, but this may be a good candidate to hand off to sub-agents. Let's see. So we need to assess a product against the customer's requirement and return the assessment. That's a very specific task that has a clear stopping point. This is essentially a sub-task of our agent's bigger work. So we can give the sub-agent the product details and the customer preferences, but it doesn't need the entire conversation about the missing delivery. We know that we need reasoning for this task, right, because we're interpreting descriptions and we're explaining trade-offs, so we definitely need something more than just a basic function call.

Each assessment can be independent, so assessing one shoe doesn't require the result for another shoe. So we can run these assessments in parallel, which will shorten the customer's wait time. And we know how we'll use the result. So each sub-agent returns its assessment, and our retail agent will use that to make a recommendation. So I was about to build these sub-agents, and then I remembered like, "Oh yeah, we have decision models now. Could I just make a decision model call for each product instead?" Very tempting. In fact, I tried that, right? Um, and the decision model calls were faster, but the focused LLM was more accurate here. So for this particular task, I was willing to trade the extra three seconds for better judgments, right?

And these are the decisions that we have to make as engineers. You might have a design in mind, but try a few approaches out and see how they actually perform. Is it accurate enough? Is it fast enough, right? What happens when things don't go as expected? Those results are what helps us decide what we need to build, right? And that doesn't mean that decision models can't handle this kind of task, right? It was very tempting, and it worked pretty well, but this focused LLM setup worked better for this particular test. So that's what we're going to use here. So to create a sub-agent in Mastra, we create a regular definition. We give it a model.

Um, I actually tested the sub-agent with Luna, which is what we're using for our main agent, and Luna didn't perform as well here. So I made the decision to go with a stronger model. for this subagent, and I chose GPT-6 Sole. We also have to give the subagent its own set of instructions. So its job is to assess product fit. We tell it to distinguish a preference from a must-have, to explain trade-offs, to identify missing information. And we pass in each customer's preferences with the product details, and we tell it that code has already checked the size, the price, and arrival, so that's not your responsibility. Don't worry about that. So here's exactly what it receives.

One product's name and features and the customer's preferences. That's it. No other context from the conversation. Calling generate sends that input to the subagent. So we request structured output so that the result has fields that our application can use. And this schema defines what we want back from each subagent. So why the product fits, any trade-offs, anything that it couldn't determine, and whether it's suitable. And that gives our retail agent a consistent result that it can use to compare the options and explain its recommendation. So you see how much control that we're adding here? You don't just let the model YOLO and say whatever. Now, we create a subagent for each product, and we ask it to assess that product against the customer's preferences.

Each subagent can work without waiting for the others, so we can run these in parallel. And then we collect the results, and the retail agent uses them to make a recommendation. And here's what makes that happen. So we map over the products, and we start an assessment for each one and wait for the group to finish. We keep each product's ID with its result so that we know which assessment belongs to which product. And then this comparison tool is how our retail agent requests that work. So the retail agent chooses the tool, and our code starts the subagents in parallel. The model doesn't have to figure out when to invoke the subagents. Let's go ahead and add this tool to our agent definition.

And now we can ask for a recommendation. So here, our retail agent brings the assessments together and then forms a recommendation. And we need to show the customer exactly what they'd be getting, what they'd owe, and when it's expected to arrive. So let's add a tool to prepare that proposal. This tool prepares the exact terms for the customer to review, including the pair, what they'd owe, and the estimated arrival. And this one handles their answers. So after they confirm, it requests the reservation from the supplier. Let's add both of these tools to our retail agent definition. Okay, now that we have that tool, the customer is asking the agent about the pair that it recommended, and the agent responds with a proposal.

The customer can review this, the terms, they can confirm with a separate reply. The customer says, "Yes, I would like that," and then the supplier has confirmed the reservation. So we're done with this conversation. Okay, so we've seen how our agent can call another agent and delegate work to it, but now I want us to set up our agent as a service so that other agents can delegate to us. So here is a shopping assistant. This is different than our retail agent. The shopping assistant has its own conversation with Alex. So suppose Alex uses this assistant to manage purchases from several stores. It may need to collaborate with our store on Alex's behalf. So we can publish our retail agent as a service and allow other agents to connect with us through A2A.

Now, in order for another application to reach our agent, we need an address where it can send an A2A request, and we also need some code that receives that request and passes it to our retail agent. This gateway is the server that we're putting in front of our agent to make it available to other applications. So here we configure the service's name, capability, and endpoint. The skill value, customer service, is an identifier. And the service descriptions entry supplies the descriptions for the agent and its skills. So when we publish the agent card, the identifier becomes the skills ID, and the description explains what it can do, just like the cards that we looked at earlier.

And here's where an incoming request reaches our agent. So we pass the incoming message to our retail agent using generate, and then we return its answer to our service wrapper. So here's the A2A connection inside that wrapper. We have default request handler and JSON RPC transport handler. Uh, a lot of words, I know. Um, but this comes from the official A2A SDK. So we connect these to our agent card, our task storage, and the executor that runs our agent, and they handle the A2A protocol around that work. And then this call passes the incoming request to the SDK handler. So the code below sends its results back to the caller, either as streamed events or as a JSON response, and that's where the answer goes back over the connection.

So that gives the shopping assistant one place to contact. The customer's answers and approvals now pass through another agent. We need our retail agent to receive what the customer actually said, right? So the shopping tool forwards the latest customer message directly, and then the delegation component saves the retail task and the context IDs for this customer in the shopping thread. When the retail agent asks a question, the next customer answer continues that task. So let's add this tool to our agent definition. Okay, this is the shopping assistant's very first tool. Yay. Okay, so the customer is now talking to the shopping assistant, and the shopping assistant is reaching out to our retail agent for help.

Let's be nosy and look in the tool to see what came back. Okay, so our retail agent is telling this agent that it needs more information, and the shopping assistant then passes that question back to the customer. And again, these IDs help to keep the conversation connected to whenever the customer answers. Okay, let's go ahead and answer on behalf of the customer. And if we expand this tool result, we see that it's the same task, it's the same context. We're continue the conversation with retail. This is not like a brand new thing. Okay, so now the shopping agent is asking for more information about what the customer wants and what's his preferences. So we'll go ahead and send that.

And there we go. The customer stayed with their shopping assistant while our retail agent worked with the other business to help them. So we started this whole thing with an agent that could look up an order but couldn't resolve a missing delivery. And so we discovered what other businesses offered. We delegated work to their agents through A2A, and we built our own subagents to assess the options in parallel. And then we made our retail agent available for other agents to call. So that's the overall lesson of this chapter. Start with work that your agent needs help with, decide who should handle it, give them the information that they need, and be clear about what you expect back.

That's how we get all of these agents to work together on our behalf. [music]