You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: agent-framework/migration-guide/from-semantic-kernel/index.md
+56-14Lines changed: 56 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -297,7 +297,7 @@ Semantic kernel provides specific agent classes for various services, e.g.
297
297
298
298
#### Agent Framework
299
299
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`.
301
301
302
302
`ChatClientAgent` can be used to build agents using any underlying service that provides an SDK implementing the `Microsoft.Extensions.AI.IChatClient` interface.
303
303
@@ -354,7 +354,14 @@ Every agent in Semantic Kernel depends on a `Kernel` instance and will have
354
354
an empty `Kernel` if not provided.
355
355
356
356
```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
+
)
358
365
```
359
366
360
367
@@ -385,7 +392,9 @@ The direct method, exposes all possible parameters you can set for your agent, w
385
392
The caller has to know the thread type and create it manually.
386
393
387
394
```python
388
-
#TODO: Add thread creation examples
395
+
from semantic_kernel.agents import ChatHistoryAgentThread
396
+
397
+
thread = ChatHistoryAgentThread()
389
398
```
390
399
391
400
#### Agent Framework
@@ -416,7 +425,8 @@ If you require thread deletion and the provider allows this, the caller **should
416
425
417
426
i.e: OpenAI Assistants Provider
418
427
```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()
420
430
```
421
431
422
432
### 5. Tool Registration
@@ -431,7 +441,19 @@ In semantic kernel to expose a function as a tool you must:
431
441
4. Pass the `Kernel` to the agent.
432
442
433
443
```python
434
-
#TODO: Add SK tool registration example
444
+
from semantic_kernel.functions import kernel_function
@@ -508,16 +530,26 @@ Key differences can be seen in the method names from `invoke` to `run`, return t
508
530
509
531
#### Semantic Kernel
510
532
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.
512
534
513
535
```python
514
-
#TODO: Add SK non-streaming invocation example
536
+
asyncfor 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}")
515
547
```
516
548
517
549
#### Agent Framework
518
550
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)`.
521
553
All messages created as part of the response are returned in the `response.messages` list.
522
554
This may include tool call messages, function results, reasoning updates and final results.
523
555
@@ -536,22 +568,27 @@ Key differences in the method names from `invoke` to `run_stream`, return types
536
568
#### Semantic Kernel
537
569
538
570
```python
539
-
#TODO: Add SK streaming invocation example
571
+
asyncfor 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)
540
577
```
541
578
542
579
#### Agent Framework
543
580
544
581
Similar streaming API pattern with the key difference being that it returns `AgentRunResponseUpdate` objects including more agent related information per update.
545
582
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.
547
584
548
585
```python
549
586
from agent_framework import AgentRunResponse
550
587
agent =...
551
588
updates = []
552
589
asyncfor update in agent.run_stream(user_input, thread):
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.
0 commit comments