Skip to content

Commit 06c7d6f

Browse files
chore(agentserver-activity): simplify sample logging and debug output
1 parent d491b23 commit 06c7d6f

3 files changed

Lines changed: 15 additions & 77 deletions

File tree

  • sdk/agentserver/azure-ai-agentserver-activity/samples

sdk/agentserver/azure-ai-agentserver-activity/samples/echo-agent/main.py

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,39 @@
11
# Copyright (c) Microsoft. All rights reserved.
22

3-
"""Tier 1 ΓÇö Zero-Config Activity Protocol Agent (with debug logging).
3+
"""Tier 1 - Zero-Config Activity Protocol Agent.
44
55
The simplest possible activity protocol agent. The package auto-initializes
66
the M365 Agents SDK from environment variables, applies MSAL auth patches,
77
and bridges activities to the AgentApplication turn pipeline.
88
9-
You write only handler logic ΓÇö no SDK wiring needed.
9+
You write only handler logic - no SDK wiring needed.
1010
"""
1111

12-
import logging
13-
from os import environ
14-
15-
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s %(name)s | %(message)s")
16-
logger = logging.getLogger("tier1-echo")
17-
18-
# Enable verbose logging for all relevant namespaces
19-
for ns in ["azure.ai.agentserver", "microsoft_agents", "hypercorn"]:
20-
logging.getLogger(ns).setLevel(logging.DEBUG)
21-
22-
logger.info("========== TIER1-ECHO STARTING (debug build Jun 16 2026) ==========")
23-
logger.info("Agent name: %s", environ.get("FOUNDRY_AGENT_NAME", "(not set)"))
24-
logger.info("Agent version: %s", environ.get("FOUNDRY_AGENT_VERSION", "(not set)"))
25-
logger.info("Session ID: %s", environ.get("FOUNDRY_AGENT_SESSION_ID", "(not set)"))
26-
logger.info("Port: %s", environ.get("PORT", "8088"))
27-
logger.info("Auth type: %s", environ.get("CONNECTIONS__SERVICE_CONNECTION__SETTINGS__AUTHTYPE", "(not set)"))
28-
logger.info("Client ID: %s", environ.get("CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTID", "(not set)"))
29-
logger.info("Tenant ID: %s", environ.get("CONNECTIONS__SERVICE_CONNECTION__SETTINGS__TENANTID", "(not set)"))
30-
3112
from azure.ai.agentserver.activity import ActivityAgentServerHost
3213

3314
app = ActivityAgentServerHost()
3415

3516

3617
@app.activity("message")
3718
async def on_message(context, state):
38-
"""Echo the user's message back with environment variables."""
19+
"""Echo the user's message back."""
3920
user_text = context.activity.text or ""
40-
logger.info("MESSAGE RECEIVED | text=%s | from=%s | conv=%s",
41-
user_text[:100],
42-
getattr(context.activity.from_property, "id", "?") if context.activity.from_property else "?",
43-
context.activity.conversation.id if context.activity.conversation else "?")
4421
if user_text.strip():
45-
# Build response with user message and env vars
46-
env_lines = ["=== tier1echo16jun313pm ENVIRONMENT VARIABLES ==="]
47-
for k, v in sorted(environ.items()):
48-
env_lines.append(f"{k}={v}")
49-
50-
reply = f"[Echo agent Jun 16 2026 tier1echo16jun313pm PM ]\n\nYour message: {user_text}\n\n" + "\n".join(env_lines)
22+
reply = f"Echo: {user_text}"
5123
await context.send_activity(reply)
52-
logger.info("REPLY SENT | text=%s", reply)
5324

5425

5526
@app.activity("conversationUpdate")
5627
async def on_members_added(context, state):
5728
"""Welcome new members."""
5829
for member in context.activity.members_added or []:
5930
if member.id != context.activity.recipient.id:
60-
logger.info("MEMBER ADDED | name=%s | id=%s", member.name, member.id)
61-
try:
62-
await context.send_activity(f"Welcome, {member.name}!")
63-
except Exception as exc:
64-
logger.warning("Could not send welcome: %s", exc)
31+
await context.send_activity(f"Welcome, {member.name}!")
6532

6633

6734
@app.error
6835
async def on_error(context, error):
6936
"""Handle unhandled errors."""
70-
logger.error("HANDLER ERROR | error=%s", error, exc_info=True)
7137
await context.send_activity(f"Sorry, something went wrong: {error}")
7238

7339

sdk/agentserver/azure-ai-agentserver-activity/samples/multi-protocol-agent/main.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
# Copyright (c) Microsoft. All rights reserved.
22

3-
"""Multi-Protocol Agent Activity + Invocations.
3+
"""Multi-Protocol Agent - Activity + Invocations.
44
55
Demonstrates composing Activity and Invocations protocols on a single
6-
server using Python mixin inheritance (Tier 2 Builder pattern).
6+
server using Python mixin inheritance (Tier 2 - Builder pattern).
77
88
Both protocols share the same server on port 8088:
9-
POST /activity/messages Activity protocol (Teams/M365)
10-
POST /api/messages Activity protocol (Bot Framework compat)
11-
POST /invocations Invocations protocol (HTTP API)
9+
POST /activity/messages - Activity protocol (Teams/M365)
10+
POST /api/messages - Activity protocol (Bot Framework compat)
11+
POST /invocations - Invocations protocol (HTTP API)
1212
"""
1313

14-
import logging
15-
1614
from starlette.requests import Request
1715
from starlette.responses import JSONResponse, Response
1816

1917
from azure.ai.agentserver.activity import ActivityAgentServerHost
2018
from azure.ai.agentserver.invocations import InvocationAgentServerHost
2119

22-
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s | %(message)s")
23-
2420

2521
class MultiProtocolHost(ActivityAgentServerHost, InvocationAgentServerHost):
2622
pass

sdk/agentserver/azure-ai-agentserver-activity/samples/self-hosted-agent/main.py

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright (c) Microsoft. All rights reserved.
22

3-
"""Self-Hosted Activity Agent Full M365 SDK Control.
3+
"""Self-Hosted Activity Agent - Full M365 SDK Control.
44
55
Demonstrates the handler pattern (Tier 3) where the developer owns the
66
full M365 Agents SDK pipeline: MsalConnectionManager, HttpAdapterBase,
@@ -12,9 +12,6 @@
1212
- Full control over the activity processing pipeline
1313
"""
1414

15-
import logging
16-
import sys
17-
import traceback
1815
from os import environ
1916

2017
from starlette.responses import JSONResponse, Response
@@ -34,17 +31,10 @@
3431
TurnState,
3532
)
3633

37-
logging.basicConfig(
38-
level=logging.INFO,
39-
format="%(asctime)s %(levelname)s %(name)s | %(message)s",
40-
)
41-
logger = logging.getLogger("self-hosted-agent")
42-
4334
# ── M365 SDK setup ───────────────────────────────────────────────
4435
# Apply MSAL patches before creating MsalConnectionManager.
4536
apply_msal_patches()
4637

47-
logger.info("Initializing M365 SDK...")
4838
config = load_configuration_from_env(environ)
4939
storage = MemoryStorage()
5040
connection_manager = MsalConnectionManager(**config)
@@ -57,7 +47,6 @@
5747
authorization=authorization,
5848
**config,
5949
)
60-
logger.info("M365 SDK initialized successfully.")
6150

6251

6352
# ── Business logic ───────────────────────────────────────────────
@@ -66,41 +55,30 @@
6655
async def on_message(context: TurnContext, state: TurnState):
6756
"""Echo the user's message back."""
6857
user_text = context.activity.text or ""
69-
logger.info("Message received | text=%s", user_text[:100])
7058
await context.send_activity(Activity(type="typing"))
7159
reply = f"[Self-Hosted] Echo: {user_text}"
7260
await context.send_activity(reply)
73-
logger.info("Reply sent | text=%s", reply)
7461

7562

7663
@agent_app.activity("conversationUpdate")
7764
async def on_members_added(context: TurnContext, state: TurnState):
7865
"""Welcome new members."""
7966
for member in context.activity.members_added or []:
8067
if member.id != context.activity.recipient.id:
81-
try:
82-
await context.send_activity(f"Welcome, {member.name}!")
83-
except Exception as exc:
84-
logger.warning("Could not send welcome: %s", exc)
68+
await context.send_activity(f"Welcome, {member.name}!")
8569

8670

8771
@agent_app.error
8872
async def on_error(context: TurnContext, error: Exception):
8973
"""Handle unhandled errors."""
90-
print(f"\n [on_turn_error] unhandled error: {error}", file=sys.stderr)
91-
traceback.print_exc()
9274
await context.send_activity("The agent encountered an error.")
9375

9476

9577
# ── Foundry host with custom handler ─────────────────────────────
9678

9779
async def handle(request) -> Response:
98-
"""Bridge to M365 SDK parses activity and delegates to agent_app."""
80+
"""Bridge to M365 SDK - parses activity and delegates to agent_app."""
9981
activity_dict = request.state.activity
100-
activity_type = activity_dict.get("type", "unknown")
101-
session_id = request.state.session_id
102-
103-
logger.info("Activity received | type=%s | session=%s", activity_type, session_id)
10482

10583
activity = Activity.model_validate(activity_dict)
10684

@@ -116,11 +94,9 @@ async def handle(request) -> Response:
11694
invoke_response = await adapter.process_activity(claims, activity, agent_app.on_turn)
11795
except PermissionError:
11896
return Response(status_code=401)
119-
except TypeError as exc:
120-
logger.warning("TypeError (likely missing serviceUrl) | error=%s", exc)
97+
except TypeError:
12198
return Response(status_code=202)
122-
except Exception as exc:
123-
logger.exception("Error processing activity | error=%s", exc)
99+
except Exception:
124100
return Response(status_code=202)
125101

126102
if activity.type == "invoke" or activity.delivery_mode == "expectReplies":

0 commit comments

Comments
 (0)