Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def run_semantic_kernel() -> None:
async with AzureCliCredential() as credential, AzureAIAgent.create_client(credential=credential) as client:
settings = AzureAIAgentSettings() # Reads env vars for region/deployment.
# SK builds the remote agent definition then wraps it with AzureAIAgent.
definition = await client.agents.as_agent(
definition = await client.agents.create_agent(
model=settings.model_deployment_name,
name="Support",
instructions="Answer customer questions in one paragraph.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def run_semantic_kernel() -> None:
async with AzureCliCredential() as credential, AzureAIAgent.create_client(credential=credential) as client:
settings = AzureAIAgentSettings()
# Register the hosted code interpreter tool with the remote agent.
definition = await client.agents.as_agent(
definition = await client.agents.create_agent(
model=settings.model_deployment_name,
name="Analyst",
instructions="Use the code interpreter for numeric work.",
Expand All @@ -46,9 +46,7 @@ async def run_agent_framework() -> None:
AzureCliCredential() as credential,
AzureAIAgentsProvider(credential=credential) as provider,
):
# Create a client to access hosted tool factory methods
client = AzureAIAgentClient(agents_client=provider._agents_client)
code_interpreter_tool = client.get_code_interpreter_tool()
code_interpreter_tool = AzureAIAgentClient.get_code_interpreter_tool()

agent = await provider.create_agent(
name="Analyst",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def run_semantic_kernel() -> None:

async with AzureCliCredential() as credential, AzureAIAgent.create_client(credential=credential) as client:
settings = AzureAIAgentSettings()
definition = await client.agents.as_agent(
definition = await client.agents.create_agent(
model=settings.model_deployment_name,
name="Planner",
instructions="Track follow-up questions within the same thread.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def specials(self) -> str:


async def run_agent_framework() -> None:
from agent_framework._tools import tool
from agent_framework import tool
from agent_framework.openai import OpenAIChatClient

@tool(name="specials", description="List daily specials")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ async def run_agent_framework() -> None:
instructions="Answer questions in one concise paragraph.",
model=ASSISTANT_MODEL,
) as assistant_agent:
reply = await assistant_agent.run("What is the capital of Denmark?")
session = assistant_agent.create_session()
reply = await assistant_agent.run("What is the capital of Denmark?", session=session)
print("[AF]", reply.text)
follow_up = await assistant_agent.run(
"How many residents live there?",
session=assistant_agent.create_session(),
session=session,
)
print("[AF][follow-up]", follow_up.text)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def run_semantic_kernel() -> None:

# Enable the hosted code interpreter tool on the assistant definition.
definition = await client.beta.assistants.create(
model=OpenAISettings().chat_deployment_name,
model=OpenAISettings().chat_model_id,
name="CodeRunner",
instructions="Run the provided request as code and return the result.",
tools=code_interpreter_tool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def run_semantic_kernel() -> None:

class WeatherPlugin:
@kernel_function(name="get_forecast", description="Look up the forecast for a city and day.")
async def fake_weather_lookup(city: str, day: str) -> dict[str, Any]:
async def fake_weather_lookup(self, city: str, day: str) -> dict[str, Any]:
"""Pretend to call a weather service."""
return {
"city": city,
Expand All @@ -50,9 +50,8 @@ async def fake_weather_lookup(city: str, day: str) -> dict[str, Any]:
model=ASSISTANT_MODEL,
name="WeatherHelper",
instructions="Call get_forecast to fetch weather details.",
plugins=[WeatherPlugin()],
)
agent = OpenAIAssistantAgent(client=client, definition=definition)
agent = OpenAIAssistantAgent(client=client, definition=definition, plugins=[WeatherPlugin()])

thread: AssistantAgentThread | None = None
response = await agent.get_response(
Expand All @@ -64,7 +63,7 @@ async def fake_weather_lookup(city: str, day: str) -> dict[str, Any]:


async def run_agent_framework() -> None:
from agent_framework._tools import tool
from agent_framework import tool
from agent_framework.openai import OpenAIAssistantsClient

@tool(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,19 @@


async def run_semantic_kernel() -> None:
from azure.identity import AzureCliCredential
from semantic_kernel.agents import AzureResponsesAgent
from semantic_kernel.connectors.ai.open_ai import AzureOpenAISettings

credential = AzureCliCredential()
try:
client = AzureResponsesAgent.create_client(credential=credential)
# SK response agents wrap Azure OpenAI's hosted Responses API.
agent = AzureResponsesAgent(
ai_model_id=AzureOpenAISettings().responses_deployment_name,
client=client,
instructions="Answer in one concise sentence.",
name="Expert",
)
response = await agent.get_response("Why is the sky blue?")
print("[SK]", response.message.content)
finally:
await credential.close()
from semantic_kernel.agents import OpenAIResponsesAgent
from semantic_kernel.connectors.ai.open_ai import OpenAISettings

client = OpenAIResponsesAgent.create_client()
# SK response agents wrap OpenAI's hosted Responses API.
agent = OpenAIResponsesAgent(
ai_model_id=OpenAISettings().responses_model_id,
client=client,
instructions="Answer in one concise sentence.",
name="Expert",
)
response = await agent.get_response("Why is the sky blue?")
print("[SK]", response.message.content)


async def run_agent_framework() -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,31 @@


async def run_semantic_kernel() -> None:
from azure.identity import AzureCliCredential
from semantic_kernel.agents import AzureResponsesAgent
from semantic_kernel.connectors.ai.open_ai import AzureOpenAISettings
from semantic_kernel.agents import OpenAIResponsesAgent
from semantic_kernel.connectors.ai.open_ai import OpenAISettings
from semantic_kernel.functions import kernel_function

class MathPlugin:
@kernel_function(name="add", description="Add two numbers")
def add(self, a: float, b: float) -> float:
return a + b

credential = AzureCliCredential()
try:
client = AzureResponsesAgent.create_client(credential=credential)
# Plugins advertise callable tools to the Responses agent.
agent = AzureResponsesAgent(
ai_model_id=AzureOpenAISettings().responses_deployment_name,
client=client,
instructions="Use the add tool when math is required.",
name="MathExpert",
plugins=[MathPlugin()],
)
response = await agent.get_response("Use add(41, 1) and explain the result.")
print("[SK]", response.message.content)
finally:
await credential.close()
client = OpenAIResponsesAgent.create_client()
# Plugins advertise callable tools to the Responses agent.
agent = OpenAIResponsesAgent(
ai_model_id=OpenAISettings().responses_model_id,
client=client,
instructions="Use the add tool when math is required.",
name="MathExpert",
plugins=[MathPlugin()],
)
response = await agent.get_response("Use add(41, 1) and explain the result.")
print("[SK]", response.message.content)


async def run_agent_framework() -> None:
from agent_framework import Agent
from agent_framework._tools import tool
from agent_framework import tool
from agent_framework.openai import OpenAIResponsesClient

@tool(name="add", description="Add two numbers")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,22 @@ class ReleaseBrief(BaseModel):


async def run_semantic_kernel() -> None:
from azure.identity import AzureCliCredential
from semantic_kernel.agents import AzureResponsesAgent
from semantic_kernel.connectors.ai.open_ai import AzureOpenAISettings
from semantic_kernel.agents import OpenAIResponsesAgent
from semantic_kernel.connectors.ai.open_ai import OpenAISettings

credential = AzureCliCredential()
try:
client = AzureResponsesAgent.create_client(credential=credential)
# response_format requests schema-constrained output from the model.
agent = AzureResponsesAgent(
ai_model_id=AzureOpenAISettings().responses_deployment_name,
client=client,
instructions="Return launch briefs as structured JSON.",
name="ProductMarketer",
text=AzureResponsesAgent.configure_response_format(ReleaseBrief),
)
response = await agent.get_response(
"Draft a launch brief for the Contoso Note app.",
response_format=ReleaseBrief,
)
print("[SK]", response.message.content)
finally:
await credential.close()
client = OpenAIResponsesAgent.create_client()
# response_format requests schema-constrained output from the model.
agent = OpenAIResponsesAgent(
ai_model_id=OpenAISettings().responses_model_id,
client=client,
instructions="Return launch briefs as structured JSON.",
name="ProductMarketer",
text=OpenAIResponsesAgent.configure_response_format(ReleaseBrief),
)
response = await agent.get_response(
"Draft a launch brief for the Contoso Note app.",
)
print("[SK]", response.message.content)


async def run_agent_framework() -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
######################################################################


def build_semantic_kernel_agents() -> list[Agent]:
def build_semantic_kernel_agents() -> list[ChatCompletionAgent]:
credential = AzureCliCredential()

physics_agent = ChatCompletionAgent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from agent_framework.azure import AzureOpenAIChatClient, AzureOpenAIResponsesClient
from agent_framework.orchestrations import GroupChatBuilder
from azure.identity import AzureCliCredential
from semantic_kernel.agents import Agent, ChatCompletionAgent, GroupChatOrchestration
from semantic_kernel.agents import ChatCompletionAgent, GroupChatOrchestration
from semantic_kernel.agents.orchestration.group_chat import (
BooleanResult,
GroupChatManager,
Expand Down Expand Up @@ -50,7 +50,7 @@
######################################################################


def build_semantic_kernel_agents() -> list[Agent]:
def build_semantic_kernel_agents() -> list[ChatCompletionAgent]:
credential = AzureCliCredential()

researcher = ChatCompletionAgent(
Expand Down Expand Up @@ -82,25 +82,25 @@ class ChatCompletionGroupChatManager(GroupChatManager):
topic: str

termination_prompt: str = (
"You are coordinating a conversation about '{{topic}}'. "
"You are coordinating a conversation about '{{$topic}}'. "
"Decide if the discussion has produced a solid answer. "
'Respond using JSON: {"result": true|false, "reason": "..."}.'
)

selection_prompt: str = (
"You are coordinating a conversation about '{{topic}}'. "
"You are coordinating a conversation about '{{$topic}}'. "
"Choose the next participant by returning JSON with keys (result, reason). "
"The result must match one of: {{participants}}."
"The result must match one of: {{$participants}}."
)

summary_prompt: str = (
"You have just finished a discussion about '{{topic}}'. "
"You have just finished a discussion about '{{$topic}}'. "
"Summarize the plan and highlight key takeaways. Return JSON with keys (result, reason) where "
"result is the final response text."
)

def __init__(self, *, topic: str, service: ChatCompletionClientBase) -> None:
super().__init__(topic=topic, service=service)
def __init__(self, *, topic: str, service: ChatCompletionClientBase, max_rounds: int | None = None) -> None:
super().__init__(topic=topic, service=service, max_rounds=max_rounds)
self._round_robin_index = 0

async def _render_prompt(self, template: str, **kwargs: Any) -> str:
Expand Down
16 changes: 10 additions & 6 deletions python/samples/semantic-kernel-migration/orchestrations/handoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
WorkflowEvent,
)
from agent_framework.azure import AzureOpenAIChatClient
from agent_framework.orchestrations import HandoffBuilder, HandoffUserInputRequest
from agent_framework.orchestrations import HandoffAgentUserRequest, HandoffBuilder
from azure.identity import AzureCliCredential
from semantic_kernel.agents import Agent, ChatCompletionAgent, HandoffOrchestration, OrchestrationHandoffs
from semantic_kernel.agents.runtime import InProcessRuntime
Expand Down Expand Up @@ -223,7 +223,7 @@ async def _drain_events(stream: AsyncIterable[WorkflowEvent]) -> list[WorkflowEv
def _collect_handoff_requests(events: list[WorkflowEvent]) -> list[WorkflowEvent]:
requests: list[WorkflowEvent] = []
for event in events:
if event.type == "request_info" and isinstance(event.data, HandoffUserInputRequest):
if event.type == "request_info" and isinstance(event.data, HandoffAgentUserRequest):
requests.append(event)
return requests

Expand All @@ -241,12 +241,16 @@ async def run_agent_framework_example(initial_task: str, scripted_responses: Seq
triage, refund, status, returns = _create_af_agents(client)

workflow = (
HandoffBuilder(name="sk_af_handoff_migration", participants=[triage, refund, status, returns])
.set_coordinator(triage)
HandoffBuilder(
name="sk_af_handoff_migration",
participants=[triage, refund, status, returns],
termination_condition=lambda conv: sum(1 for m in conv if m.role == "user") >= 4,
)
.with_start_agent(triage)
.add_handoff(triage, [refund, status, returns])
.add_handoff(refund, [status, triage])
.add_handoff(status, [refund, triage])
.add_handoff(returns, triage)
.add_handoff(returns, [triage])
.build()
)

Expand All @@ -260,7 +264,7 @@ async def run_agent_framework_example(initial_task: str, scripted_responses: Seq
user_reply = next(scripted_iter)
except StopIteration:
user_reply = "Thanks, that's all."
responses = {request.request_id: user_reply for request in pending}
responses = {request.request_id: [Message(role="user", text=user_reply)] for request in pending}
final_events = await _drain_events(workflow.run(stream=True, responses=responses))
pending = _collect_handoff_requests(final_events)

Expand Down
Loading