OpenAgentID documentation
Source referencesRust module referenceopenagent-claude-agent

openagent-claude-agent · hooks

Declared module signatures, types, configuration, and source documentation.

Source: openagent-sdk/integrations/claude-agent-sdk/rust/src/hooks.rs. SHA-256: 3bf764fae3216f04fddedb38b0a7577d86ac1c17c79e524af886d11402a0a892.

This source reference follows declared modules and preserves feature attributes. It includes public declarations and implementation methods in those modules. Private-module exports and trait resolution still require the compiler; not every declaration is a crate-root import. Function bodies and constant values are omitted. Source comments describe their implementation context and are not a production deployment claim.

hooks::HookContext

Per-session hook context. Constructed on session start, threaded through subsequent hook invocations, dropped on session end.

pub struct HookContext {
/// The verified agent identity.

pub identity: Arc<dyn OpenAgentIdentity>,
/// Capability checker (Arsenal-backed in production).

pub capabilities: Arc<dyn CapabilityChecker>,
/// Skills policy (defaults to `DenyUnlessScopedSkillsPolicy`).

pub skills_policy: Arc<dyn SkillsPolicy>,
/// Audit chain for this session.

pub chain: Arc<AuditChain>,
/// Whether outbound messages are signed with the agent's key.

pub sign_messages: bool
}

Source line: 27.

hooks::OpenAgentHooks

Lifecycle hook trait. Implement this in any Rust agent harness to receive OpenAgent enforcement and audit events.

#[async_trait]
pub trait OpenAgentHooks: Send + Sync {
    /// Called once when a new session begins.
    async fn on_session_start(&self, session_id: &str) -> Result<()>;

    /// Called once when the session ends.
    async fn on_session_end(&self) -> Result<()>;

    /// Called before a tool runs. Returns Err(ToolDenied) on deny in
    /// `Throw` mode; otherwise returns Ok with the (allow=false) audit
    /// trail already recorded.
    async fn pre_tool_use(&self, tool_name: &str, args: &Value) -> Result<()>;

    /// Called after a tool runs.
    async fn post_tool_use(
        &self,
        tool_name: &str,
        result: &Value,
        ok: bool,
        error: Option<&str>,
    ) -> Result<()>;

    /// Called when an outbound or inbound message passes through the agent.
    async fn on_message(&self, body: &[u8], outbound: bool) -> Result<Option<String>>;

    /// Called when the agent attempts to invoke a SKILLS.md skill.
    async fn on_skill_invoke(&self, skill_name: &str, args: Option<&Value>) -> Result<()>;
}

Source line: 43.

On this page