Building a Custom Agent

You can use the built-in AI agents to streamline content management, but you can also create your own for more flexible integration with Liferay DXP. Follow this example to create an agent that translates English blog content into Spanish, then call it from the AI Assistant. For the full reference on managing agents in the Agent Builder, see Agents.

First, log into your AI Hub account and click Agent Builder in the AI Hub left navigation.

Find the list of built-in agents in the AI Hub instance.

If you don’t have an AI Hub account yet, see Integrating AI Hub with Liferay DXP to get set up.

Note

On the Activate subscription tier, agent creation is limited:

  • You must duplicate an existing agent, then customize it.
  • You can create up to five custom agents.

To create a new Spanish translation agent,

  1. You can start from scratch with the New button, but it’s easiest to copy an existing agent. Find the Make Shorter agent and click Actions ActionsDuplicate.

    You can duplicate an existing agent.

  2. Now view the copied agent by clicking Actions ActionsView.

  3. Edit these fields:

    Title: Spanish Translator

    Description: This writing agent takes your text and translates it to Spanish.

  4. Click Save.

  5. Now update the agent logic. Click the View Workflow button.

  6. Change the workflow title to Spanish Translator.

  7. In the workflow editor canvas, click on the Make Shorter node.

  8. In the right node editor menu, change the label to Spanish Translator.

  9. Change the Node Name to translateToSpanish.

  10. Replace the Description with

    Translate text to Spanish using LLM models.
    
  11. Replace the Prompt with

    You are an expert translator. Your sole task is to translate the provided text to Spanish, preserving the exact semantic meaning of the input. If the text is already in Spanish, return it unchanged. Output only the translated text, with no explanations or commentary.
    
  12. Replace the User Message with

    This is the text to be translated: {{text}}
    

Your Spanish translator is ready to use.

  1. Click Update.

Now that the translation agent is created, you can try it out.

Using the Custom Agent

To test or use the custom agent, go back to your Liferay DXP instance that’s connected to AI Hub.

  1. Access a space in the Liferay CMS and edit a blog post.

    Tip

    You can generate a blog post with the built-in writing agents. See Enhancing Content Management for more information.

  2. Click AI Assistant in the top toolbar to open the chat panel. Paste the source HTML of your blog post and ask the assistant to translate it, for example:

    Can you please translate this HTML into Spanish?
    

The AI Assistant is a supervisor agent to all of the individual agents in your system. Ask it questions and it calls the relevant agents to fulfill the request.

If you ask the supervisor chat agent to translate your blog post to French, it cannot.

The supervisor agent cannot translate to French because there is no applicable agent.

Now you can build custom agents and call them with the supervisor agent. To let a custom agent answer from a website’s content, attach a data source to it.