Python: Fix migration samples (#5015)

* Fix migration samples

* Fix migration samples 2

* Fix formatting

* Comments
This commit is contained in:
Tao Chen
2026-03-31 23:32:30 -07:00
committed by GitHub
Unverified
parent d992febe9b
commit e43fc8ccec
14 changed files with 100 additions and 84 deletions
@@ -22,10 +22,13 @@ async def run_semantic_kernel() -> None:
from semantic_kernel.agents import OpenAIResponsesAgent
from semantic_kernel.connectors.ai.open_ai import OpenAISettings
openai_settings = OpenAISettings()
assert openai_settings.responses_model_id is not None, "Responses model ID must be set in OpenAISettings"
client = OpenAIResponsesAgent.create_client()
# SK response agents wrap OpenAI's hosted Responses API.
agent = OpenAIResponsesAgent(
ai_model=OpenAISettings().responses_model_id,
ai_model_id=openai_settings.responses_model_id,
client=client,
instructions="Answer in one concise sentence.",
name="Expert",
@@ -28,10 +28,13 @@ async def run_semantic_kernel() -> None:
def add(self, a: float, b: float) -> float:
return a + b
openai_settings = OpenAISettings()
assert openai_settings.responses_model_id is not None, "Responses model ID must be set in OpenAISettings"
client = OpenAIResponsesAgent.create_client()
# Plugins advertise callable tools to the Responses agent.
agent = OpenAIResponsesAgent(
ai_model=OpenAISettings().responses_model_id,
ai_model_id=openai_settings.responses_model_id,
client=client,
instructions="Use the add tool when math is required.",
name="MathExpert",
@@ -29,14 +29,17 @@ async def run_semantic_kernel() -> None:
from semantic_kernel.agents import OpenAIResponsesAgent
from semantic_kernel.connectors.ai.open_ai import OpenAISettings
openai_settings = OpenAISettings()
assert openai_settings.responses_model_id is not None, "Responses model ID must be set in OpenAISettings"
client = OpenAIResponsesAgent.create_client()
# response_format requests schema-constrained output from the model.
agent = OpenAIResponsesAgent(
ai_model=OpenAISettings().responses_model_id,
ai_model_id=openai_settings.responses_model_id,
client=client,
instructions="Return launch briefs as structured JSON.",
name="ProductMarketer",
text=OpenAIResponsesAgent.configure_response_format(ReleaseBrief),
text=OpenAIResponsesAgent.configure_response_format(ReleaseBrief), # type: ignore
)
response = await agent.get_response(
"Draft a launch brief for the Contoso Note app.",