pub struct PurviewAgentMiddleware(/* private fields */);Expand description
SupportsAgentRun middleware enforcing Purview policy on both the outgoing prompt and
the agent’s response. Mirrors Python’s PurviewPolicyMiddleware.
- Prompt (pre) check: evaluates
ctx.messages. If blocked, short-circuits with a singlesystem-role message (PurviewSettings::blocked_prompt_message) andctx.terminate = true— the wrapped agent/chat-client is never called, matching this crate’sShortCircuitChat-style test pattern inagent-framework-core. - Response (post) check: only runs when
!ctx.is_streamingand a result was produced (mirrors Python: “Streaming responses are not supported for post-checks”). If blocked,ctx.resultis replaced with a singlesystem-role message (PurviewSettings::blocked_response_message) — unlike the prompt check,ctx.terminateis not set here (there’s nothing left to terminate; the underlying call already happened), matching Python.
use agent_framework_core::prelude::*;
use agent_framework_purview::{PurviewAgentMiddleware, PurviewSettings, PurviewAppLocation, PurviewLocationType, StaticTokenProvider};
use std::sync::Arc;
let settings = PurviewSettings::new("My App")
.with_tenant_id("00000000-0000-0000-0000-000000000000")
.with_purview_app_location(PurviewAppLocation::new(
PurviewLocationType::Application,
"00000000-0000-0000-0000-000000000001",
));
let middleware = PurviewAgentMiddleware::new(StaticTokenProvider::new("<graph-bearer-token>"), settings);
let agent = Agent::builder(client)
.instructions("You are a helpful assistant.")
.middleware(Arc::new(middleware))
.build();Implementations§
Source§impl PurviewAgentMiddleware
impl PurviewAgentMiddleware
pub fn new( token_provider: impl TokenProvider + 'static, settings: PurviewSettings, ) -> Self
Trait Implementations§
Source§impl Middleware<AgentContext> for PurviewAgentMiddleware
impl Middleware<AgentContext> for PurviewAgentMiddleware
fn process<'life0, 'async_trait>(
&'life0 self,
ctx: AgentContext,
next: Next<AgentContext>,
) -> Pin<Box<dyn Future<Output = Result<AgentContext>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Auto Trait Implementations§
impl !RefUnwindSafe for PurviewAgentMiddleware
impl !UnwindSafe for PurviewAgentMiddleware
impl Freeze for PurviewAgentMiddleware
impl Send for PurviewAgentMiddleware
impl Sync for PurviewAgentMiddleware
impl Unpin for PurviewAgentMiddleware
impl UnsafeUnpin for PurviewAgentMiddleware
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more