[Feature]: Support typed input contracts when exposing agents through AsAIFunction
Description
Problem
AsAIFunction() exposes an agent through a fixed query: string input. In applications where a parent agent delegates structured tasks, we need named, typed arguments with a model-visible JSON schema.
We currently use AIFunctionFactory.Create around a typed delegate, build the child agent’s input from those arguments, and invoke the child explicitly. This works, but repeats adaptation code across specialized agents.
Requested capability
Consider a typed overload or companion helper that:
- Generates the tool’s input schema from a request type, exposing its properties as top-level tool arguments.
- Deserializes the full arguments object into that type.
- By default, serializes the request as JSON into a user message.
- Accepts an optional callback mapping the typed request to the child’s message or messages.
- Uses the configured serializer options consistently for schema generation, argument binding, and default message serialization.
- Rejects missing required properties or incompatible types before invoking the child.
- Provides a hook for application validation before invoking the child.
Alternatives considered
A typed AIFunctionFactory.Create wrapper is our current solution. Schema customization plus custom parameter binding is another option, but still requires adaptation logic and coordination between the advertised schema and invocation behavior.
Would a typed helper fit the intended direction of AsAIFunction()? If the existing wrapper is the preferred design, an official sample documenting that pattern would also be useful.
Environment
Microsoft.Agents.AI 1.15.0; Microsoft.Extensions.AI 10.8.3.
Code Sample
using System.Text.Json;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
// Assume chatClient is an already configured IChatClient.
var serializerOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web);
AIAgent reviewer = chatClient.AsAIAgent(
name: "DocumentReviewer",
instructions: "Review the supplied document according to its review criteria.");
// PROPOSED API:
// Generate the input schema from DocumentReviewRequest,
// bind incoming arguments, then map the typed request to messages.
AIFunction reviewTool = reviewer.AsAIFunction<DocumentReviewRequest>(
inputToMessages: request =>
[
new ChatMessage(
ChatRole.User,
JsonSerializer.Serialize(request, serializerOptions))
],
options: new AIFunctionFactoryOptions
{
Name = "review_document",
Description = "Review a document for a target audience.",
SerializerOptions = serializerOptions
});
AIAgent assistant = chatClient.AsAIAgent(
name: "Assistant",
instructions: "Delegate document reviews to the review_document tool.",
tools: [reviewTool]);
// Request types would normally live in separate files.
public sealed record DocumentReviewRequest
{
public required string DocumentText { get; init; }
public required ReviewCriteria Criteria { get; init; }
}
public sealed record ReviewCriteria
{
public required string TargetAudience { get; init; }
public required int MaxFindings { get; init; }
}
// Example of how an agent would fill the DTO to call the subagent
//{
// "documentText": "Our application helps teams organize their work.",
// "criteria": {
// "targetAudience": "Nontechnical customers",
// "maxFindings": 5
// }
//}Language/SDK
Both
Source: microsoft/agent-framework