Skip to content

AgentExecutionContextExtensions

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework.Context

AgentExecutionContextExtensions Class

Extension methods for IAgentExecutionContextAccessor and IAgentExecutionContext.

public static class AgentExecutionContextExtensions

Inheritance System.Object 🡒 AgentExecutionContextExtensions

Methods

AgentExecutionContextExtensions.GetProperty<T>(this IAgentExecutionContext) Method

Gets a typed property from the context's property bag, keyed by the type's full name. Returns null if not found or if the stored value is not assignable to T.

public static T? GetProperty<T>(this NexusLabs.Needlr.AgentFramework.Context.IAgentExecutionContext context)
    where T : class;

Type parameters

T

Parameters

context IAgentExecutionContext

Returns

T

Remarks

The default key (typeof(T).FullName) works well when each property type is unique within a context — the common case for domain records like ArticleAssignment, SeoReport, etc.

Properties is read-only by design. Consumers that need to store typed state should populate the property bag at context construction time via their own IAgentExecutionContext implementation.

AgentExecutionContextExtensions.GetProperty<T>(this IAgentExecutionContext, string) Method

Gets a typed property from the context's property bag with an explicit key. Returns null if not found or if the stored value is not assignable to T.

public static T? GetProperty<T>(this NexusLabs.Needlr.AgentFramework.Context.IAgentExecutionContext context, string key)
    where T : class;

Type parameters

T

Parameters

context IAgentExecutionContext

key System.String

Returns

T

AgentExecutionContextExtensions.GetRequired(this IAgentExecutionContextAccessor) Method

Returns the current IAgentExecutionContext or throws if none is established. Tools should call this rather than checking Current directly — there is no valid "anonymous" execution.

public static NexusLabs.Needlr.AgentFramework.Context.IAgentExecutionContext GetRequired(this NexusLabs.Needlr.AgentFramework.Context.IAgentExecutionContextAccessor accessor);

Parameters

accessor IAgentExecutionContextAccessor

Returns

IAgentExecutionContext

Exceptions

System.InvalidOperationException
Thrown when no execution context scope is active. This indicates a programming error: the orchestration layer must call BeginScope(IAgentExecutionContext) before invoking tools.

AgentExecutionContextExtensions.GetRequiredWorkspace(this IAgentExecutionContext) Method

Gets the workspace from the context, throwing if none is set. Convenience for tool implementations that require a workspace to operate.

public static NexusLabs.Needlr.AgentFramework.Workspace.IWorkspace GetRequiredWorkspace(this NexusLabs.Needlr.AgentFramework.Context.IAgentExecutionContext context);

Parameters

context IAgentExecutionContext

Returns

IWorkspace

Exceptions

System.InvalidOperationException
No workspace is available in the current context.

AgentExecutionContextExtensions.GetWorkspace(this IAgentExecutionContext) Method

Gets the workspace from the context, or null if none is set. Works with both AgentExecutionContext (which stores the workspace in Properties automatically) and custom implementations that put an IWorkspace in the property bag under the type key.

public static NexusLabs.Needlr.AgentFramework.Workspace.IWorkspace? GetWorkspace(this NexusLabs.Needlr.AgentFramework.Context.IAgentExecutionContext context);

Parameters

context IAgentExecutionContext

Returns

IWorkspace