Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ This project includes example agents in the [`agents/`](agents/) directory that

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

**To run an agent:**

Expand Down
57 changes: 32 additions & 25 deletions agents/agentframework_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import os
from datetime import datetime

from agent_framework import ChatAgent, MCPStreamableHTTPTool
from agent_framework.azure import AzureOpenAIChatClient
from agent_framework import Agent, MCPStreamableHTTPTool
from agent_framework.openai import OpenAIChatClient
from azure.identity import DefaultAzureCredential
from azure.identity.aio import DefaultAzureCredential, get_bearer_token_provider
from dotenv import load_dotenv
from rich import print
from rich.logging import RichHandler
Expand All @@ -26,19 +25,21 @@

# Configure chat client based on API_HOST
API_HOST = os.getenv("API_HOST", "github")
async_credential = None

if API_HOST == "azure":
client = AzureOpenAIChatClient(
credential=DefaultAzureCredential(),
deployment_name=os.environ.get("AZURE_OPENAI_CHAT_DEPLOYMENT"),
endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT"),
api_version=os.environ.get("AZURE_OPENAI_VERSION"),
async_credential = DefaultAzureCredential()
token_provider = get_bearer_token_provider(async_credential, "https://cognitiveservices.azure.com/.default")
client = OpenAIChatClient(
base_url=f"{os.environ['AZURE_OPENAI_ENDPOINT']}/openai/v1/",
Comment on lines +33 to +34
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AZURE_OPENAI_ENDPOINT in .env-sample ends with a trailing slash, so building base_url as f"{os.environ['AZURE_OPENAI_ENDPOINT']}/openai/v1/" produces a double-slash (...azure.com//openai/v1/). This can break request routing in some HTTP stacks. Consider normalizing the endpoint first (e.g., rstrip('/')) before appending the path.

Suggested change
client = OpenAIChatClient(
base_url=f"{os.environ['AZURE_OPENAI_ENDPOINT']}/openai/v1/",
azure_endpoint = os.environ["AZURE_OPENAI_ENDPOINT"].rstrip("/")
client = OpenAIChatClient(
base_url=f"{azure_endpoint}/openai/v1/",

Copilot uses AI. Check for mistakes.
api_key=token_provider,
model_id=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT"],
)
elif API_HOST == "github":
client = OpenAIChatClient(
base_url="https://models.github.ai/inference",
api_key=os.environ["GITHUB_TOKEN"],
model_id=os.getenv("GITHUB_MODEL", "openai/gpt-4o"),
model_id=os.getenv("GITHUB_MODEL", "openai/gpt-4.1-mini"),
)
elif API_HOST == "ollama":
client = OpenAIChatClient(
Expand All @@ -48,28 +49,34 @@
)
else:
client = OpenAIChatClient(
api_key=os.environ.get("OPENAI_API_KEY"), model_id=os.environ.get("OPENAI_MODEL", "gpt-4o")
api_key=os.environ.get("OPENAI_API_KEY"), model_id=os.environ.get("OPENAI_MODEL", "gpt-4.1-mini")
)


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

# Keep the worker alive in production
while RUNNING_IN_PRODUCTION:
await asyncio.sleep(60)
logger.info("Worker still running...")
# Keep the worker alive in production
while RUNNING_IN_PRODUCTION:
await asyncio.sleep(60)
logger.info("Worker still running...")
finally:
if async_credential:
await async_credential.close()


if __name__ == "__main__":
Expand Down
52 changes: 30 additions & 22 deletions agents/agentframework_learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import logging
import os

from agent_framework import ChatAgent, MCPStreamableHTTPTool
from agent_framework.azure import AzureOpenAIChatClient
from agent_framework import Agent, MCPStreamableHTTPTool
from agent_framework.openai import OpenAIChatClient
from azure.identity import DefaultAzureCredential
from azure.identity.aio import DefaultAzureCredential, get_bearer_token_provider
from dotenv import load_dotenv
from rich import print
from rich.logging import RichHandler
Expand All @@ -20,18 +19,20 @@

# Configure chat client based on API_HOST
API_HOST = os.getenv("API_HOST", "github")
async_credential = None
if API_HOST == "azure":
client = AzureOpenAIChatClient(
credential=DefaultAzureCredential(),
deployment_name=os.environ.get("AZURE_OPENAI_CHAT_DEPLOYMENT"),
endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT"),
api_version=os.environ.get("AZURE_OPENAI_VERSION"),
async_credential = DefaultAzureCredential()
token_provider = get_bearer_token_provider(async_credential, "https://cognitiveservices.azure.com/.default")
client = OpenAIChatClient(
base_url=f"{os.environ['AZURE_OPENAI_ENDPOINT']}/openai/v1/",
Comment on lines +26 to +27
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AZURE_OPENAI_ENDPOINT in .env-sample includes a trailing slash, so base_url=f"{os.environ['AZURE_OPENAI_ENDPOINT']}/openai/v1/" will end up with //openai/v1/. Consider stripping any trailing / from the endpoint before appending /openai/v1/.

Suggested change
client = OpenAIChatClient(
base_url=f"{os.environ['AZURE_OPENAI_ENDPOINT']}/openai/v1/",
azure_endpoint = os.environ["AZURE_OPENAI_ENDPOINT"].rstrip("/")
client = OpenAIChatClient(
base_url=f"{azure_endpoint}/openai/v1/",

Copilot uses AI. Check for mistakes.
api_key=token_provider,
model_id=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT"],
)
elif API_HOST == "github":
client = OpenAIChatClient(
base_url="https://models.github.ai/inference",
api_key=os.environ["GITHUB_TOKEN"],
model_id=os.getenv("GITHUB_MODEL", "openai/gpt-4o"),
model_id=os.getenv("GITHUB_MODEL", "openai/gpt-4.1-mini"),
)
elif API_HOST == "ollama":
client = OpenAIChatClient(
Expand All @@ -41,26 +42,33 @@
)
else:
client = OpenAIChatClient(
api_key=os.environ.get("OPENAI_API_KEY"), model_id=os.environ.get("OPENAI_MODEL", "gpt-4o")
api_key=os.environ.get("OPENAI_API_KEY"), model_id=os.environ.get("OPENAI_MODEL", "gpt-4.1-mini")
)


async def http_mcp_example():
async def http_mcp_example() -> None:
"""
Creates an agent that can answer questions about Microsoft documentation
using the Microsoft Learn MCP server.
"""
async with (
MCPStreamableHTTPTool(name="Microsoft Learn MCP", url="https://learn.microsoft.com/api/mcp") as mcp_server,
ChatAgent(
chat_client=client,
name="DocsAgent",
instructions="You help with Microsoft documentation questions.",
) as agent,
):
query = "How to create an Azure storage account using az cli?"
result = await agent.run(query, tools=mcp_server)
print(result)

try:
async with (
MCPStreamableHTTPTool(name="Microsoft Learn MCP", url="https://learn.microsoft.com/api/mcp") as mcp_server,
Agent(
client=client,
name="DocsAgent",
instructions="You help with Microsoft documentation questions.",
tools=[mcp_server],
) as agent,
):
query = "How to create an Azure storage account using az cli?"
result = await agent.run(query)
print(result.text)

finally:
if async_credential:
await async_credential.close()


if __name__ == "__main__":
Expand Down
69 changes: 0 additions & 69 deletions agents/agentframework_tavily.py

This file was deleted.

84 changes: 0 additions & 84 deletions agents/langchainv1_tavily.py

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies = [
"langchain-openai>=1.0.1",
"langchain-mcp-adapters>=0.1.11",
"azure-ai-agents>=1.1.0",
"agent-framework>=1.0.0b251016",
"agent-framework>=1.0.0rc5",
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on the agent-framework meta-package now pulls in agent-framework-core[all] (see uv.lock), which brings a large set of optional integrations and heavy transitive deps (e.g., pythonnet, durabletask, etc.). If these examples only need the core OpenAI client + MCP tool support, consider depending on agent-framework-core (or a smaller extra set) instead to keep installs lighter and reduce platform-specific dependency risk.

Suggested change
"agent-framework>=1.0.0rc5",
"agent-framework-core>=1.0.0rc5",

Copilot uses AI. Check for mistakes.
"azure-cosmos>=4.9.0",
"azure-monitor-opentelemetry>=1.8.3",
"opentelemetry-instrumentation-starlette>=0.60b0",
Expand Down
Loading
Loading