Building Glean Agents with sub-agents has benefits like improved test-ability and flow control, but communicating context between sub-agents can be tricky.
Let’s take a simple example of an agent with two sub-agents and a respond step.
Sub-agents have input fields that define the context input to the sub-agent. The only context that a sub-agent starts with is the values of the input fields. Those values could be extensive, but they must be communicated to the sub-agent via the fields. A sub-agent never knows about any of its parent’s context unless passed in through the sub-agents input fields.
Similarly, the only context that the parent has access to from the sub-agent is based on the response text from the sub-agent. A parent agent never knows about the internal context generated by a sub-agent. For example, if a sub-agent does a company search, the parent will not have access to any of those search results directly. The parent will only have access to the response text generated by the sub-agent.
Therefore, the only way to communicate context between multiple sub-agents is via sub-agent responses and input field values. What are the logistics to make this work in Glean’s agent builder?
The screenshot above shows the definition of the second sub-agent in my parent agent. When I built the sub-agent, I gave it one input field. When configuring the sub-agent in my parent agent, I’ve selected “Manual” for this example, but that isn’t required. You can also use the AI-generated approach to customize the context that gets input to the sub-agent.
The trick here is to use the first sub-agent’s response text. You do that by typing “[[“ to see the fields that are available for inserting. You will see that “1. Sub-Agent” is an available field. This isn’t an input field of the parent agent; however, every step’s response in the parent agent becomes a field that you can use in subsequent steps in the parent agent. By selecting this option, you will input the response of the first sub-agent as the value of the field in the second sub-agent.
That’s it. Now you’re communicating context between sub-agents. Please let me know if you have any questions about how this works.