11import asyncio
2+ import base64
23import inspect
4+ import json
35from collections .abc import AsyncGenerator , Awaitable , Callable
46from contextlib import asynccontextmanager
57from typing import Any
@@ -341,6 +343,16 @@ def run(self, host: str = "0.0.0.0", port: int = 8000, **kwargs):
341343 """Start the Uvicorn server for async handlers."""
342344 uvicorn .run (self , host = host , port = port , ** kwargs )
343345
346+ def _get_auth_principal (self , env_vars : EnvironmentVariables ):
347+ if not env_vars .AUTH_PRINCIPAL_B64 :
348+ return None
349+
350+ try :
351+ decoded_str = base64 .b64decode (env_vars .AUTH_PRINCIPAL_B64 ).decode ('utf-8' )
352+ return json .loads (decoded_str )
353+ except Exception :
354+ return None
355+
344356 async def _register_agent (self , env_vars : EnvironmentVariables ):
345357 """Register this agent with the Agentex server"""
346358 # Build the agent's own URL
@@ -350,12 +362,14 @@ async def _register_agent(self, env_vars: EnvironmentVariables):
350362 env_vars .AGENT_DESCRIPTION
351363 or f"Generic description for agent: { env_vars .AGENT_NAME } "
352364 )
365+
353366 # Prepare registration data
354367 registration_data = {
355368 "name" : env_vars .AGENT_NAME ,
356369 "description" : description ,
357370 "acp_url" : full_acp_url ,
358371 "acp_type" : env_vars .ACP_TYPE ,
372+ "principal_context" : self ._get_auth_principal (env_vars )
359373 }
360374
361375 if env_vars .AGENT_ID :
0 commit comments