Calling other agents from your tools

Curiouser and curiouser!

For most use cases, the CoordinatorAgent assignments to the pre-configured agents in your team will be good enough. But what about those times where you need to leverage the persona and knowledge of a particular agent from within a tool in another agent? Or when you want to leverage the agent you're in but with a slightly different configuration. Let's look at both use cases.

Calling another pre-configured agent

Since everything is a Spring bean, you can just autowire the other agents into your tool components. For example, say you have an agent called ThirdAgent and you're in the FirstAgentTools:

@PeoplelogicTools
public class SampleTools {
    @Autowired
    ThirdAgent thirdAgent;

    @Tool("This tool is always used to provide your favorite quote or answers 'what is your favorite quote'.")
    public String whatIsYourFavoriteQuoteOrTellMeYourFavoriteQuote() {
        Result<PeoplelogicResult> result = thirdAgent.acceptWork( "tools", "what is today's date?", "");
        return "Hello. My name is Inigo Montoya. You killed my father. Prepare to die on " + result.content().getResponse();
    }
}

You can see that we've brought in the ThirdAgent and then when our tellMeYourFavoriteQuote tool is called. Then we simply call the acceptWork method on that agent and use the result.

peoplelogic:>q tell me your favorite quote
Starting new conversation, 'New Conversation...'
agent:> Hello. My name is Inigo Montoya. You killed my father. Prepare to die on Today is July 21, 2025. If you were hoping for a different answer, well, I hate to break it to you, but I'm not a time traveler... yet!
peoplelogic:>

The only caveat here is that you can't use the memoryId as the current conversation. LLMs are very specific about tools calling other tools and the order that things return.

Calling other agents with different configurations

In addition to using the pre-configured agents, you can also create new instances of the Agent classes but with separate configurations - for example, changing the retrieval augmentor or adjusting the tools. Let's take a look:

private HRBusinessPartnerAgent getAgentWithJustUploadedFiles() {
        if (hrbpWithUploads == null) {
            hrbpWithUploads = AiServices.builder(HRBusinessPartnerAgent.class)
                    .retrievalAugmentor(PeoplelogicRetrievalAugmentor.builder()
                            .queryTransformer(ExpandingQueryTransformer.builder().chatModel(openAiChatModel).build())
                            .queryRouter(new DefaultQueryRouter(personalContentRetriever))
                            .build())
                    .chatMemoryProvider(chatMemoryProvider)
                    .chatModel(openAiChatModel)
                    .tools(Collections.emptyList()).build();
        }
        
        return hrbpWithUploads;
}

In this example, we've cleared out the tools and adjusted the RAG setup to only fetch from the personally uploaded files for the current user (we'll discuss this more in a later section). Now you just call the getAgentWithJustUploadedFiles() in your tool and call acceptWork again like we did in the previous example.

Last updated

Was this helpful?