mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: Added Copilot Studio Agent (#722)
* Small fix in dotnet conformance tests * Added CopilotStudioAgent implementation * Added examples * Updated package README * Small fixes * Small improvements * Fixed dotnet tests * Add unit tests * Updated tests * Small updates * Small test fixes * Revert "Small test fixes" This reverts commit983ac44a70. * Small fixes in documentation * Updated test configuration * Revert "Updated test configuration" This reverts commit2a16fea815. * Small fix * Reverted TODO item * Small suppressions * More fixes * Small fixes * Fixed tests * Removed disallow_any_unimported rule in all packages * Fixes
This commit is contained in:
committed by
GitHub
Unverified
parent
74879489a4
commit
e7cd03b32e
@@ -0,0 +1,47 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
import asyncio
|
||||
|
||||
from agent_framework.copilotstudio import CopilotStudioAgent
|
||||
|
||||
# Environment variables needed:
|
||||
# COPILOTSTUDIOAGENT__ENVIRONMENTID - Environment ID where your copilot is deployed
|
||||
# COPILOTSTUDIOAGENT__SCHEMANAME - Agent identifier/schema name of your copilot
|
||||
# COPILOTSTUDIOAGENT__AGENTAPPID - Client ID for authentication
|
||||
# COPILOTSTUDIOAGENT__TENANTID - Tenant ID for authentication
|
||||
|
||||
|
||||
async def non_streaming_example() -> None:
|
||||
"""Example of non-streaming response (get the complete result at once)."""
|
||||
print("=== Non-streaming Response Example ===")
|
||||
|
||||
agent = CopilotStudioAgent()
|
||||
|
||||
query = "What is the capital of France?"
|
||||
print(f"User: {query}")
|
||||
result = await agent.run(query)
|
||||
print(f"Agent: {result}\n")
|
||||
|
||||
|
||||
async def streaming_example() -> None:
|
||||
"""Example of streaming response (get results as they are generated)."""
|
||||
print("=== Streaming Response Example ===")
|
||||
|
||||
agent = CopilotStudioAgent()
|
||||
|
||||
query = "What is the capital of Spain?"
|
||||
print(f"User: {query}")
|
||||
print("Agent: ", end="", flush=True)
|
||||
async for chunk in agent.run_stream(query):
|
||||
if chunk.text:
|
||||
print(chunk.text, end="", flush=True)
|
||||
print("\n")
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
await non_streaming_example()
|
||||
await streaming_example()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user