Skip to content

Commit c783a53

Browse files
Copilotrogerbarreto
andcommitted
Add runtime tool registration example to migration guide
Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
1 parent a377369 commit c783a53

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

.github/upgrades/prompts/SemanticKernelToAgentFramework.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,57 @@ AIAgent agent = chatClient.CreateAIAgent(
384384
7. Pass tools directly to agent creation method
385385
</configuration_changes>
386386

387+
### Runtime Tool Registration Transformation
388+
389+
<configuration_changes>
390+
In Semantic Kernel, plugins/tools could be registered via DI and then added to the kernel at runtime. Agent Framework requires tools to be provided either at agent creation time or at runtime via options.
391+
392+
**Replace this Semantic Kernel runtime tool registration pattern:**
393+
```csharp
394+
// Semantic Kernel - Tools registered via DI and added to kernel instance
395+
IKernelBuilder kernelBuilder = Kernel.CreateBuilder();
396+
kernelBuilder.Services.AddSingleton<ISearchService, SearchService>();
397+
kernelBuilder.Plugins.AddFromType<SearchPlugin>();
398+
399+
Kernel kernel = kernelBuilder.Build();
400+
ChatCompletionAgent agent = new() { Kernel = kernel };
401+
402+
// Tools are available on every invocation
403+
await foreach (var item in agent.InvokeAsync(userInput, thread)) { ... }
404+
```
405+
406+
**With this Agent Framework pattern using runtime tool registration:**
407+
```csharp
408+
// Define the tool function
409+
[Description("Get the weather for a location")]
410+
static string GetWeather(string location) => $"Weather in {location}: Sunny";
411+
412+
// Create agent without tools
413+
AIAgent agent = chatClient.CreateAIAgent(
414+
instructions: "You are a helpful assistant");
415+
416+
// Provide tools at runtime via ChatClientAgentRunOptions
417+
var chatOptions = new ChatOptions
418+
{
419+
Tools = [AIFunctionFactory.Create(GetWeather)]
420+
};
421+
var options = new ChatClientAgentRunOptions(chatOptions);
422+
423+
AgentRunResponse result = await agent.RunAsync(userInput, thread, options);
424+
```
425+
426+
**Required changes:**
427+
1. Create agent without tools if tools need to be determined at runtime
428+
2. Create `ChatOptions` with the `Tools` property containing the tools
429+
3. Wrap `ChatOptions` in `ChatClientAgentRunOptions`
430+
4. Pass options to `RunAsync()` or `RunStreamingAsync()` methods
431+
432+
**Note:** This pattern is useful for scenarios where tools need to be:
433+
- Enabled/disabled per user or per request
434+
- Added based on tenant configuration, licensing, or feature flags
435+
- Composed dynamically in modular systems
436+
</configuration_changes>
437+
387438
### Invocation Method Transformation
388439

389440
<api_changes>

0 commit comments

Comments
 (0)