A Persona is a structured attribute bundle (role, style, goals, etc.) used to condition LLM prompts. SDialog provides many built-in personas across domains like Healthcare, Finance, and Technical Support.
Custom Personas
To create a custom persona, inherit from sdialog.personas.BasePersona. All personas support .clone(overrides) for creating variants with lineage tracking, and serialization via .json() or .to_file().
Automated Persona Generation
You can use PersonaGenerator to automatically generate persona instances based on a class definition. If you use Pydantic Field descriptions in your class, the generator uses those descriptions as instructions for the LLM.
from sdialog.generators import PersonaGenerator
from sdialog.personas import BasePersona
from pydantic import Field
# Define a custom persona with field descriptions for the LLM
class TravelAgentPersona(BasePersona):
role: str = Field("", description="The role of the persona, e.g., 'Travel Agent'")
expertise: str = Field("", description="The area of expertise")
tone: str = Field("", description="The tone of the persona")
goals: str = Field("", description="A short description of the goals")
constraints: str = Field("", description="Operational constraints")
# Use PersonaGenerator to create an instance via an LLM
generator = PersonaGenerator(TravelAgentPersona, model="openai:gpt-4")
generated_persona = generator.generate()
generated_persona.print()