Commit f4d7b68
feat(langchain): implement native GovernanceMiddleware via AgentMiddleware (microsoft#1585)
Replaces fragile proxy-based wrapping with LangChain's native
AgentMiddleware system (wrap_tool_call / wrap_model_call).
Changes:
- Add GovernanceMiddleware class implementing wrap_tool_call and
wrap_model_call lifecycle hooks for native governance gating
- Add as_middleware() factory on LangChainKernel for clean integration
- Implement blocked-pattern checks on both tool and model outputs
- Support pre_execute/post_execute Cedar/OPA gates on tool calls
- Support content filtering on model inputs and outputs
- Deprecate LangChainKernel.wrap() and module-level wrap() with
clear migration path to as_middleware()
- Add comprehensive test suite (39 tests) covering:
* Tool allowlist/blocklist enforcement
* Blocked pattern detection in args, tool names, and outputs
* Model input/output content filtering
* Cedar evaluator passthrough
* Shared kernel state across middleware instances
* Deprecation warning verification
* Full backward compatibility with existing wrap() API
Resolves microsoft#1584
Co-authored-by: Nishar <you@example.com>1 parent 41201fb commit f4d7b68
3 files changed
Lines changed: 1002 additions & 45 deletions
File tree
- agent-governance-python/agent-os
- src/agent_os/integrations
- tests
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
75 | 78 | | |
76 | 79 | | |
77 | 80 | | |
| |||
0 commit comments