Skip to content

.NET: [Feature]: Allow AIAgent to attach AIContextProvider during a single run #6370

@helloxubo

Description

@helloxubo

Description

I would like AIAgent to support attaching an AIContextProvider for a specific run, so that context enrichment can be applied dynamically at runtime.
Currently, AIContextProvider can enrich:
• Instructions
• Tools
• Messages
However, there does not appear to be a straightforward way to attach a provider to AIAgent for a single invocation in the same style as:

agent = agent
    .AsBuilder()
    .UseAIContextProviders(xxxProvider)
    .Build();

Problem Statement
At the moment, AIAgentBuilder.UseAIContextProviders(...) appears to support only MessageAIContextProvider, while AIContextProvider itself is more general and can enrich more than just messages.
This makes it difficult to dynamically inject context enrichment logic at runtime for a single agent execution.

Expected Behavior
I would like to xxxProvider is an AIContextProvider, and it can be used during one agent run to enrich:
• Instructions
• Tools
• Messages

Use Cases
• Injecting runtime-specific system instructions
• Loading tools dynamically before invocation
• Adding contextual messages from session or memory
• Updating session state after the run
Current Limitation
• AIAgent does not seem to provide a direct way to attach a general AIContextProvider per run
• The existing builder API seems focused on MessageAIContextProvider
• This limits the ability to use the full AIContextProvider lifecycle in agent pipelines
Suggested Improvement
Consider adding support in AIAgentBuilder for AIContextProvider, similar to the existing support in ChatClientBuilder.
This would make runtime context enrichment more consistent and flexible across the framework.

Code Sample

Language/SDK

.NET

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions