Skip to content

[Microsoft.Extensions.AI] A way to dynamically provide Tools (AIFunctions) #6526

Answered by stephentoub
MihaMarkic asked this question in Q&A
Discussion options

You must be logged in to vote

You can derive from AIFunction and implement a derived type however you want. AIFunctionFactory.Create is just a convenient way to create an instance that represents a very common case, where you supply a delegate and it creates such a derived instance for you, but that's not the only way they're created. In the ModelContextProtocol library, for example, it has its own AIFunction-derived type that wraps the MCP server's tool information and overrides InvokeAsync to call back to the server.
https://github.com/modelcontextprotocol/csharp-sdk/blob/befa31d5c948f72396a280a675535a653ee19aee/src/ModelContextProtocol.Core/Client/McpClientTool.cs

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@MihaMarkic
Comment options

@stephentoub
Comment options

@MihaMarkic
Comment options

@stephentoub
Comment options

@MihaMarkic
Comment options

Answer selected by MihaMarkic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants