mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Renamed async_credential to credential (#2648)
This commit is contained in:
committed by
GitHub
Unverified
parent
eb06faea2d
commit
cfcb71334a
@@ -33,7 +33,7 @@ async def non_streaming_example() -> None:
|
||||
# authentication option.
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="BasicWeatherAgent",
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
@@ -54,7 +54,7 @@ async def streaming_example() -> None:
|
||||
# authentication option.
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="BasicWeatherAgent",
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
|
||||
@@ -31,7 +31,7 @@ async def main() -> None:
|
||||
async with AzureCliCredential() as credential:
|
||||
async with (
|
||||
AzureAIClient(
|
||||
async_credential=credential,
|
||||
credential=credential,
|
||||
).create_agent(
|
||||
name="MyWeatherAgent",
|
||||
instructions="You are a helpful weather agent.",
|
||||
@@ -47,7 +47,7 @@ async def main() -> None:
|
||||
# Create a new agent instance
|
||||
async with (
|
||||
AzureAIClient(
|
||||
async_credential=credential,
|
||||
credential=credential,
|
||||
# This parameter will allow to re-use latest agent version
|
||||
# instead of creating a new one
|
||||
use_latest_version=True,
|
||||
|
||||
@@ -21,7 +21,7 @@ Prerequisites:
|
||||
async def main() -> None:
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="MyA2AAgent",
|
||||
instructions="""You are a helpful assistant that can communicate with other agents.
|
||||
Use the A2A tool when you need to interact with other agents to complete tasks
|
||||
|
||||
@@ -21,7 +21,7 @@ Prerequisites:
|
||||
async def main() -> None:
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="MySearchAgent",
|
||||
instructions="""You are a helpful assistant. You must always provide citations for
|
||||
answers using the tool and render them as: `[message_idx:search_idx†source]`.""",
|
||||
|
||||
@@ -21,7 +21,7 @@ Prerequisites:
|
||||
async def main() -> None:
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="MyCustomSearchAgent",
|
||||
instructions="""You are a helpful agent that can use Bing Custom Search tools to assist users.
|
||||
Use the available Bing Custom Search tools to answer questions and perform tasks.""",
|
||||
|
||||
@@ -27,7 +27,7 @@ To get your Bing connection ID:
|
||||
async def main() -> None:
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="MyBingGroundingAgent",
|
||||
instructions="""You are a helpful assistant that can search the web for current information.
|
||||
Use the Bing search tool to find up-to-date information and provide accurate, well-sourced answers.
|
||||
|
||||
@@ -21,7 +21,7 @@ Prerequisites:
|
||||
async def main() -> None:
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="MyBrowserAutomationAgent",
|
||||
instructions="""You are an Agent helping with browser automation tasks.
|
||||
You can answer questions, provide information, and assist with various tasks
|
||||
|
||||
@@ -21,7 +21,7 @@ async def main() -> None:
|
||||
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="MyCodeInterpreterAgent",
|
||||
instructions="You are a helpful assistant that can write and execute Python code to solve problems.",
|
||||
tools=HostedCodeInterpreterTool(),
|
||||
|
||||
@@ -36,7 +36,7 @@ async def main() -> None:
|
||||
chat_client=AzureAIClient(
|
||||
project_endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
|
||||
model_deployment_name=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
|
||||
async_credential=credential,
|
||||
credential=credential,
|
||||
agent_name="WeatherAgent",
|
||||
),
|
||||
instructions="You are a helpful weather agent.",
|
||||
|
||||
@@ -32,7 +32,7 @@ async def main() -> None:
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AgentsClient(endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"], credential=credential) as agents_client,
|
||||
AzureAIClient(async_credential=credential) as client,
|
||||
AzureAIClient(credential=credential) as client,
|
||||
):
|
||||
try:
|
||||
# 1. Upload file and create vector store
|
||||
|
||||
@@ -64,7 +64,7 @@ async def run_hosted_mcp_without_approval() -> None:
|
||||
# authentication option.
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="MyLearnDocsAgent",
|
||||
instructions="You are a helpful assistant that can help with Microsoft documentation questions.",
|
||||
tools=HostedMCPTool(
|
||||
@@ -89,7 +89,7 @@ async def run_hosted_mcp_with_approval_and_thread() -> None:
|
||||
# authentication option.
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="MyApiSpecsAgent",
|
||||
instructions="You are a helpful agent that can use MCP tools to assist users.",
|
||||
tools=HostedMCPTool(
|
||||
|
||||
@@ -27,7 +27,7 @@ async def main() -> None:
|
||||
# authentication option.
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="ImageGenAgent",
|
||||
instructions="Generate images based on user requirements.",
|
||||
tools=[ImageGenTool(quality="low", size="1024x1024")],
|
||||
|
||||
@@ -24,7 +24,7 @@ async def main() -> None:
|
||||
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="DocsAgent",
|
||||
instructions="You are a helpful assistant that can help with Microsoft documentation questions.",
|
||||
tools=MCPStreamableHTTPTool(
|
||||
|
||||
@@ -47,7 +47,7 @@ async def main() -> None:
|
||||
print(f"Created memory store: {memory_store.name} ({memory_store.id}): {memory_store.description}")
|
||||
|
||||
# Then, create the agent using Agent Framework
|
||||
async with AzureAIClient(async_credential=credential).create_agent(
|
||||
async with AzureAIClient(credential=credential).create_agent(
|
||||
name="MyMemoryAgent",
|
||||
instructions="""You are a helpful assistant that remembers past conversations.
|
||||
Use the memory search tool to recall relevant information from previous interactions.""",
|
||||
|
||||
@@ -21,7 +21,7 @@ Prerequisites:
|
||||
async def main() -> None:
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="MyFabricAgent",
|
||||
instructions="You are a helpful assistant.",
|
||||
tools={
|
||||
|
||||
@@ -29,7 +29,7 @@ async def main() -> None:
|
||||
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="MyOpenAPIAgent",
|
||||
instructions="""You are a helpful assistant that can use country APIs to provide information.
|
||||
Use the available OpenAPI tools to answer questions about countries, currencies, and demographics.""",
|
||||
|
||||
@@ -29,7 +29,7 @@ async def main() -> None:
|
||||
# authentication option.
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="ProductMarketerAgent",
|
||||
instructions="Return launch briefs as structured JSON.",
|
||||
) as agent,
|
||||
|
||||
@@ -36,7 +36,7 @@ async def main() -> None:
|
||||
# authentication option.
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="ProductMarketerAgent",
|
||||
instructions="Return launch briefs as structured JSON.",
|
||||
) as agent,
|
||||
|
||||
@@ -21,7 +21,7 @@ Prerequisites:
|
||||
async def main() -> None:
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="MySharePointAgent",
|
||||
instructions="""You are a helpful agent that can use SharePoint tools to assist users.
|
||||
Use the available SharePoint tools to answer questions and perform tasks.""",
|
||||
|
||||
@@ -30,7 +30,7 @@ async def example_with_automatic_thread_creation() -> None:
|
||||
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="BasicWeatherAgent",
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
@@ -59,7 +59,7 @@ async def example_with_thread_persistence_in_memory() -> None:
|
||||
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="BasicWeatherAgent",
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
@@ -100,7 +100,7 @@ async def example_with_existing_thread_id() -> None:
|
||||
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="BasicWeatherAgent",
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
@@ -122,7 +122,7 @@ async def example_with_existing_thread_id() -> None:
|
||||
print("\n--- Continuing with the same thread ID in a new agent instance ---")
|
||||
|
||||
async with (
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="BasicWeatherAgent",
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
|
||||
@@ -24,7 +24,7 @@ async def main() -> None:
|
||||
# authentication option.
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIClient(async_credential=credential).create_agent(
|
||||
AzureAIClient(credential=credential).create_agent(
|
||||
name="WebsearchAgent",
|
||||
instructions="You are a helpful assistant that can search the web",
|
||||
tools=[HostedWebSearchTool()],
|
||||
|
||||
@@ -34,7 +34,7 @@ async def non_streaming_example() -> None:
|
||||
# authentication option.
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIAgentClient(async_credential=credential).create_agent(
|
||||
AzureAIAgentClient(credential=credential).create_agent(
|
||||
name="WeatherAgent",
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
@@ -56,7 +56,7 @@ async def streaming_example() -> None:
|
||||
# authentication option.
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIAgentClient(async_credential=credential).create_agent(
|
||||
AzureAIAgentClient(credential=credential).create_agent(
|
||||
name="WeatherAgent",
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ async def main() -> None:
|
||||
|
||||
# 2. Use AzureAIAgentClient as async context manager for automatic cleanup
|
||||
async with (
|
||||
AzureAIAgentClient(async_credential=AzureCliCredential()) as client,
|
||||
AzureAIAgentClient(credential=AzureCliCredential()) as client,
|
||||
ChatAgent(
|
||||
chat_client=client,
|
||||
name="BingSearchAgent",
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ async def main() -> None:
|
||||
|
||||
# 2. Use AzureAIAgentClient as async context manager for automatic cleanup
|
||||
async with (
|
||||
AzureAIAgentClient(async_credential=AzureCliCredential()) as client,
|
||||
AzureAIAgentClient(credential=AzureCliCredential()) as client,
|
||||
ChatAgent(
|
||||
chat_client=client,
|
||||
name="BingSearchAgent",
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ async def main() -> None:
|
||||
# authentication option.
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIAgentClient(async_credential=credential) as chat_client,
|
||||
AzureAIAgentClient(credential=credential) as chat_client,
|
||||
):
|
||||
agent = chat_client.create_agent(
|
||||
name="CodingAgent",
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ async def main() -> None:
|
||||
chat_client=AzureAIAgentClient(
|
||||
project_endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
|
||||
model_deployment_name=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
|
||||
async_credential=credential,
|
||||
credential=credential,
|
||||
agent_name="WeatherAgent",
|
||||
should_cleanup_agent=True, # Set to False if you want to disable automatic agent cleanup
|
||||
),
|
||||
|
||||
@@ -24,7 +24,7 @@ USER_INPUTS = [
|
||||
|
||||
async def main() -> None:
|
||||
"""Main function demonstrating Azure AI agent with file search capabilities."""
|
||||
client = AzureAIAgentClient(async_credential=AzureCliCredential())
|
||||
client = AzureAIAgentClient(credential=AzureCliCredential())
|
||||
file: FileInfo | None = None
|
||||
vector_store: VectorStore | None = None
|
||||
|
||||
@@ -74,7 +74,7 @@ async def main() -> None:
|
||||
# 6. Cleanup: Delete the vector store and file in case of earlier failure to prevent orphaned resources.
|
||||
|
||||
# Refreshing the client is required since chat agent closes it
|
||||
client = AzureAIAgentClient(async_credential=AzureCliCredential())
|
||||
client = AzureAIAgentClient(credential=AzureCliCredential())
|
||||
try:
|
||||
if vector_store:
|
||||
await client.agents_client.vector_stores.delete(vector_store.id)
|
||||
|
||||
+3
-3
@@ -43,7 +43,7 @@ async def tools_on_agent_level() -> None:
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
ChatAgent(
|
||||
chat_client=AzureAIAgentClient(async_credential=credential),
|
||||
chat_client=AzureAIAgentClient(credential=credential),
|
||||
instructions="You are a helpful assistant that can provide weather and time information.",
|
||||
tools=[get_weather, get_time], # Tools defined at agent creation
|
||||
) as agent,
|
||||
@@ -77,7 +77,7 @@ async def tools_on_run_level() -> None:
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
ChatAgent(
|
||||
chat_client=AzureAIAgentClient(async_credential=credential),
|
||||
chat_client=AzureAIAgentClient(credential=credential),
|
||||
instructions="You are a helpful assistant.",
|
||||
# No tools defined here
|
||||
) as agent,
|
||||
@@ -111,7 +111,7 @@ async def mixed_tools_example() -> None:
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
ChatAgent(
|
||||
chat_client=AzureAIAgentClient(async_credential=credential),
|
||||
chat_client=AzureAIAgentClient(credential=credential),
|
||||
instructions="You are a comprehensive assistant that can help with various information requests.",
|
||||
tools=[get_weather], # Base tool available for all queries
|
||||
) as agent,
|
||||
|
||||
@@ -42,7 +42,7 @@ async def main() -> None:
|
||||
"""Example showing Hosted MCP tools for a Azure AI Agent."""
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIAgentClient(async_credential=credential) as chat_client,
|
||||
AzureAIAgentClient(credential=credential) as chat_client,
|
||||
):
|
||||
agent = chat_client.create_agent(
|
||||
name="DocsAgent",
|
||||
|
||||
@@ -28,7 +28,7 @@ async def mcp_tools_on_run_level() -> None:
|
||||
url="https://learn.microsoft.com/api/mcp",
|
||||
) as mcp_server,
|
||||
ChatAgent(
|
||||
chat_client=AzureAIAgentClient(async_credential=credential),
|
||||
chat_client=AzureAIAgentClient(credential=credential),
|
||||
name="DocsAgent",
|
||||
instructions="You are a helpful assistant that can help with microsoft documentation questions.",
|
||||
) as agent,
|
||||
@@ -55,7 +55,7 @@ async def mcp_tools_on_agent_level() -> None:
|
||||
# The agent will connect to the MCP server through its context manager.
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIAgentClient(async_credential=credential).create_agent(
|
||||
AzureAIAgentClient(credential=credential).create_agent(
|
||||
name="DocsAgent",
|
||||
instructions="You are a helpful assistant that can help with microsoft documentation questions.",
|
||||
tools=MCPStreamableHTTPTool( # Tools defined at agent creation
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ async def main() -> None:
|
||||
"""Example showing Hosted MCP tools for a Azure AI Agent."""
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIAgentClient(async_credential=credential) as chat_client,
|
||||
AzureAIAgentClient(credential=credential) as chat_client,
|
||||
):
|
||||
agent = chat_client.create_agent(
|
||||
name="DocsAgent",
|
||||
|
||||
@@ -41,7 +41,7 @@ async def main() -> None:
|
||||
weather_openapi_spec, countries_openapi_spec = load_openapi_specs()
|
||||
|
||||
# 2. Use AzureAIAgentClient as async context manager for automatic cleanup
|
||||
async with AzureAIAgentClient(async_credential=AzureCliCredential()) as client:
|
||||
async with AzureAIAgentClient(credential=AzureCliCredential()) as client:
|
||||
# 3. Create OpenAPI tools using Azure AI's OpenApiTool
|
||||
auth = OpenApiAnonymousAuthDetails()
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ async def example_with_automatic_thread_creation() -> None:
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
ChatAgent(
|
||||
chat_client=AzureAIAgentClient(async_credential=credential),
|
||||
chat_client=AzureAIAgentClient(credential=credential),
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
) as agent,
|
||||
@@ -63,7 +63,7 @@ async def example_with_thread_persistence() -> None:
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
ChatAgent(
|
||||
chat_client=AzureAIAgentClient(async_credential=credential),
|
||||
chat_client=AzureAIAgentClient(credential=credential),
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
) as agent,
|
||||
@@ -104,7 +104,7 @@ async def example_with_existing_thread_id() -> None:
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
ChatAgent(
|
||||
chat_client=AzureAIAgentClient(async_credential=credential),
|
||||
chat_client=AzureAIAgentClient(credential=credential),
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
) as agent,
|
||||
@@ -127,7 +127,7 @@ async def example_with_existing_thread_id() -> None:
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
ChatAgent(
|
||||
chat_client=AzureAIAgentClient(thread_id=existing_thread_id, async_credential=credential),
|
||||
chat_client=AzureAIAgentClient(thread_id=existing_thread_id, credential=credential),
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
) as agent,
|
||||
|
||||
Reference in New Issue
Block a user