pub struct UserPromptSubmitEvent {
pub prompt: String,
pub history: Vec<Value>,
}Expand description
Event fired before processing user input, enabling content moderation and prompt enhancement.
This event is triggered whenever a user submits a prompt to the agent, before the agent begins processing it. Use this to implement content moderation, add context, inject instructions, or track user interactions.
§Use Cases
- Content moderation: Filter inappropriate or harmful user inputs
- Prompt enhancement: Add system context, timestamps, or user information
- Input validation: Ensure prompts meet format or length requirements
- Usage tracking: Log user interactions for analytics or billing
- Context injection: Add relevant background information to every prompt
§Fields
prompt: The user’s original input texthistory: Read-only snapshot of the conversation history before this prompt
§Example: Content Moderation
use open_agent::{UserPromptSubmitEvent, HookDecision};
async fn content_moderator(event: UserPromptSubmitEvent) -> Option<HookDecision> {
// Block prompts containing banned words
let banned_words = ["spam", "malware", "hack"];
for word in banned_words {
if event.prompt.to_lowercase().contains(word) {
return Some(HookDecision::block(
format!("Content policy violation: contains '{}'", word)
));
}
}
None // Allow clean prompts
}§Example: Automatic Context Enhancement
use open_agent::{UserPromptSubmitEvent, HookDecision};
async fn add_context(event: UserPromptSubmitEvent) -> Option<HookDecision> {
// Add helpful context to every user prompt
let enhanced = format!(
"{}\n\n---\nContext: User timezone is UTC, current session started at 2025-11-07",
event.prompt
);
Some(HookDecision::modify_prompt(
enhanced,
"Added session context"
))
}§Example: Usage Tracking
use open_agent::{UserPromptSubmitEvent, HookDecision};
async fn track_usage(event: UserPromptSubmitEvent) -> Option<HookDecision> {
// Log every user interaction for analytics
println!(
"[ANALYTICS] User submitted prompt of {} characters at history depth {}",
event.prompt.len(),
event.history.len()
);
// Could also:
// - Update usage quotas
// - Send to analytics service
// - Check rate limits
None // Don't modify the prompt
}§Modification Behavior
If you return HookDecision::modify_prompt(), the modified prompt completely replaces
the original user input before the agent processes it. This is powerful but should be
used carefully to avoid confusing the user or the agent.
Fields§
§prompt: StringThe user’s original input prompt text
history: Vec<Value>Snapshot of conversation history (read-only) - does not include this prompt yet
Implementations§
Trait Implementations§
Source§impl Clone for UserPromptSubmitEvent
impl Clone for UserPromptSubmitEvent
Source§fn clone(&self) -> UserPromptSubmitEvent
fn clone(&self) -> UserPromptSubmitEvent
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for UserPromptSubmitEvent
impl RefUnwindSafe for UserPromptSubmitEvent
impl Send for UserPromptSubmitEvent
impl Sync for UserPromptSubmitEvent
impl Unpin for UserPromptSubmitEvent
impl UnwindSafe for UserPromptSubmitEvent
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