Skip to content

Commit b91419d

Browse files
committed
Improve error handling in orchestration manager
Added try/except blocks for chat client and manager instantiation in OrchestrationManager to log and raise errors. Also fixed import formatting and parameter names for AzureOpenAIChatClient. Minor formatting update in pyproject.toml dependencies.
1 parent ee61d94 commit b91419d

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

src/backend/af/orchestration/orchestration_manager.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
# agent_framework imports
99
from agent_framework.azure import AzureOpenAIChatClient
10+
1011
from agent_framework import ChatMessage, ChatOptions
1112
from agent_framework._workflows import MagenticBuilder
1213
from agent_framework._workflows._magentic import AgentRunResponseUpdate # type: ignore
@@ -24,9 +25,7 @@
2425
from af.config.settings import connection_config, orchestration_config
2526
from af.models.messages import WebsocketMessageType
2627
from af.orchestration.human_approval_manager import HumanApprovalMagenticManager
27-
from af.magentic_agents.magentic_agent_factory import (
28-
MagenticAgentFactory,
29-
)
28+
from af.magentic_agents.magentic_agent_factory import MagenticAgentFactory
3029

3130
class OrchestrationManager:
3231
"""Manager for handling orchestration logic using agent_framework Magentic workflow."""
@@ -104,20 +103,30 @@ def get_token():
104103
return token.token
105104

106105
# Create Azure chat client (agent_framework style) - relying on environment or explicit kwargs.
107-
chat_client = AzureOpenAIChatClient(
108-
endpoint=config.AZURE_OPENAI_ENDPOINT,
109-
model_deployment_name=config.AZURE_OPENAI_DEPLOYMENT_NAME,
110-
azure_ad_token_provider=get_token,
111-
)
112-
106+
try:
107+
chat_client = AzureOpenAIChatClient(
108+
endpoint=config.AZURE_OPENAI_ENDPOINT,
109+
deployment_name=config.AZURE_OPENAI_DEPLOYMENT_NAME,
110+
ad_token_provider=get_token,
111+
)
112+
except Exception as e: # noqa: BLE001
113+
logging.getLogger(__name__).error(
114+
"chat_client error: %s", e
115+
)
116+
raise
113117
# HumanApprovalMagenticManager needs the chat_client passed as 'chat_client' in its constructor signature (it subclasses StandardMagenticManager)
114-
manager = HumanApprovalMagenticManager(
115-
user_id=user_id,
116-
chat_client=chat_client,
117-
instructions=None, # optionally supply orchestrator system instructions
118-
max_round_count=orchestration_config.max_rounds,
119-
)
120-
118+
try:
119+
manager = HumanApprovalMagenticManager(
120+
user_id=user_id,
121+
chat_client=chat_client,
122+
instructions=None, # optionally supply orchestrator system instructions
123+
max_round_count=orchestration_config.max_rounds,
124+
)
125+
except Exception as e: # noqa: BLE001
126+
logging.getLogger(__name__).error(
127+
"manager error: %s", e
128+
)
129+
raise
121130
# Build participant map: use each agent's name as key
122131
participants = {}
123132
for ag in agents:

src/backend/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Add your description here"
55
readme = "README.md"
66
requires-python = ">=3.11"
77
dependencies = [
8-
"agent-framework-core @ git+https://github.com/microsoft/agent-framework.git@main#subdirectory=python/packages/core",
8+
"agent-framework-core @ git+https://github.com/microsoft/agent-framework.git@main#subdirectory=python/packages/core",
99
"agent-framework-azure-ai @ git+https://github.com/microsoft/agent-framework.git@main#subdirectory=python/packages/azure-ai",
1010
"agent-framework-copilotstudio @ git+https://github.com/microsoft/agent-framework.git@main#subdirectory=python/packages/copilotstudio",
1111
"agent-framework-devui @ git+https://github.com/microsoft/agent-framework.git@main#subdirectory=python/packages/devui",

0 commit comments

Comments
 (0)