Skip to content

Commit da056ce

Browse files
committed
Improve logging for agent-framework
2 parents 45147b5 + 3a0c9ce commit da056ce

33 files changed

+765
-569
lines changed

.github/workflows/azure-dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
uses: Azure/[email protected]
4141

4242
- name: Install Nodejs
43-
uses: actions/setup-node@v5
43+
uses: actions/setup-node@v6
4444
with:
4545
node-version: 18
4646

.github/workflows/template-validation.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@v5
1717

18-
- uses: microsoft/[email protected].3
18+
- uses: microsoft/[email protected].4
1919
env:
2020
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
2121
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ This project includes infrastructure as code (IaC) to provision Azure OpenAI dep
197197
198198
## Resources
199199
200-
* [AutoGen Documentation](https://microsoft.github.io/autogen/)
201200
* [LangGraph Documentation](https://langchain-ai.github.io/langgraph/tutorials/introduction/)
202201
* [LlamaIndex Documentation](https://docs.llamaindex.ai/en/latest/)
203202
* [OpenAI Agents Documentation](https://openai.github.io/openai-agents-python/)
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
"""
2+
Agent Framework MagenticOne Example - Travel Planning with Multiple Agents
3+
"""
4+
import asyncio
5+
import os
6+
7+
from agent_framework import (
8+
ChatAgent,
9+
MagenticAgentMessageEvent,
10+
MagenticBuilder,
11+
MagenticCallbackEvent,
12+
MagenticCallbackMode,
13+
MagenticOrchestratorMessageEvent,
14+
WorkflowOutputEvent,
15+
)
16+
from agent_framework.azure import AzureOpenAIChatClient
17+
from agent_framework.openai import OpenAIChatClient
18+
from azure.identity import DefaultAzureCredential
19+
from dotenv import load_dotenv
20+
from rich.console import Console
21+
from rich.markdown import Markdown
22+
from rich.panel import Panel
23+
24+
# Setup the client to use either Azure OpenAI or GitHub Models
25+
load_dotenv(override=True)
26+
API_HOST = os.getenv("API_HOST", "github")
27+
28+
if API_HOST == "azure":
29+
client = AzureOpenAIChatClient(
30+
credential=DefaultAzureCredential(),
31+
deployment_name=os.environ.get("AZURE_OPENAI_CHAT_DEPLOYMENT"),
32+
endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT"),
33+
api_version=os.environ.get("AZURE_OPENAI_VERSION"),
34+
)
35+
elif API_HOST == "github":
36+
client = OpenAIChatClient(
37+
base_url="https://models.github.ai/inference",
38+
api_key=os.environ["GITHUB_TOKEN"],
39+
model_id=os.getenv("GITHUB_MODEL", "openai/gpt-4o"),
40+
)
41+
elif API_HOST == "ollama":
42+
client = OpenAIChatClient(
43+
base_url=os.environ.get("OLLAMA_ENDPOINT", "http://localhost:11434/v1"),
44+
api_key="none",
45+
model_id=os.environ.get("OLLAMA_MODEL", "llama3.1:latest"),
46+
)
47+
else:
48+
client = OpenAIChatClient(api_key=os.environ.get("OPENAI_API_KEY"), model_id=os.environ.get("OPENAI_MODEL", "gpt-4o"))
49+
50+
# Initialize rich console
51+
console = Console()
52+
53+
# Create the agents
54+
local_agent = ChatAgent(
55+
chat_client=client,
56+
instructions=("You are a helpful assistant that can suggest authentic and interesting local activities " "or places to visit for a user and can utilize any context information provided."),
57+
name="local_agent",
58+
description="A local assistant that can suggest local activities or places to visit.",
59+
)
60+
61+
language_agent = ChatAgent(
62+
chat_client=client,
63+
instructions=(
64+
"You are a helpful assistant that can review travel plans, providing feedback on important/critical "
65+
"tips about how best to address language or communication challenges for the given destination. "
66+
"If the plan already includes language tips, you can mention that the plan is satisfactory, with rationale."
67+
),
68+
name="language_agent",
69+
description="A helpful assistant that can provide language tips for a given destination.",
70+
)
71+
72+
travel_summary_agent = ChatAgent(
73+
chat_client=client,
74+
instructions=(
75+
"You are a helpful assistant that can take in all of the suggestions and advice from the other agents "
76+
"and provide a detailed final travel plan. You must ensure that the final plan is integrated and complete. "
77+
"YOUR FINAL RESPONSE MUST BE THE COMPLETE PLAN. Provide a comprehensive summary when all perspectives "
78+
"from other agents have been integrated."
79+
),
80+
name="travel_summary_agent",
81+
description="A helpful assistant that can summarize the travel plan.",
82+
)
83+
84+
85+
# Event callback for streaming output with rich formatting
86+
async def on_event(event: MagenticCallbackEvent) -> None:
87+
if isinstance(event, MagenticOrchestratorMessageEvent):
88+
emoji = "✅" if event.kind == "task_ledger" else "🦠"
89+
console.print(
90+
Panel(
91+
Markdown(event.message.text),
92+
title=f"{emoji} orchestrator: {event.kind}",
93+
border_style="bold green",
94+
padding=(1, 2),
95+
)
96+
)
97+
elif isinstance(event, MagenticAgentMessageEvent):
98+
console.print(
99+
Panel(
100+
Markdown(event.message.text),
101+
title=f"🤖 {event.agent_id}",
102+
border_style="bold blue",
103+
padding=(1, 2),
104+
)
105+
)
106+
107+
108+
magentic_orchestrator = (
109+
MagenticBuilder()
110+
.participants(
111+
local_agent=local_agent,
112+
language_agent=language_agent,
113+
travel_summary_agent=travel_summary_agent,
114+
)
115+
.on_event(on_event, mode=MagenticCallbackMode.NON_STREAMING)
116+
.with_standard_manager(
117+
chat_client=client,
118+
max_round_count=20,
119+
max_stall_count=3,
120+
max_reset_count=2,
121+
)
122+
.build()
123+
)
124+
125+
126+
async def main():
127+
async for event in magentic_orchestrator.run_stream("Plan a half-day trip to Costa Rica"):
128+
if isinstance(event, WorkflowOutputEvent):
129+
final_result = event.data
130+
console.print(
131+
Panel(
132+
Markdown(final_result.text),
133+
title="🌎 final travel plan",
134+
border_style="bold green",
135+
padding=(1, 2),
136+
)
137+
)
138+
139+
140+
if __name__ == "__main__":
141+
asyncio.run(main())

examples/agentframework_supervisor.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
from rich import print
1515
from rich.logging import RichHandler
1616

17-
# Logging setup
18-
logging.basicConfig(level=logging.WARNING, format="%(message)s", datefmt="[%X]", handlers=[RichHandler()])
19-
logger = logging.getLogger("supervisor_demo")
17+
# Setup logging
18+
handler = RichHandler(show_path=False, rich_tracebacks=True, show_level=False)
19+
logging.basicConfig(level=logging.WARNING, handlers=[handler], force=True, format="%(message)s")
20+
logger = logging.getLogger(__name__)
21+
logger.setLevel(logging.INFO)
2022

23+
# Configure OpenAI client based on environment
2124
load_dotenv(override=True)
2225
API_HOST = os.getenv("API_HOST", "github")
23-
2426
if API_HOST == "azure":
2527
client = OpenAIChatClient(
2628
base_url=os.environ.get("AZURE_OPENAI_ENDPOINT") + "/openai/v1/",
@@ -141,7 +143,9 @@ def check_fridge() -> list[str]:
141143

142144
meal_agent = ChatAgent(
143145
chat_client=client,
144-
instructions=("You help users plan meals and choose the best recipes. " "Include the ingredients and cooking instructions in your response. " "Indicate what the user needs to buy from the store when their fridge is missing ingredients."),
146+
instructions=(
147+
"You help users plan meals and choose the best recipes. " "Include the ingredients and cooking instructions in your response. " "Indicate what the user needs to buy from the store when their fridge is missing ingredients."
148+
),
145149
tools=[find_recipes, check_fridge],
146150
)
147151

@@ -159,7 +163,11 @@ async def plan_meal(query: str) -> str:
159163

160164
supervisor_agent = ChatAgent(
161165
chat_client=client,
162-
instructions=("You are a supervisor managing two specialist agents: a weekend planning agent and a meal planning agent. " "Break down the user's request, decide which specialist (or both) to call via the available tools, " "and then synthesize a final helpful answer. When invoking a tool, provide clear, concise queries."),
166+
instructions=(
167+
"You are a supervisor managing two specialist agents: a weekend planning agent and a meal planning agent. "
168+
"Break down the user's request, decide which specialist (or both) to call via the available tools, "
169+
"and then synthesize a final helpful answer. When invoking a tool, provide clear, concise queries."
170+
),
163171
tools=[plan_weekend, plan_meal],
164172
)
165173

examples/agentframework_tool.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
from rich import print
1414
from rich.logging import RichHandler
1515

16-
# Setup logging with rich
17-
logging.basicConfig(level=logging.WARNING, format="%(message)s", datefmt="[%X]", handlers=[RichHandler()])
18-
logger = logging.getLogger("weekend_planner")
16+
# Setup logging
17+
handler = RichHandler(show_path=False, rich_tracebacks=True, show_level=False)
18+
logging.basicConfig(level=logging.WARNING, handlers=[handler], force=True, format="%(message)s")
19+
logger = logging.getLogger(__name__)
20+
logger.setLevel(logging.INFO)
1921

22+
# Configure OpenAI client based on environment
2023
load_dotenv(override=True)
2124
API_HOST = os.getenv("API_HOST", "github")
22-
2325
if API_HOST == "azure":
2426
client = OpenAIChatClient(
2527
base_url=os.environ.get("AZURE_OPENAI_ENDPOINT") + "/openai/v1/",

examples/agentframework_tools.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
from rich import print
1515
from rich.logging import RichHandler
1616

17-
# Setup logging with rich
18-
logging.basicConfig(level=logging.WARNING, format="%(message)s", datefmt="[%X]", handlers=[RichHandler()])
19-
logger = logging.getLogger("weekend_planner")
17+
# Setup logging
18+
handler = RichHandler(show_path=False, rich_tracebacks=True, show_level=False)
19+
logging.basicConfig(level=logging.WARNING, handlers=[handler], force=True, format="%(message)s")
20+
logger = logging.getLogger(__name__)
21+
logger.setLevel(logging.INFO)
2022

23+
# Configure OpenAI client based on environment
2124
load_dotenv(override=True)
2225
API_HOST = os.getenv("API_HOST", "github")
23-
2426
if API_HOST == "azure":
2527
client = OpenAIChatClient(
2628
base_url=os.environ.get("AZURE_OPENAI_ENDPOINT") + "/openai/v1/",

0 commit comments

Comments
 (0)