You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🛡️ APort Middleware Integration for Microsoft Agent Framework
Overview
APort provides a universal, open, enterprise-grade guardrail, identity verification, policy enforcement, and audit trails for AI agents. We propose integrating APort as middleware for Microsoft Agent Framework to enable pre-execution authorization - ensuring agents are verified and compliant before they execute any actions.
🎯 Value Proposition for Microsoft Agent Framework
Current Challenge
Agents execute actions with no easy way do handle pre-authorization checks
No standardized way to verify agent identity before execution
Limited audit trails for compliance (SOC 2, IIROC, OSFI)
Risk of unauthorized agent actions in enterprise environments
APort Solution
Pre-execution verification: Verify agent passports before agent runs
Policy enforcement: Enforce spending limits, data access, regional restrictions
Real-time authorization: ms authorization decisions
Audit trails: Cryptographically signed attestations for compliance
fromtypingimportCallable, Awaitable, Optional, Dict, Anyfromagent_frameworkimportAgentRunContextfromaporthq_sdk_pythonimportAPortClient, APortClientOptions, AportError, PolicyVerificationResponseasyncdefaport_agent_middleware(
context: AgentRunContext,
next: Callable[[AgentRunContext], Awaitable[None]],
) ->None:
"""APort middleware for agent authorization and policy enforcement."""# Initialize APort client (in production, this would be injected)client=APortClient(APortClientOptions(
base_url="https://api.aport.io", # Optionalapi_key="your-api-key", # From environment or config. Optional. No API key or account required.timeout_ms=800# Optional
))
# Extract agent ID from context metadataagent_id=context.metadata.get('agent_id') orcontext.metadata.get('agent_passport_id')
ifnotagent_id:
# Fail closed - terminate execution if no agent ID providedcontext.terminate=Truecontext.result= {
"error": "missing_agent_id",
"message": "Agent ID is required for authorization"
}
returntry:
# Extract policy ID from context metadatapolicy_id=context.metadata.get('policy_id')
ifpolicy_id:
# Policy verification includes passport verification automaticallydecision: PolicyVerificationResponse=awaitclient.verify_policy(
agent_id=agent_id,
policy_id=policy_id,
context=_extract_context_data(context)
)
# https://github.com/aporthq/aport-spec/blob/main/oap/decision-schema.jsonifnotdecision.allow:
# Policy violation - terminate executioncontext.terminate=Truecontext.result= {
"error": "policy_violation",
"decision_id": decision.decision_id,
"reasons": decision.reasons,
"assurance_level": decision.assurance_level
}
return# Store policy decision in context for audit trailcontext.metadata['aport_decision'] = {
"decision_id": decision.decision_id,
"allow": decision.allow,
"assurance_level": decision.assurance_level,
"reasons": decision.reasons
}
else:
# Only verify passport if no policy specifiedpassport_view=awaitclient.get_passport_view(agent_id)
context.metadata['agent_passport'] =passport_view# Continue to next middleware or agent executionawaitnext(context)
# Generate audit trail after successful executionifcontext.resultandnotcontext.terminate:
await_generate_audit_trail(client, agent_id, context)
exceptAportErrorase:
# APort API error - terminate executioncontext.terminate=Truecontext.result= {
"error": "agent_verification_failed",
"status": e.status,
"message": str(e),
"reasons": e.reasons,
"decision_id": e.decision_id
}
exceptExceptionase:
# Unexpected error - terminate executioncontext.terminate=Truecontext.result= {
"error": "internal_error",
"message": f"Authorization failed: {str(e)}"
}
finally:
# Clean up client resourcesawaitclient.close()
def_extract_context_data(context: AgentRunContext) ->Dict[str, Any]:
"""Extract relevant context data for policy evaluation."""return {
"action": context.metadata.get('action', 'unknown'),
"resource": context.metadata.get('resource'),
"amount": context.metadata.get('amount'),
"region": context.metadata.get('region'),
"timestamp": context.metadata.get('timestamp'),
# Add any other context data needed for policy evaluation
}
asyncdef_generate_audit_trail(
client: APortClient,
agent_id: str,
context: AgentRunContext
) ->None:
"""Generate cryptographically signed audit trail."""audit_data= {
"agent_id": agent_id,
"action": context.metadata.get('action', 'unknown'),
"result": context.result,
"timestamp": context.metadata.get('timestamp'),
"policy_id": context.metadata.get('policy_id'),
"decision_id": context.metadata.get('aport_decision', {}).get('decision_id')
}
# Note: This would be implemented when audit trail API is available# await client.create_audit_trail(audit_data)print(f"Audit trail: {audit_data}") # Placeholder
Usage Example
fromagent_framework.azureimportAzureAIAgentClientfromazure.identity.aioimportAzureCliCredentialasyncdefmain():
credential=AzureCliCredential()
# Create agent with APort middlewareasyncwithAzureAIAgentClient(async_credential=credential).create_agent(
name="RefundAgent",
instructions="You are a helpful refund assistant.",
tools=[process_refund_tool],
middleware=[aport_agent_middleware], # Agent-level middleware
) asagent:
# Run with agent ID and policy contextresult=awaitagent.run(
"Process a $50 refund for order 12345",
middleware=[], # No additional run-level middleware neededmetadata={
'agent_id': 'ap_a2d10232c6534523812423eec8a1425c45678',
'policy_id': 'finance.payment.refund.v1',
'action': 'refund',
'amount': 5000, # Amount in cents'region': 'US'
}
)
print(f"Refund result: {result}")
# Tool function that benefits from pre-authorizationasyncdefprocess_refund_tool(order_id: str, amount: int) ->str:
"""Process a refund - only called if APort authorization passes."""returnf"Refund of ${amount/100:.2f} processed for order {order_id}"
Alternative: Class-Based Implementation
For more complex scenarios requiring stateful operations:
Policies: How should policy definitions be managed, versioned, and distributed across the ecosystem? Currently, they are at https://github.com/aporthq/aport-policies
Performance: What are the acceptable latency requirements for authorization in different use cases?
Error Handling: How should authorization failures be handled in different agent execution contexts? Currently, we have Open Agent Passport (OAP) Spec, https://github.com/aporthq/aport-spec, that defines decision, errors etc
🔗 Resources
Live Demo: demo.aport.io - Interactive APort demonstration
Community Feedback: Gather input on integration approach and requirements
Proof of Concept: Build initial middleware implementation with Microsoft Agent Framework
Pull Request: Submit PR with working middleware and comprehensive tests
Documentation: Create integration guides, examples, and best practices
Discord Launch: Share implementation on Microsoft Agent Framework Discord community
We're excited to contribute to the Microsoft Agent Framework ecosystem and help make AI agents more secure and compliant for enterprise use cases!
What are your thoughts on this integration approach? We'd love to hear from the community and Microsoft team about the technical implementation and enterprise requirements, before we create an issue and PR
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
🛡️ APort Middleware Integration for Microsoft Agent Framework
Overview
APort provides a universal, open, enterprise-grade guardrail, identity verification, policy enforcement, and audit trails for AI agents. We propose integrating APort as middleware for Microsoft Agent Framework to enable pre-execution authorization - ensuring agents are verified and compliant before they execute any actions.
🎯 Value Proposition for Microsoft Agent Framework
Current Challenge
APort Solution
🔧 Technical Integration
Proposed Implementation
Based on the Microsoft Agent Framework middleware documentation, we'll use the function-based middleware approach for simplicity and elegance:
Usage Example
Alternative: Class-Based Implementation
For more complex scenarios requiring stateful operations:
🏢 Enterprise Use Cases
Financial Services
Healthcare
E-commerce
📊 Benefits for Microsoft Agent Framework Ecosystem
🚀 Implementation Approach
Phase 1: Core Middleware (First PR)
Phase 2: Advanced and Enterprise Features (2nd PR)
🔧 Technical Specifications
Performance Requirements
Security Features
🤝 Community Benefits
📋 Questions for Discussion
@aporthq/microsoft-agent-middlewareimplement at https://github.com/aporthq/aport-sdks-and-middlewares) or integrated into the core framework?🔗 Resources
💡 Next Steps
We're excited to contribute to the Microsoft Agent Framework ecosystem and help make AI agents more secure and compliant for enterprise use cases!
What are your thoughts on this integration approach? We'd love to hear from the community and Microsoft team about the technical implementation and enterprise requirements, before we create an issue and PR
Beta Was this translation helpful? Give feedback.
All reactions