Class AgentIdentity
Represents the identity of an agent, defining its persona and behavioral instructions.
public sealed class AgentIdentity
- Inheritance
-
AgentIdentity
- Inherited Members
Examples
Creating identities for different roles:
using LMKit.Agents;
// Technical support agent
var supportIdentity = new AgentIdentity(
persona: "Technical Support Specialist",
instruction: "Help users troubleshoot software issues. " +
"Ask clarifying questions before suggesting solutions. " +
"Escalate complex issues to human support."
);
// Creative writing agent
var writerIdentity = new AgentIdentity(
persona: "Creative Writing Coach",
instruction: "Help users improve their creative writing. " +
"Provide constructive feedback and specific suggestions. " +
"Encourage experimentation while respecting the author's voice."
);
// Code review agent
var reviewerIdentity = new AgentIdentity(
persona: "Senior Code Reviewer",
instruction: "Review code for bugs, security issues, and best practices. " +
"Explain issues clearly and suggest concrete fixes. " +
"Focus on high-impact improvements."
);
Remarks
An agent's identity shapes who it is and how it behaves. It consists of two components:
- Persona: The agent's role, personality, and communication style (who it is).
- Instruction: The operational guidelines defining what tasks the agent handles and how (what it does).
Designing Effective Identities
A well-designed identity helps the model produce consistent, high-quality responses:
- Keep personas concise and role-focused.
- Use instructions to define boundaries and output expectations.
- Be specific about the domain and expertise level.
Thread Safety
This class is immutable and thread-safe for concurrent reads after construction.
Constructors
- AgentIdentity(string)
Initializes a new instance of the AgentIdentity class with only a persona.
- AgentIdentity(string, string)
Initializes a new instance of the AgentIdentity class with the specified persona and instruction.
Properties
- Empty
Gets an empty identity with no persona or instruction defined.
- HasInstruction
Gets a value indicating whether this identity has a defined instruction.
- HasPersona
Gets a value indicating whether this identity has a defined persona.
- Instruction
Gets the base instruction that guides the agent's behavior and responsibilities.
- IsEmpty
Gets a value indicating whether this identity is empty (no persona or instruction defined).
- Persona
Gets the persona that defines the agent's role and communication style.
Methods
- ToString()
Returns the persona as the string representation of this identity.
- ToSystemPrompt()
Formats the identity as a system prompt suitable for injection into a conversation.
- WithInstruction(string)
Creates a new AgentIdentity with the specified instruction, preserving the current persona.
- WithPersona(string)
Creates a new AgentIdentity with the specified persona, preserving the current instruction.