-
Notifications
You must be signed in to change notification settings - Fork 49
Run bare open ai agent when agentic auth is false #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -232,11 +232,12 @@ async def setup_mcp_servers(self, auth: Authorization, auth_handler_name: str, c | |||||||||||||||||||||||||||||||||
| context=context, | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||
| # For anonymous mode, don't pass auth/context to avoid token retrieval | ||||||||||||||||||||||||||||||||||
| self.agent = await self.tool_service.add_tool_servers_to_agent( | ||||||||||||||||||||||||||||||||||
| agent=self.agent, | ||||||||||||||||||||||||||||||||||
| auth=auth, | ||||||||||||||||||||||||||||||||||
| auth_handler_name=auth_handler_name, | ||||||||||||||||||||||||||||||||||
| context=context, | ||||||||||||||||||||||||||||||||||
| auth=None, | ||||||||||||||||||||||||||||||||||
| auth_handler_name=None, | ||||||||||||||||||||||||||||||||||
| context=None, | ||||||||||||||||||||||||||||||||||
| auth_token=self.auth_options.bearer_token, | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -268,8 +269,11 @@ async def process_user_message( | |||||||||||||||||||||||||||||||||
| ) -> str: | ||||||||||||||||||||||||||||||||||
| """Process user message using the OpenAI Agents SDK""" | ||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||
| # Setup MCP servers | ||||||||||||||||||||||||||||||||||
| await self.setup_mcp_servers(auth, auth_handler_name, context) | ||||||||||||||||||||||||||||||||||
| # Setup MCP servers only if not already done or if auth is available | ||||||||||||||||||||||||||||||||||
| # In anonymous mode (USE_AGENTIC_AUTH=false), skip setup to avoid auth errors | ||||||||||||||||||||||||||||||||||
| use_agentic_auth = os.getenv("USE_AGENTIC_AUTH", "false").lower() == "true" | ||||||||||||||||||||||||||||||||||
| if use_agentic_auth and auth is not None: | ||||||||||||||||||||||||||||||||||
| await self.setup_mcp_servers(auth, auth_handler_name, context) | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+272
to
+276
|
||||||||||||||||||||||||||||||||||
| # Setup MCP servers only if not already done or if auth is available | |
| # In anonymous mode (USE_AGENTIC_AUTH=false), skip setup to avoid auth errors | |
| use_agentic_auth = os.getenv("USE_AGENTIC_AUTH", "false").lower() == "true" | |
| if use_agentic_auth and auth is not None: | |
| await self.setup_mcp_servers(auth, auth_handler_name, context) | |
| # Setup MCP servers for each message. The setup_mcp_servers method | |
| # internally handles both authenticated and anonymous modes based on | |
| # the USE_AGENTIC_AUTH environment variable. | |
| await self.setup_mcp_servers(auth, auth_handler_name, context) |
Copilot
AI
Jan 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The environment variable check is duplicated - it's read both in process_user_message (line 274) and in setup_mcp_servers (line 226). This creates redundant code and potential inconsistency if the logic changes. Since setup_mcp_servers already handles the conditional logic internally, the check in process_user_message is unnecessary.
| # Setup MCP servers only if not already done or if auth is available | |
| # In anonymous mode (USE_AGENTIC_AUTH=false), skip setup to avoid auth errors | |
| use_agentic_auth = os.getenv("USE_AGENTIC_AUTH", "false").lower() == "true" | |
| if use_agentic_auth and auth is not None: | |
| await self.setup_mcp_servers(auth, auth_handler_name, context) | |
| # Setup MCP servers; internal logic handles auth vs. anonymous modes | |
| await self.setup_mcp_servers(auth, auth_handler_name, context) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,8 +46,8 @@ def check_agent_inheritance(agent_class) -> bool: | |
| True if the agent inherits from AgentInterface, False otherwise | ||
| """ | ||
| if not issubclass(agent_class, AgentInterface): | ||
| print(f"❌ Agent {agent_class.__name__} does not inherit from AgentInterface") | ||
| print(f"ERROR: Agent {agent_class.__name__} does not inherit from AgentInterface") | ||
|
||
| return False | ||
|
|
||
| print(f"✅ Agent {agent_class.__name__} properly inherits from AgentInterface") | ||
| print(f"SUCCESS: Agent {agent_class.__name__} properly inherits from AgentInterface") | ||
| return True | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -68,7 +68,9 @@ def __init__(self, agent_class: type[AgentInterface], *agent_args, **agent_kwarg | |||||||||||||||||||||
| if not check_agent_inheritance(agent_class): | ||||||||||||||||||||||
| raise TypeError(f"Agent class {agent_class.__name__} must inherit from AgentInterface") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| self.auth_handler_name = "AGENTIC" | ||||||||||||||||||||||
| # Only use auth handler when agentic auth is enabled | ||||||||||||||||||||||
| use_agentic_auth = os.getenv("USE_AGENTIC_AUTH", "false").lower() == "true" | ||||||||||||||||||||||
| self.auth_handler_name = "AGENTIC" if use_agentic_auth else None | ||||||||||||||||||||||
|
||||||||||||||||||||||
| self.auth_handler_name = "AGENTIC" if use_agentic_auth else None | |
| if use_agentic_auth: | |
| self.auth_handler_name = "AGENTIC" | |
| else: | |
| self.auth_handler_name = None | |
| logger.warning( | |
| "Agentic authentication is disabled (USE_AGENTIC_AUTH=false). " | |
| "The GenericAgentHost will accept unauthenticated requests; " | |
| "ensure appropriate network-level access controls are in place for this deployment." | |
| ) |
Copilot
AI
Jan 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using **handler_config to conditionally pass auth_handlers is a clean approach, but it relies on the framework accepting an empty dictionary when no auth handlers are needed. While this likely works, consider verifying that the activity decorator properly handles the case when auth_handlers is not provided, especially to ensure backward compatibility with different versions of the Microsoft Agents SDK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states "For anonymous mode, don't pass auth/context to avoid token retrieval", but this approach may break MCP server functionality that depends on context for other purposes beyond authentication. Consider documenting the specific MCP server limitations when running in anonymous mode, or verify that all MCP operations can function with just a bearer token and no context.