|
1 | 1 | # Copyright (c) Microsoft. All rights reserved. |
2 | 2 |
|
3 | | -"""Tier 1 ΓÇö Zero-Config Activity Protocol Agent (with debug logging). |
| 3 | +"""Tier 1 - Zero-Config Activity Protocol Agent. |
4 | 4 |
|
5 | 5 | The simplest possible activity protocol agent. The package auto-initializes |
6 | 6 | the M365 Agents SDK from environment variables, applies MSAL auth patches, |
7 | 7 | and bridges activities to the AgentApplication turn pipeline. |
8 | 8 |
|
9 | | -You write only handler logic ΓÇö no SDK wiring needed. |
| 9 | +You write only handler logic - no SDK wiring needed. |
10 | 10 | """ |
11 | 11 |
|
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 | | - |
31 | 12 | from azure.ai.agentserver.activity import ActivityAgentServerHost |
32 | 13 |
|
33 | 14 | app = ActivityAgentServerHost() |
34 | 15 |
|
35 | 16 |
|
36 | 17 | @app.activity("message") |
37 | 18 | async def on_message(context, state): |
38 | | - """Echo the user's message back with environment variables.""" |
| 19 | + """Echo the user's message back.""" |
39 | 20 | 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 "?") |
44 | 21 | 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}" |
51 | 23 | await context.send_activity(reply) |
52 | | - logger.info("REPLY SENT | text=%s", reply) |
53 | 24 |
|
54 | 25 |
|
55 | 26 | @app.activity("conversationUpdate") |
56 | 27 | async def on_members_added(context, state): |
57 | 28 | """Welcome new members.""" |
58 | 29 | for member in context.activity.members_added or []: |
59 | 30 | 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}!") |
65 | 32 |
|
66 | 33 |
|
67 | 34 | @app.error |
68 | 35 | async def on_error(context, error): |
69 | 36 | """Handle unhandled errors.""" |
70 | | - logger.error("HANDLER ERROR | error=%s", error, exc_info=True) |
71 | 37 | await context.send_activity(f"Sorry, something went wrong: {error}") |
72 | 38 |
|
73 | 39 |
|
|
0 commit comments