Skip to content

Commit 48ff232

Browse files
updated migration guide
1 parent 58d407a commit 48ff232

1 file changed

Lines changed: 56 additions & 14 deletions

File tree

  • agent-framework/migration-guide/from-semantic-kernel

agent-framework/migration-guide/from-semantic-kernel/index.md

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ Semantic kernel provides specific agent classes for various services, e.g.
297297

298298
#### Agent Framework
299299

300-
The agent framework supports all the abovementioned services via a single agent type, `ChatClientAgent`.
300+
The agent framework supports all the above mentioned services via a single agent type, `ChatClientAgent`.
301301

302302
`ChatClientAgent` can be used to build agents using any underlying service that provides an SDK implementing the `Microsoft.Extensions.AI.IChatClient` interface.
303303

@@ -354,7 +354,14 @@ Every agent in Semantic Kernel depends on a `Kernel` instance and will have
354354
an empty `Kernel` if not provided.
355355

356356
```python
357-
# TODO: Add Semantic Kernel example
357+
from semantic_kernel.agents import ChatCompletionAgent
358+
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
359+
360+
agent = ChatCompletionAgent(
361+
service=OpenAIChatCompletion(),
362+
name="Support",
363+
instructions="Answer in one sentence.",
364+
)
358365
```
359366

360367

@@ -385,7 +392,9 @@ The direct method, exposes all possible parameters you can set for your agent, w
385392
The caller has to know the thread type and create it manually.
386393

387394
```python
388-
# TODO: Add thread creation examples
395+
from semantic_kernel.agents import ChatHistoryAgentThread
396+
397+
thread = ChatHistoryAgentThread()
389398
```
390399

391400
#### Agent Framework
@@ -416,7 +425,8 @@ If you require thread deletion and the provider allows this, the caller **should
416425

417426
i.e: OpenAI Assistants Provider
418427
```python
419-
# TODO: Add thread deletion via provider SDK example
428+
# OpenAI Assistants threads have self-deletion method in SK
429+
await thread.delete_async()
420430
```
421431

422432
### 5. Tool Registration
@@ -431,7 +441,19 @@ In semantic kernel to expose a function as a tool you must:
431441
4. Pass the `Kernel` to the agent.
432442

433443
```python
434-
# TODO: Add SK tool registration example
444+
from semantic_kernel.functions import kernel_function
445+
446+
class SpecialsPlugin:
447+
@kernel_function(name="specials", description="List daily specials")
448+
def specials(self) -> str:
449+
return "Clam chowder, Cobb salad, Chai tea"
450+
451+
agent = ChatCompletionAgent(
452+
service=OpenAIChatCompletion(),
453+
name="Host",
454+
instructions="Answer menu questions accurately.",
455+
plugins=[SpecialsPlugin()],
456+
)
435457
```
436458

437459
#### Agent Framework
@@ -508,16 +530,26 @@ Key differences can be seen in the method names from `invoke` to `run`, return t
508530

509531
#### Semantic Kernel
510532

511-
The Non-Streaming uses an async iterator pattern for returning multiple agent messages.
533+
The Non-Streaming invoke uses an async iterator pattern for returning multiple agent messages.
512534

513535
```python
514-
# TODO: Add SK non-streaming invocation example
536+
async for response in agent.invoke(
537+
messages=user_input,
538+
thread=thread,
539+
):
540+
print(f"# {response.role}: {response}")
541+
thread = response.thread
542+
```
543+
And we had a convenience method to get the final response:
544+
```python
545+
response = await agent.get_response(messages="How do I reset my bike tire?", thread=thread)
546+
print(f"# {response.role}: {response}")
515547
```
516548

517549
#### Agent Framework
518550

519-
The Non-Streaming returns a single `AgentRunResponse` with the agent response that can contain multiple messages.
520-
The text result of the run is available in `response.text` or `str(AgentRunResponse)`.
551+
The Non-Streaming run returns a single `AgentRunResponse` with the agent response that can contain multiple messages.
552+
The text result of the run is available in `response.text` or `str(response)`.
521553
All messages created as part of the response are returned in the `response.messages` list.
522554
This may include tool call messages, function results, reasoning updates and final results.
523555

@@ -536,22 +568,27 @@ Key differences in the method names from `invoke` to `run_stream`, return types
536568
#### Semantic Kernel
537569

538570
```python
539-
# TODO: Add SK streaming invocation example
571+
async for update in agent.invoke_stream(
572+
messages="Draft a 2 sentence blurb.",
573+
thread=thread,
574+
):
575+
if update.message:
576+
print(update.message.content, end="", flush=True)
540577
```
541578

542579
#### Agent Framework
543580

544581
Similar streaming API pattern with the key difference being that it returns `AgentRunResponseUpdate` objects including more agent related information per update.
545582

546-
All contents produced by any service underlying the Agent are returned. The textual result of the agent is available by concatenating the `response.text` values. And you can gather the updates up to a full response if needed.
583+
All contents produced by any service underlying the Agent are returned. The final result of the agent is available by combining the `update` values into a single response.
547584

548585
```python
549586
from agent_framework import AgentRunResponse
550587
agent = ...
551588
updates = []
552589
async for update in agent.run_stream(user_input, thread):
553590
updates.append(update)
554-
print(update.text) # Update is str() friendly
591+
print(update.text)
555592

556593
full_response = AgentRunResponse.from_agent_run_response_updates(updates)
557594
print("Full agent response:", full_response.text)
@@ -572,12 +609,17 @@ print("Full agent response:", full_response.text)
572609
**Problem**: Complex options setup in SK
573610

574611
```python
575-
# TODO: Add SK options configuration example
612+
from semantic_kernel.connectors.ai.open_ai import OpenAIPromptExecutionSettings
613+
614+
settings = OpenAIPromptExecutionSettings(max_tokens=1000)
615+
arguments = KernelArguments(settings)
616+
617+
response = await agent.get_response(user_input, thread=thread, arguments=arguments)
576618
```
577619

578620
**Solution**: Simplified options in AF
579621

580-
In agent framework, we allow the passing of all parameters directly to the relevant methods, so that you do not have to import anything extra, or create any options objects, unless you want to. Internally we use a `ChatOptions` object, that you can also create and pass in if you want to. This is also created in a `ChatAgent` to hold the options and can be overridden per call.
622+
In agent framework, we allow the passing of all parameters directly to the relevant methods, so that you do not have to import anything extra, or create any options objects, unless you want to. Internally we use a `ChatOptions` object for `ChatClients` and `ChatAgents`, that you can also create and pass in if you want to. This is also created in a `ChatAgent` to hold the options and can be overridden per call.
581623

582624
```python
583625
agent = ...

0 commit comments

Comments
 (0)