mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: Clean up imports (#2318)
* chore: tidy imports * Update python/packages/azurefunctions/agent_framework_azurefunctions/_errors.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/packages/azurefunctions/agent_framework_azurefunctions/_callbacks.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: revert stub file change * chore: trigger pre-commit hook, re-add `annotations` import --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
b3e96b80ae
commit
79bb87061b
+19
-21
@@ -13,32 +13,30 @@ async def run_semantic_kernel() -> None:
|
||||
from azure.identity.aio import AzureCliCredential
|
||||
from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings
|
||||
|
||||
async with AzureCliCredential() as credential:
|
||||
async with 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.create_agent(
|
||||
model=settings.model_deployment_name,
|
||||
name="Support",
|
||||
instructions="Answer customer questions in one paragraph.",
|
||||
)
|
||||
agent = AzureAIAgent(client=client, definition=definition)
|
||||
response = await agent.get_response("How do I upgrade my plan?")
|
||||
print("[SK]", response.message.content)
|
||||
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.create_agent(
|
||||
model=settings.model_deployment_name,
|
||||
name="Support",
|
||||
instructions="Answer customer questions in one paragraph.",
|
||||
)
|
||||
agent = AzureAIAgent(client=client, definition=definition)
|
||||
response = await agent.get_response("How do I upgrade my plan?")
|
||||
print("[SK]", response.message.content)
|
||||
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
from azure.identity.aio import AzureCliCredential
|
||||
from agent_framework.azure import AzureAIAgentClient
|
||||
from azure.identity.aio import AzureCliCredential
|
||||
|
||||
async with AzureCliCredential() as credential:
|
||||
async with AzureAIAgentClient(async_credential=credential).create_agent(
|
||||
name="Support",
|
||||
instructions="Answer customer questions in one paragraph.",
|
||||
) as agent:
|
||||
# AF client returns an asynchronous context manager for remote agents.
|
||||
reply = await agent.run("How do I upgrade my plan?")
|
||||
print("[AF]", reply.text)
|
||||
async with AzureCliCredential() as credential, AzureAIAgentClient(async_credential=credential).create_agent(
|
||||
name="Support",
|
||||
instructions="Answer customer questions in one paragraph.",
|
||||
) as agent:
|
||||
# AF client returns an asynchronous context manager for remote agents.
|
||||
reply = await agent.run("How do I upgrade my plan?")
|
||||
print("[AF]", reply.text)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
|
||||
+26
-28
@@ -13,39 +13,37 @@ async def run_semantic_kernel() -> None:
|
||||
from azure.identity.aio import AzureCliCredential
|
||||
from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings
|
||||
|
||||
async with AzureCliCredential() as credential:
|
||||
async with AzureAIAgent.create_client(credential=credential) as client:
|
||||
settings = AzureAIAgentSettings()
|
||||
# Register the hosted code interpreter tool with the remote agent.
|
||||
definition = await client.agents.create_agent(
|
||||
model=settings.model_deployment_name,
|
||||
name="Analyst",
|
||||
instructions="Use the code interpreter for numeric work.",
|
||||
tools=[{"type": "code_interpreter"}],
|
||||
)
|
||||
agent = AzureAIAgent(client=client, definition=definition)
|
||||
response = await agent.get_response(
|
||||
"Use Python to compute 42 ** 2 and explain the result.",
|
||||
)
|
||||
print("[SK]", response.message.content)
|
||||
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.create_agent(
|
||||
model=settings.model_deployment_name,
|
||||
name="Analyst",
|
||||
instructions="Use the code interpreter for numeric work.",
|
||||
tools=[{"type": "code_interpreter"}],
|
||||
)
|
||||
agent = AzureAIAgent(client=client, definition=definition)
|
||||
response = await agent.get_response(
|
||||
"Use Python to compute 42 ** 2 and explain the result.",
|
||||
)
|
||||
print("[SK]", response.message.content)
|
||||
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
from azure.identity.aio import AzureCliCredential
|
||||
from agent_framework.azure import AzureAIAgentClient, HostedCodeInterpreterTool
|
||||
from azure.identity.aio import AzureCliCredential
|
||||
|
||||
async with AzureCliCredential() as credential:
|
||||
async with AzureAIAgentClient(async_credential=credential).create_agent(
|
||||
name="Analyst",
|
||||
instructions="Use the code interpreter for numeric work.",
|
||||
tools=[HostedCodeInterpreterTool()],
|
||||
) as agent:
|
||||
# HostedCodeInterpreterTool mirrors the built-in Azure AI capability.
|
||||
reply = await agent.run(
|
||||
"Use Python to compute 42 ** 2 and explain the result.",
|
||||
tool_choice="auto",
|
||||
)
|
||||
print("[AF]", reply.text)
|
||||
async with AzureCliCredential() as credential, AzureAIAgentClient(async_credential=credential).create_agent(
|
||||
name="Analyst",
|
||||
instructions="Use the code interpreter for numeric work.",
|
||||
tools=[HostedCodeInterpreterTool()],
|
||||
) as agent:
|
||||
# HostedCodeInterpreterTool mirrors the built-in Azure AI capability.
|
||||
reply = await agent.run(
|
||||
"Use Python to compute 42 ** 2 and explain the result.",
|
||||
tool_choice="auto",
|
||||
)
|
||||
print("[AF]", reply.text)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
|
||||
+36
-38
@@ -8,53 +8,51 @@ async def run_semantic_kernel() -> None:
|
||||
from azure.identity.aio import AzureCliCredential
|
||||
from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings, AzureAIAgentThread
|
||||
|
||||
async with AzureCliCredential() as credential:
|
||||
async with AzureAIAgent.create_client(credential=credential) as client:
|
||||
settings = AzureAIAgentSettings()
|
||||
definition = await client.agents.create_agent(
|
||||
model=settings.model_deployment_name,
|
||||
name="Planner",
|
||||
instructions="Track follow-up questions within the same thread.",
|
||||
)
|
||||
agent = AzureAIAgent(client=client, definition=definition)
|
||||
async with AzureCliCredential() as credential, AzureAIAgent.create_client(credential=credential) as client:
|
||||
settings = AzureAIAgentSettings()
|
||||
definition = await client.agents.create_agent(
|
||||
model=settings.model_deployment_name,
|
||||
name="Planner",
|
||||
instructions="Track follow-up questions within the same thread.",
|
||||
)
|
||||
agent = AzureAIAgent(client=client, definition=definition)
|
||||
|
||||
thread: AzureAIAgentThread | None = None
|
||||
# SK returns the updated AzureAIAgentThread on each response.
|
||||
first = await agent.get_response("Outline the onboarding checklist.", thread=thread)
|
||||
thread = first.thread
|
||||
print("[SK][turn1]", first.message.content)
|
||||
thread: AzureAIAgentThread | None = None
|
||||
# SK returns the updated AzureAIAgentThread on each response.
|
||||
first = await agent.get_response("Outline the onboarding checklist.", thread=thread)
|
||||
thread = first.thread
|
||||
print("[SK][turn1]", first.message.content)
|
||||
|
||||
second = await agent.get_response(
|
||||
"Highlight the items that require legal review.",
|
||||
thread=thread,
|
||||
)
|
||||
print("[SK][turn2]", second.message.content)
|
||||
if thread is not None:
|
||||
print("[SK][thread-id]", thread.id)
|
||||
second = await agent.get_response(
|
||||
"Highlight the items that require legal review.",
|
||||
thread=thread,
|
||||
)
|
||||
print("[SK][turn2]", second.message.content)
|
||||
if thread is not None:
|
||||
print("[SK][thread-id]", thread.id)
|
||||
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
from azure.identity.aio import AzureCliCredential
|
||||
from agent_framework.azure import AzureAIAgentClient
|
||||
from azure.identity.aio import AzureCliCredential
|
||||
|
||||
async with AzureCliCredential() as credential:
|
||||
async with AzureAIAgentClient(async_credential=credential).create_agent(
|
||||
name="Planner",
|
||||
instructions="Track follow-up questions within the same thread.",
|
||||
) as agent:
|
||||
thread = agent.get_new_thread()
|
||||
# AF threads are explicit and can be serialized for external storage.
|
||||
first = await agent.run("Outline the onboarding checklist.", thread=thread)
|
||||
print("[AF][turn1]", first.text)
|
||||
async with AzureCliCredential() as credential, AzureAIAgentClient(async_credential=credential).create_agent(
|
||||
name="Planner",
|
||||
instructions="Track follow-up questions within the same thread.",
|
||||
) as agent:
|
||||
thread = agent.get_new_thread()
|
||||
# AF threads are explicit and can be serialized for external storage.
|
||||
first = await agent.run("Outline the onboarding checklist.", thread=thread)
|
||||
print("[AF][turn1]", first.text)
|
||||
|
||||
second = await agent.run(
|
||||
"Highlight the items that require legal review.",
|
||||
thread=thread,
|
||||
)
|
||||
print("[AF][turn2]", second.text)
|
||||
second = await agent.run(
|
||||
"Highlight the items that require legal review.",
|
||||
thread=thread,
|
||||
)
|
||||
print("[AF][turn2]", second.text)
|
||||
|
||||
serialized = await thread.serialize()
|
||||
print("[AF][thread-json]", serialized)
|
||||
serialized = await thread.serialize()
|
||||
print("[AF][thread-json]", serialized)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
|
||||
Reference in New Issue
Block a user