Building Better AI Agents: Mastering CrewAI Personas

Lately, I’ve been researching how to make AI agents that don’t suck, are engaging, and produce the expected results and one thing that kept coming up is the importance of having well-crafted prompts. Prompts are texts that go into an LLM and induce it to take an action and produce an output. The quality of your prompts determines the quality of your outputs. I wrote a small post about this on LinkedIn, check it out.

What is CrewAI

CrewAi describes itself as a cutting-edge framework for orchestrating role-playing, autonomous AI agents. This means role playing aka personas are an integral part of the system. Asking 2 agents which have different personas the same question often leads to getting significantly different results.

What are personas and why do we need them

In AI, a persona agent is an agent that has a specific character, personality, or role. The agent has a well-defined character with unique attributes, values, and beliefs. An example of a persona agent is a customer support agent who personifies a specific company culture or product image. This enhances the user experience because when they communicate with the agent the company’s brand and identity is maintained.

Agents with personas enhance the user experience by creating a more natural interaction which in turn increases user satisfaction and engagement. Since personas are system prompts for our agents, we can define them to be whatever we want eg we can make it in such a way that it strengthens the brand’s voice in every interaction customers have with our agent.

How are personas defined in CrewAI

CrewAI allows us to define agents with 3 attributes that help shape the persona of our agents.

  • role - the specific real-world role the agent is supposed to play eg Customer Support Agent
  • goal - the outcome or result that we aim to achieve eg resolve customer queries
  • backstory - this provides more details on the role, goal, and how to achieve it.

an example of this is the customer support agent below

from crewai import Agent

agent = Agent(
  role='Customer Support Agent',
  goal='Resolve customer issues efficiently and effectively, while maintaining a positive and helpful demeanor.',
  backstory="""You are a seasoned customer support professional with years of experience under your belt. 
  You love figuring out what customers need and finding solutions. 
  You are good at building relationships and turning frustrated customers into happy ones. 
  Always looking for ways to make things better for our customers and the team.
  """,
 )

It have been noted that agents with a suitable role, goal and backstory often perform very well. The paper **PersonaGym: Evaluating Persona Agents and LLMs provides valuable insight into this.**

CrewAI also provides us a way to add more context to our agent when it’s performing it’s tasks. We can pass in a description and expected_output

  • description - a clear description of the task to be performed
  • expected_output - the exact result we expect when the agent finishes executing.

An example might look like the task below

task = Task(
    description='Resolve customer inquiries and complaints related to our products or services.',
    expected_output='Customer issues are resolved to satisfaction, resulting in increased customer loyalty and positive brand perception.',
)

To craft a great persona that performs well requires a lot of research and experimentation. This requires minor tweaks to the persona until we get the level of performance that we want.

What has been your experience building personas for your CrewAI projects. Reach out to me on X (formerly Twitter) or LinkedIn.

AI should drive results, not complexity. AgentemAI helps businesses build scalable, efficient, and secure AI solutions. See how we can help.