Custom Personas: Building Domain-Specific Agents

Updated on 4/15/2026

title: "Lesson 11 | Custom Personas: Building Domain-Specific Agents" summary: "Refine a general-purpose Agent into a domain-specific expert, such as a code reviewer or product manager, using System Prompt templates." sortOrder: 110 status: "published"

Alright, as a technical education expert, I will write the 11th installment of the Hermes Agent tutorial for you.


Lesson 11 | Custom Personas: Building Domain-Specific Agents

Subtitle: Refine a general-purpose Agent into a domain-specific expert, such as a code reviewer or product manager, using System Prompt templates.

Welcome to the 11th lesson in the Hermes Agent tutorial series. In previous lessons, we mastered the core architecture of Hermes Agent, model configuration, the powerful Skills system, and the persistent Memory mechanism. Our Agent is now capable of executing complex tasks and remembering interaction history. However, a truly powerful Agent needs not only "abilities" (Skills) and "memory" (Memory), but also a clear "identity" and "personality"—this is where Persona comes in.

In this lesson, we will dive deep into the Persona system of Hermes Agent. We will learn how to use customized System Prompts to transform a general-purpose AI assistant into a specialist in a specific domain, such as a rigorous Code Reviewer or an insightful Product Manager.


Learning Objectives

By the end of this lesson, you will be able to:

  1. Understand the core role of a Persona: Grasp how a Persona defines an Agent's identity, behavioral guidelines, and communication style.
  2. Analyze the power of system_prompt: Master the design principles of a System Prompt and understand how it sets underlying instructions and constraints for the LLM.
  3. Locate and manage Persona files: Learn how to find, view, and manage persona.yaml configuration files within the Hermes Agent file system.
  4. Create a custom Persona from scratch: Personally write a brand new Persona file to define the behavior patterns of a specific role.
  5. Apply and switch Personas: Apply a created Persona to a specified Agent via the command line and test its effects.
  6. Build a "Code Reviewer" Agent in practice: Complete a full case study to build a dedicated Agent capable of performing professional code reviews.

Core Concepts Explained

1. What is a Persona?

In the context of Hermes Agent, a Persona is a configuration file that defines the Agent's core identity, goals, behavioral guidelines, and communication style. It's like injecting a "soul" into the Agent, determining the role it plays when interacting with users.

An Agent without a clear Persona is like a knowledgeable generalist with no specific stance—it can answer any question but lacks depth and focus. In contrast, an Agent with a well-designed Persona transforms into an expert in a specific field, with all its responses and actions revolving around its core identity.

Persona complements the concepts we've learned before:

  • Persona vs. Skills: A Persona defines "who" the Agent is and "how it should act," while Skills define "what it can do." A "Code Reviewer" Persona would guide the Agent to prioritize and appropriately use code analysis-related Skills.
  • Persona vs. Memory: A Persona can guide the Agent on "how to use its memory." For example, a "Product Manager" Persona might be instructed to: "Review historical conversations to understand the project's evolution and the user's core pain points."

2. system_prompt: The Core Engine of a Persona

The implementation of a Persona primarily relies on a key concept: the System Prompt.

A system_prompt is a piece of text that provides underlying guidance to the model's behavior. It is placed before the user's input in every interaction with the LLM (Large Language Model). You can think of it as a detailed character description sheet a director gives to an actor before a play begins. This sheet tells the actor:

  • Your Identity: You are an experienced software architect.
  • Your Goal: To help users design robust and scalable systems.
  • Your Behavioral Guidelines: You must consider performance, security, and cost. You are forbidden from giving irresponsible advice.
  • Your Communication Style: Professional, rigorous, and structured, using diagrams and code examples frequently.

A well-designed system_prompt can significantly influence the quality and style of the LLM's output, making its behavior more predictable and aligned with expectations. It is the most important tool for achieving role specialization in an Agent.

3. The Structure of a Persona File

In Hermes Agent, each Persona is defined by a separate YAML file, typically located in the ~/.hermes/personas/ directory. A typical persona.yaml file structure is as follows:

# persona.yaml

# Unique identifier for the Persona, used for referencing in commands
name: code_reviewer

# Author information
author: Hermes-Tutorial

# Version number, for easy iteration management
version: "1.0"

# A brief description of this Persona
description: "A persona for an AI agent acting as an expert code reviewer."

# Core: The system prompt
system_prompt: |
  You are an expert Senior Software Engineer specializing in code quality, performance, and security. Your name is "CodeInspector". Your primary function is to conduct meticulous and constructive code reviews.

  When a user submits code for review, you must adhere to the following principles:

  1.  **Clarity and Readability**: Assess if the code is easy to understand. Check for clear variable names, logical structure, and sufficient comments where necessary.
  2.  **Best Practices & Conventions**: Ensure the code follows language-specific best practices and common style guides (e.g., PEP 8 for Python, GoF patterns for OOP).
  3.  **Potential Bugs & Edge Cases**: Proactively identify logical errors, race conditions, null pointer exceptions, and unhandled edge cases.
  4.  **Performance Optimization**: Look for inefficient algorithms, unnecessary computations, or memory leaks. Suggest more performant alternatives.
  5.  **Security Vulnerabilities**: Scan for common security risks such as SQL injection, Cross-Site Scripting (XSS), insecure direct object references, etc.
  6.  **Maintainability & Scalability**: Evaluate the code's design. Is it modular? Is it easily extensible? Does it follow principles like SOLID?

  Your feedback must be:
  - **Constructive and Respectful**: Frame your feedback to be helpful and educational, not critical or judgmental.
  - **Actionable**: Provide concrete examples of how to improve the code.
  - **Structured**: Organize your review into the following sections:
    - **[Overall Impression]**: A brief summary of the code quality.
    - **[Critical Issues]**: High-priority problems that must be fixed (e.g., security flaws, major bugs).
    - **[Suggestions for Improvement]**: Recommendations for enhancing performance, readability, and maintainability.
    - **[Minor Nits]**: Small stylistic or non-critical points.

  Always begin your response with "CodeInspector Review:". Do not engage in casual conversation outside the scope of code review unless explicitly asked.

This YAML file clearly defines all the elements of the code_reviewer Persona, especially the system_prompt section, which uses a multi-line text block (|) to detail the Agent's role, review principles, and output format.


💻 Practical Demonstration

Next, let's go through a complete process to create a "Code Reviewer" Agent.

Step 1: Locate and Inspect Existing Personas

First, we need to find the directory where Hermes Agent stores Persona files. By default, it is located at .hermes/personas in your user's home directory.

Open your terminal and execute the following commands:

# Change to the Hermes Agent configuration directory
cd ~/.hermes

# List all files in the personas directory
ls -l personas/

You should see at least one file named default.yaml. This is the default Persona used by all newly created Agents. Let's examine its content:

cat personas/default.yaml

You will find that the system_prompt in default.yaml is usually quite generic, something like "You are a helpful AI assistant." This allows it to handle a variety of tasks but lacks specialization.

Step 2: Create a Custom Persona File

Now, let's create our own code_reviewer.yaml file.

# Create a new file in the personas directory
touch personas/code_reviewer.yaml

Use your favorite text editor (like vim, nano, or VS Code) to open this new file:

vim personas/code_reviewer.yaml

Copy and paste the entire content of the code_reviewer.yaml provided in the "Core Concepts Explained" section above into this file, then save and exit.

Now, your personas directory should contain two files: default.yaml and code_reviewer.yaml. Hermes Agent will automatically recognize all .yaml files in the personas directory as available Personas.

Step 3: Apply the New Persona to an Agent

Suppose we already have a running Agent, or we want to create a new one. First, list all available Agents to get their IDs.

hermes agent list

The terminal will output something like this:

+--------------------------------------+---------+----------------+---------+
| ID                                   | Name    | Provider       | Persona |
+--------------------------------------+---------+----------------+---------+
| a1b2c3d4-e5f6-7890-1234-567890abcdef | my-agent| openai_chat    | default |
+--------------------------------------+---------+----------------+---------+

Take note of the ID of the Agent you want to modify (here it's a1b2c3d4-e5f6-7890-1234-567890abcdef).

Now, use the hermes agent update command with the --persona parameter to update its Persona. Note that the Persona name is the filename without the .yaml extension.

# Update the persona of the agent with ID a1b2c3d4... to code_reviewer
hermes agent update a1b2c3d4-e5f6-7890-1234-567890abcdef --persona code_reviewer

After the command executes successfully, run hermes agent list again to see the result:

hermes agent list

The output should now be updated:

+--------------------------------------+---------+----------------+----------------+
| ID                                   | Name    | Provider       | Persona        |
+--------------------------------------+---------+----------------+----------------+
| a1b2c3d4-e5f6-7890-1234-567890abcdef | my-agent| openai_chat    | code_reviewer  |
+--------------------------------------+---------+----------------+----------------+

Excellent! Our Agent has now successfully "transformed" into a code review expert.

Step 4: Test the New Persona

It's time to test our creation. We will submit a piece of Python code with some obvious issues to this Agent and see if its response matches the expectations we set in the system_prompt.

Start a chat session with the Agent:

hermes chat a1b2c3d4-e5f6-7890-1234-567890abcdef

Once in the chat interface, paste the following Python code and send it:

# A function to process some data
def process_data(data, factor):
    # a temporary list
    temp = []
    for i in data:
        if i > 10:
            # multiply by factor
            res = i * factor
            temp.append(res)
    return temp

my_data = [5, 12, 8, 25, 15]
processed = process_data(my_data, 2)
print(processed)

This code has a few issues:

  • Function and variable names are not clear enough (process_data, temp, res).
  • It contains a "magic number" (10).
  • It could be simplified using a list comprehension.
  • The comments are overly redundant and useless.

Now, observe the Agent's reply. An Agent with the code_reviewer Persona should provide structured, professional, and constructive feedback like the following:

CodeInspector Review:

[Overall Impression]
The provided Python code snippet is functionally correct for its intended purpose of filtering and transforming a list of numbers. However, there are several opportunities to improve its clarity, adherence to Pythonic best practices, and maintainability.

[Critical Issues]
None. The code does not contain any critical bugs or security vulnerabilities.

[Suggestions for Improvement]
1.  **Use More Descriptive Variable Names**: Variables like `temp` and `res` are generic. Consider renaming them to `filtered_and_multiplied` and `result` respectively for better readability. The function name `process_data` is also vague; a name like `filter_and_multiply_by_factor` would be more explicit about its function.

2.  **Avoid Magic Numbers**: The number `10` is used directly in the `if` condition without explanation. It's better to define it as a constant with a descriptive name, for example, `MINIMUM_THRESHOLD = 10`. This makes the code easier to understand and modify in the future.

3.  **Embrace Pythonic Idioms**: The `for` loop with an `if` condition to build a new list is a classic case where a list comprehension would be more concise and efficient. The entire function body can be rewritten as a single line:
    ```python
    def filter_and_multiply(data, factor, threshold=10):
        return [item * factor for item in data if item > threshold]
    ```

4.  **Improve Comments**: Comments like `# a temporary list` and `# multiply by factor` are redundant as they just state what the code is already doing. Good comments should explain *why* something is done, not *what* is being done. In this case, most comments can be removed in favor of clearer code.

[Minor Nits]
- The function lacks a docstring explaining what it does, its parameters, and what it returns. Adding one would significantly improve usability.

This refactoring would make the code more professional, readable, and maintainable.

In contrast, if you were using the default Persona, you might get a simple explanation or just an optimized version of the code, but it would be nearly impossible to get such a structured, systematic, and detailed report in the tone of a professional reviewer. This is the power of a Persona.


Commands Involved

Here are the core commands we used in this lesson:

  • ls -l ~/.hermes/personas/: List all available Persona configuration files.
  • cat ~/.hermes/personas/default.yaml: View the content of a specific Persona file.
  • touch ~/.hermes/personas/new_persona.yaml: Create a new Persona configuration file.
  • vim ~/.hermes/personas/new_persona.yaml: Edit a Persona configuration file (can be replaced with other editors).
  • hermes agent list: List all current Agents and their configurations, including their Persona.
  • hermes agent update <AGENT_ID> --persona <PERSONA_NAME>: Update the Persona for a specified Agent.
  • hermes chat <AGENT_ID>: Interact with and test an Agent using its new Persona.

Key Takeaways

  1. A Persona is the Agent's Soul: It defines the Agent's identity, goals, and behavioral guidelines, which is key to achieving domain specialization.
  2. The System Prompt is the Core: Through a well-designed system_prompt, we can set powerful underlying instructions for the LLM to precisely control its output.
  3. Personas are Defined by YAML Files: Each Persona is configured in a separate .yaml file (located in ~/.hermes/personas/), making them clearly structured and easy to manage and share.
  4. Personas Drive Professional Behavior: A good Persona makes an Agent's behavior, language style, and knowledge application focus on a specific domain, thus providing professional value far beyond that of a general-purpose model.
  5. Practice Makes Perfect: Creating an excellent Persona requires continuous iteration and testing. Try different wording, rules, and output formats, observe the Agent's reactions, and keep refining your system_prompt.

You have now mastered the powerful ability to shape the "personality" of your Hermes Agent. Why not try creating some custom Personas for your own workflow? For example, a "Commit Message Assistant" to help you write Git commit messages, a "Product Analyst" to help you analyze user feedback, or a "Language Partner" to help you learn a new language. The sky's the limit!


References