Python: OpenAI Assistants Chat Client and Agent (#288)

* Initial version of assistant client

* More updates to assistant client

* Finished assistant chat client implementation

* Small fixes and basic example

* Added code interpreter example

* More examples

* Added chat client example

* Small fixes

* Added tests

* Enabled telemetry

* Small fix

* Removed files temporarily

* Revert "Removed files temporarily"

This reverts commit 5cdfa0d299.

* Small fixes

* Addressed PR feedback

* Fixed tests

* Small update
This commit is contained in:
Dmytro Struk
2025-08-01 05:12:41 -07:00
committed by GitHub
Unverified
parent 624709e5d1
commit 75794b4687
14 changed files with 1338 additions and 78 deletions
@@ -31,7 +31,7 @@ async def non_streaming_example() -> None:
query = "What's the weather like in Seattle?"
print(f"User: {query}")
result = await agent.run(query)
print(f"Result: {result}\n")
print(f"Agent: {result}\n")
async def streaming_example() -> None:
@@ -1,45 +0,0 @@
# Copyright (c) Microsoft. All rights reserved.
import asyncio
import os
from random import randint
from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework.foundry import FoundryChatClient
from azure.ai.projects.aio import AIProjectClient
from azure.identity.aio import AzureCliCredential
from pydantic import Field
def get_weather(
location: Annotated[str, Field(description="The location to get the weather for.")],
) -> str:
"""Get the weather for a given location."""
conditions = ["sunny", "cloudy", "rainy", "stormy"]
return f"The weather in {location} is {conditions[randint(0, 3)]} with a high of {randint(10, 30)}°C."
async def main() -> None:
print("=== Foundry Chat Client with Existing AIProjectClient ===")
# Create the client
client = AIProjectClient(endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], credential=AzureCliCredential())
# Since no Agent ID is provided, the agent will be automatically created
# and deleted after getting a response
async with ChatClientAgent(
chat_client=FoundryChatClient(
client=client,
model_deployment_name=os.environ["FOUNDRY_MODEL_DEPLOYMENT_NAME"],
agent_name="WeatherAgent",
),
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent:
result = await agent.run("What's the weather like in London?")
print(f"Result: {result}\n")
if __name__ == "__main__":
asyncio.run(main())