@@ -22,9 +22,6 @@ namespace Microsoft.Agents.AI;
2222[ DebuggerDisplay ( "{DisplayName,nq}" ) ]
2323public abstract class AIAgent
2424{
25- /// <summary>Default ID of this agent instance.</summary>
26- private readonly string _id = Guid . NewGuid ( ) . ToString ( "N" ) ;
27-
2825 /// <summary>
2926 /// Gets the unique identifier for this agent instance.
3027 /// </summary>
@@ -37,7 +34,19 @@ public abstract class AIAgent
3734 /// agent instances in multi-agent scenarios. They should remain stable for the lifetime
3835 /// of the agent instance.
3936 /// </remarks>
40- public virtual string Id => this . _id ;
37+ public string Id { get => this . IdCore ?? field ; } = Guid . NewGuid ( ) . ToString ( "N" ) ;
38+
39+ /// <summary>
40+ /// Gets a custom identifier for the agent, which can be overridden by derived classes.
41+ /// </summary>
42+ /// <value>
43+ /// A string representing the agent's identifier, or <see langword="null"/> if the default ID should be used.
44+ /// </value>
45+ /// <remarks>
46+ /// Derived classes can override this property to provide a custom identifier.
47+ /// When <see langword="null"/> is returned, the <see cref="Id"/> property will use the default randomly-generated identifier.
48+ /// </remarks>
49+ protected virtual string ? IdCore => null ;
4150
4251 /// <summary>
4352 /// Gets the human-readable name of the agent.
@@ -61,7 +70,7 @@ public abstract class AIAgent
6170 /// This property provides a guaranteed non-null string suitable for display in user interfaces,
6271 /// logs, or other contexts where a readable identifier is needed.
6372 /// </remarks>
64- public virtual string DisplayName => this . Name ?? this . Id ?? this . _id ; // final fallback to _id in case Id override returns null
73+ public virtual string DisplayName => this . Name ?? this . Id ;
6574
6675 /// <summary>
6776 /// Gets a description of the agent's purpose, capabilities, or behavior.
0 commit comments