Skip to content

Commit e43fc8c

Browse files
authored
Python: Fix migration samples (#5015)
* Fix migration samples * Fix migration samples 2 * Fix formatting * Comments
1 parent d992feb commit e43fc8c

14 files changed

Lines changed: 101 additions & 85 deletions

File tree

python/samples/autogen-migration/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ This gallery helps AutoGen developers move to the Microsoft Agent Framework (AF)
66

77
### Single-Agent Parity
88

9-
- [01_basic_assistant_agent.py](single_agent/01_basic_assistant_agent.py) — Minimal AutoGen `AssistantAgent` and AF `Agent` comparison.
10-
- [02_assistant_agent_with_tool.py](single_agent/02_assistant_agent_with_tool.py) — Function tool integration in both SDKs.
11-
- [03_assistant_agent_thread_and_stream.py](single_agent/03_assistant_agent_thread_and_stream.py) — Session management and streaming responses.
9+
- [01_basic_agent.py](single_agent/01_basic_agent.py) — Minimal AutoGen `AssistantAgent` and AF `Agent` comparison.
10+
- [02_agent_with_tool.py](single_agent/02_agent_with_tool.py) — Function tool integration in both SDKs.
11+
- [03_agent_thread_and_stream.py](single_agent/03_agent_thread_and_stream.py) — Session management and streaming responses.
1212
- [04_agent_as_tool.py](single_agent/04_agent_as_tool.py) — Using agents as tools (hierarchical agent pattern) and streaming with tools.
1313

1414
### Multi-Agent Orchestration
@@ -35,7 +35,7 @@ Each script is fully async and the `main()` routine runs both implementations ba
3535
From the repository root:
3636

3737
```bash
38-
python samples/autogen-migration/single_agent/01_basic_assistant_agent.py
38+
python samples/autogen-migration/single_agent/01_basic_agent.py
3939
```
4040

4141
Every script accepts no CLI arguments and will first call the AutoGen implementation, followed by the AF version. Adjust the prompt or credentials inside the file as necessary before running.

python/samples/autogen-migration/orchestrations/01_round_robin_group_chat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async def run_agent_framework() -> None:
6565
from agent_framework.openai import OpenAIChatClient
6666
from agent_framework.orchestrations import SequentialBuilder
6767

68-
client = OpenAIChatClient(model_id="gpt-4.1-mini")
68+
client = OpenAIChatClient(model="gpt-4.1-mini")
6969

7070
# Create specialized agents
7171
researcher = Agent(
@@ -112,7 +112,7 @@ async def run_agent_framework_with_cycle() -> None:
112112
)
113113
from agent_framework.openai import OpenAIChatClient
114114

115-
client = OpenAIChatClient(model_id="gpt-4.1-mini")
115+
client = OpenAIChatClient(model="gpt-4.1-mini")
116116

117117
# Create specialized agents
118118
researcher = Agent(

python/samples/autogen-migration/orchestrations/04_magentic_one.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async def run_agent_framework() -> None:
7676
from agent_framework.openai import OpenAIChatClient
7777
from agent_framework.orchestrations import MagenticBuilder
7878

79-
client = OpenAIChatClient(model_id="gpt-4.1-mini")
79+
client = OpenAIChatClient(model="gpt-4.1-mini")
8080

8181
# Create specialized agents
8282
researcher = Agent(

python/samples/autogen-migration/single_agent/01_basic_assistant_agent.py renamed to python/samples/autogen-migration/single_agent/01_basic_agent.py

File renamed without changes.

python/samples/autogen-migration/single_agent/02_assistant_agent_with_tool.py renamed to python/samples/autogen-migration/single_agent/02_agent_with_tool.py

File renamed without changes.

python/samples/autogen-migration/single_agent/03_assistant_agent_thread_and_stream.py renamed to python/samples/autogen-migration/single_agent/03_agent_thread_and_stream.py

File renamed without changes.

python/samples/semantic-kernel-migration/chat_completion/02_chat_completion_with_tool.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
async def run_semantic_kernel() -> None:
26-
from semantic_kernel.agents import ChatCompletionAgent, ChatHistoryAgentThread
26+
from semantic_kernel.agents import ChatCompletionAgent
2727
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
2828
from semantic_kernel.functions import kernel_function
2929

@@ -39,11 +39,7 @@ def specials(self) -> str:
3939
instructions="Answer menu questions accurately.",
4040
plugins=[SpecialsPlugin()],
4141
)
42-
thread = ChatHistoryAgentThread()
43-
response = await agent.get_response(
44-
messages="What soup can I order today?",
45-
thread=thread,
46-
)
42+
response = await agent.get_response("What soup can I order today?")
4743
print("[SK]", response.message.content)
4844

4945

@@ -62,12 +58,7 @@ async def specials() -> str:
6258
instructions="Answer menu questions accurately.",
6359
tools=[specials],
6460
)
65-
session = chat_agent.create_session()
66-
reply = await chat_agent.run(
67-
"What soup can I order today?",
68-
session=session,
69-
tool_choice="auto",
70-
)
61+
reply = await chat_agent.run("What soup can I order today?")
7162
print("[AF]", reply.text)
7263

7364

python/samples/semantic-kernel-migration/openai_responses/01_basic_responses_agent.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ async def run_semantic_kernel() -> None:
2222
from semantic_kernel.agents import OpenAIResponsesAgent
2323
from semantic_kernel.connectors.ai.open_ai import OpenAISettings
2424

25+
openai_settings = OpenAISettings()
26+
assert openai_settings.responses_model_id is not None, "Responses model ID must be set in OpenAISettings"
27+
2528
client = OpenAIResponsesAgent.create_client()
2629
# SK response agents wrap OpenAI's hosted Responses API.
2730
agent = OpenAIResponsesAgent(
28-
ai_model=OpenAISettings().responses_model_id,
31+
ai_model_id=openai_settings.responses_model_id,
2932
client=client,
3033
instructions="Answer in one concise sentence.",
3134
name="Expert",

python/samples/semantic-kernel-migration/openai_responses/02_responses_agent_with_tool.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ class MathPlugin:
2828
def add(self, a: float, b: float) -> float:
2929
return a + b
3030

31+
openai_settings = OpenAISettings()
32+
assert openai_settings.responses_model_id is not None, "Responses model ID must be set in OpenAISettings"
33+
3134
client = OpenAIResponsesAgent.create_client()
3235
# Plugins advertise callable tools to the Responses agent.
3336
agent = OpenAIResponsesAgent(
34-
ai_model=OpenAISettings().responses_model_id,
37+
ai_model_id=openai_settings.responses_model_id,
3538
client=client,
3639
instructions="Use the add tool when math is required.",
3740
name="MathExpert",

python/samples/semantic-kernel-migration/openai_responses/03_responses_agent_structured_output.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ async def run_semantic_kernel() -> None:
2929
from semantic_kernel.agents import OpenAIResponsesAgent
3030
from semantic_kernel.connectors.ai.open_ai import OpenAISettings
3131

32+
openai_settings = OpenAISettings()
33+
assert openai_settings.responses_model_id is not None, "Responses model ID must be set in OpenAISettings"
34+
3235
client = OpenAIResponsesAgent.create_client()
3336
# response_format requests schema-constrained output from the model.
3437
agent = OpenAIResponsesAgent(
35-
ai_model=OpenAISettings().responses_model_id,
38+
ai_model_id=openai_settings.responses_model_id,
3639
client=client,
3740
instructions="Return launch briefs as structured JSON.",
3841
name="ProductMarketer",
39-
text=OpenAIResponsesAgent.configure_response_format(ReleaseBrief),
42+
text=OpenAIResponsesAgent.configure_response_format(ReleaseBrief), # type: ignore
4043
)
4144
response = await agent.get_response(
4245
"Draft a launch brief for the Contoso Note app.",

0 commit comments

Comments
 (0)