Skip to content

Commit edb8aed

Browse files
authored
Upgrade agent-framework to latest RC (#50)
* Upgrade to FastMCP 3.0, update get/set state * Ignore logging warnings * Upgrade MAF to latest * RM tavily files, update MAF one * Use try/finally
1 parent eb5cb84 commit edb8aed

7 files changed

Lines changed: 680 additions & 247 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@ This project includes example agents in the [`agents/`](agents/) directory that
202202

203203
| File | Description |
204204
| ---- | ----------- |
205-
| [agents/agentframework_learn.py](agents/agentframework_learn.py) | Microsoft Agent Framework integration with MCP |
206205
| [agents/agentframework_http.py](agents/agentframework_http.py) | Microsoft Agent Framework integration with local Expenses MCP server |
207-
| [agents/langchainv1_http.py](agents/langchainv1_http.py) | LangChain agent with MCP integration |
208-
| [agents/langchainv1_github.py](agents/langchainv1_github.py) | LangChain tool filtering demo with GitHub MCP (requires `GITHUB_TOKEN`) |
206+
| [agents/agentframework_learn.py](agents/agentframework_learn.py) | Microsoft Agent Framework integration with remote Learn MCP server |
207+
| [agents/langchainv1_http.py](agents/langchainv1_http.py) | LangChain agent with local Expenses MCP server |
208+
| [agents/langchainv1_github.py](agents/langchainv1_github.py) | LangChain tool-filtering agent with remote GitHub MCP (requires `GITHUB_TOKEN`) |
209209

210210
**To run an agent:**
211211

agents/agentframework_http.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
import os
44
from datetime import datetime
55

6-
from agent_framework import ChatAgent, MCPStreamableHTTPTool
7-
from agent_framework.azure import AzureOpenAIChatClient
6+
from agent_framework import Agent, MCPStreamableHTTPTool
87
from agent_framework.openai import OpenAIChatClient
9-
from azure.identity import DefaultAzureCredential
8+
from azure.identity.aio import DefaultAzureCredential, get_bearer_token_provider
109
from dotenv import load_dotenv
1110
from rich import print
1211
from rich.logging import RichHandler
@@ -26,19 +25,21 @@
2625

2726
# Configure chat client based on API_HOST
2827
API_HOST = os.getenv("API_HOST", "github")
28+
async_credential = None
2929

3030
if API_HOST == "azure":
31-
client = AzureOpenAIChatClient(
32-
credential=DefaultAzureCredential(),
33-
deployment_name=os.environ.get("AZURE_OPENAI_CHAT_DEPLOYMENT"),
34-
endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT"),
35-
api_version=os.environ.get("AZURE_OPENAI_VERSION"),
31+
async_credential = DefaultAzureCredential()
32+
token_provider = get_bearer_token_provider(async_credential, "https://cognitiveservices.azure.com/.default")
33+
client = OpenAIChatClient(
34+
base_url=f"{os.environ['AZURE_OPENAI_ENDPOINT']}/openai/v1/",
35+
api_key=token_provider,
36+
model_id=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT"],
3637
)
3738
elif API_HOST == "github":
3839
client = OpenAIChatClient(
3940
base_url="https://models.github.ai/inference",
4041
api_key=os.environ["GITHUB_TOKEN"],
41-
model_id=os.getenv("GITHUB_MODEL", "openai/gpt-4o"),
42+
model_id=os.getenv("GITHUB_MODEL", "openai/gpt-4.1-mini"),
4243
)
4344
elif API_HOST == "ollama":
4445
client = OpenAIChatClient(
@@ -48,28 +49,34 @@
4849
)
4950
else:
5051
client = OpenAIChatClient(
51-
api_key=os.environ.get("OPENAI_API_KEY"), model_id=os.environ.get("OPENAI_MODEL", "gpt-4o")
52+
api_key=os.environ.get("OPENAI_API_KEY"), model_id=os.environ.get("OPENAI_MODEL", "gpt-4.1-mini")
5253
)
5354

5455

5556
# --- Main Agent Logic ---
5657
async def http_mcp_example() -> None:
57-
async with (
58-
MCPStreamableHTTPTool(name="Expenses MCP Server", url=MCP_SERVER_URL) as mcp_server,
59-
ChatAgent(
60-
chat_client=client,
61-
name="Expenses Agent",
62-
instructions=f"You help users to log expenses. Today's date is {datetime.now().strftime('%Y-%m-%d')}.",
63-
) as agent,
64-
):
65-
user_query = "yesterday I bought a laptop for $1200 using my visa."
66-
result = await agent.run(user_query, tools=mcp_server)
67-
print(result)
58+
"""Run an agent connected to the local expenses MCP server."""
59+
try:
60+
async with (
61+
MCPStreamableHTTPTool(name="Expenses MCP Server", url=MCP_SERVER_URL) as mcp_server,
62+
Agent(
63+
client=client,
64+
name="Expenses Agent",
65+
instructions=f"You help users to log expenses. Today's date is {datetime.now().strftime('%Y-%m-%d')}.",
66+
tools=[mcp_server],
67+
) as agent,
68+
):
69+
user_query = "yesterday I bought a laptop for $1200 using my visa."
70+
result = await agent.run(user_query)
71+
print(result.text)
6872

69-
# Keep the worker alive in production
70-
while RUNNING_IN_PRODUCTION:
71-
await asyncio.sleep(60)
72-
logger.info("Worker still running...")
73+
# Keep the worker alive in production
74+
while RUNNING_IN_PRODUCTION:
75+
await asyncio.sleep(60)
76+
logger.info("Worker still running...")
77+
finally:
78+
if async_credential:
79+
await async_credential.close()
7380

7481

7582
if __name__ == "__main__":

agents/agentframework_learn.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
import logging
33
import os
44

5-
from agent_framework import ChatAgent, MCPStreamableHTTPTool
6-
from agent_framework.azure import AzureOpenAIChatClient
5+
from agent_framework import Agent, MCPStreamableHTTPTool
76
from agent_framework.openai import OpenAIChatClient
8-
from azure.identity import DefaultAzureCredential
7+
from azure.identity.aio import DefaultAzureCredential, get_bearer_token_provider
98
from dotenv import load_dotenv
109
from rich import print
1110
from rich.logging import RichHandler
@@ -20,18 +19,20 @@
2019

2120
# Configure chat client based on API_HOST
2221
API_HOST = os.getenv("API_HOST", "github")
22+
async_credential = None
2323
if API_HOST == "azure":
24-
client = AzureOpenAIChatClient(
25-
credential=DefaultAzureCredential(),
26-
deployment_name=os.environ.get("AZURE_OPENAI_CHAT_DEPLOYMENT"),
27-
endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT"),
28-
api_version=os.environ.get("AZURE_OPENAI_VERSION"),
24+
async_credential = DefaultAzureCredential()
25+
token_provider = get_bearer_token_provider(async_credential, "https://cognitiveservices.azure.com/.default")
26+
client = OpenAIChatClient(
27+
base_url=f"{os.environ['AZURE_OPENAI_ENDPOINT']}/openai/v1/",
28+
api_key=token_provider,
29+
model_id=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT"],
2930
)
3031
elif API_HOST == "github":
3132
client = OpenAIChatClient(
3233
base_url="https://models.github.ai/inference",
3334
api_key=os.environ["GITHUB_TOKEN"],
34-
model_id=os.getenv("GITHUB_MODEL", "openai/gpt-4o"),
35+
model_id=os.getenv("GITHUB_MODEL", "openai/gpt-4.1-mini"),
3536
)
3637
elif API_HOST == "ollama":
3738
client = OpenAIChatClient(
@@ -41,26 +42,33 @@
4142
)
4243
else:
4344
client = OpenAIChatClient(
44-
api_key=os.environ.get("OPENAI_API_KEY"), model_id=os.environ.get("OPENAI_MODEL", "gpt-4o")
45+
api_key=os.environ.get("OPENAI_API_KEY"), model_id=os.environ.get("OPENAI_MODEL", "gpt-4.1-mini")
4546
)
4647

4748

48-
async def http_mcp_example():
49+
async def http_mcp_example() -> None:
4950
"""
5051
Creates an agent that can answer questions about Microsoft documentation
5152
using the Microsoft Learn MCP server.
5253
"""
53-
async with (
54-
MCPStreamableHTTPTool(name="Microsoft Learn MCP", url="https://learn.microsoft.com/api/mcp") as mcp_server,
55-
ChatAgent(
56-
chat_client=client,
57-
name="DocsAgent",
58-
instructions="You help with Microsoft documentation questions.",
59-
) as agent,
60-
):
61-
query = "How to create an Azure storage account using az cli?"
62-
result = await agent.run(query, tools=mcp_server)
63-
print(result)
54+
55+
try:
56+
async with (
57+
MCPStreamableHTTPTool(name="Microsoft Learn MCP", url="https://learn.microsoft.com/api/mcp") as mcp_server,
58+
Agent(
59+
client=client,
60+
name="DocsAgent",
61+
instructions="You help with Microsoft documentation questions.",
62+
tools=[mcp_server],
63+
) as agent,
64+
):
65+
query = "How to create an Azure storage account using az cli?"
66+
result = await agent.run(query)
67+
print(result.text)
68+
69+
finally:
70+
if async_credential:
71+
await async_credential.close()
6472

6573

6674
if __name__ == "__main__":

agents/agentframework_tavily.py

Lines changed: 0 additions & 69 deletions
This file was deleted.

agents/langchainv1_tavily.py

Lines changed: 0 additions & 84 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies = [
1616
"langchain-openai>=1.0.1",
1717
"langchain-mcp-adapters>=0.1.11",
1818
"azure-ai-agents>=1.1.0",
19-
"agent-framework>=1.0.0b251016",
19+
"agent-framework>=1.0.0rc5",
2020
"azure-cosmos>=4.9.0",
2121
"azure-monitor-opentelemetry>=1.8.3",
2222
"opentelemetry-instrumentation-starlette>=0.60b0",

0 commit comments

Comments
 (0)