mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
ce8b6305d8
* Python: Wrapper + Samples 1st (#5177) * Experiment * Update dependency and add non streaming * Add more samples * Rename samples * Add invocations * Comments 1 * Comments 2 * Comments 3 * Improve README * Add local shell sample * WIP: Add eval and memory samples * Update user agent prefix * Update user agent prefix doc * Update dependency (#5215) * Add tests and more content types (#5235) * Add tests * fix tests and sample * Fix formatting * Remove function approval contents * Python: Refine samples and upgrade packages (#5261) * Refine samples and upgrade pacakges * Upgrade to a new package that fixes a bug * Update model env var * Move samples (#5281) * Python: Upgrade agentserver packages (#5284) * Upgrade agentserver packages * Fix new types * Python: Add special handling for workflows (#5298) * Add special handling for workflows * Address comments * Improve samples (#5372) * Python: Add more types (#5378) * Add more type supports * Upgrade packages * Remove TODOs in README * Fix README * Comments and mypy * User agent scoped * Fix README * Fix pre commit * Fix pre commit 2 * Fix pre commit 3 * Fix pre commit 4 * Fix pre commit 5 * Fix pre commit 6 * Add azure-monitor-opentelemetry to dev deps Fixes Samples & Markdown CI failure. The PR's new transitive dep on azure-monitor-opentelemetry-exporter (via azure-ai-agentserver-core) makes pyright resolve the azure.monitor.opentelemetry namespace, flipping the check_md_code_blocks diagnostic for `configure_azure_monitor` from reportMissingImports (filtered) to reportAttributeAccessIssue (not filtered). Installing the umbrella azure-monitor-opentelemetry package in dev makes pyright resolve the symbol correctly, matching the install guidance the observability README already gives users. --------- Co-authored-by: Evan Mattson <evan.mattson@microsoft.com>
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
import asyncio
|
|
|
|
from agent_framework import Agent, AgentResponse, AgentResponseUpdate, ResponseStream
|
|
from agent_framework.openai import OpenAIChatClient
|
|
from typing_extensions import Any
|
|
|
|
"""
|
|
This script demonstrates how to talk to a deployed agent using the OpenAIChatClient.
|
|
|
|
Depending on where you have deployed your agent (local or Foundry Hosting), you may
|
|
need to change the base_url when initializing the OpenAIChatClient.
|
|
"""
|
|
|
|
|
|
async def print_streaming_response(streaming_response: ResponseStream[AgentResponseUpdate, AgentResponse[Any]]) -> None:
|
|
async for chunk in streaming_response:
|
|
if chunk.text:
|
|
print(chunk.text, end="", flush=True)
|
|
|
|
|
|
async def main() -> None:
|
|
agent = Agent(client=OpenAIChatClient(base_url="http://localhost:8088"))
|
|
session = agent.create_session()
|
|
|
|
# First turn
|
|
query = "Hi!"
|
|
print(f"User: {query}")
|
|
print("Agent: ", end="", flush=True)
|
|
streaming_response = agent.run(query, session=session, stream=True)
|
|
await print_streaming_response(streaming_response)
|
|
|
|
# Second turn
|
|
query = "Your name is Javis. What can you do?"
|
|
print(f"\nUser: {query}")
|
|
print("Agent: ", end="", flush=True)
|
|
streaming_response = agent.run(query, session=session, stream=True)
|
|
await print_streaming_response(streaming_response)
|
|
|
|
# Third turn
|
|
query = "What is your name?"
|
|
print(f"\nUser: {query}")
|
|
print("Agent: ", end="", flush=True)
|
|
streaming_response = agent.run(query, session=session, stream=True)
|
|
await print_streaming_response(streaming_response)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|