MCPcopy Create free account
hub / github.com/AI45Lab/Code / fire_pre_prompt

Method fire_pre_prompt

core/src/agent/turn_context.rs:404–427  ·  view source on GitHub ↗

Fire PrePrompt hook event before prompt augmentation. Returns optional modified prompt text from the hook.

(
        &self,
        session_id: &str,
        prompt: &str,
        system_prompt: &Option<String>,
        message_count: usize,
    )

Source from the content-addressed store, hash-verified

402 /// Fire PrePrompt hook event before prompt augmentation.
403 /// Returns optional modified prompt text from the hook.
404 async fn fire_pre_prompt(
405 &self,
406 session_id: &str,
407 prompt: &str,
408 system_prompt: &Option<String>,
409 message_count: usize,
410 ) -> Option<String> {
411 if let Some(he) = &self.config.hook_engine {
412 let event = HookEvent::PrePrompt(PrePromptEvent {
413 session_id: session_id.to_string(),
414 prompt: prompt.to_string(),
415 system_prompt: system_prompt.clone(),
416 message_count,
417 });
418 let result = he.fire(&event).await;
419 if let HookResult::Continue(Some(modified)) = result {
420 // Extract modified prompt from hook response
421 if let Some(new_prompt) = modified.get("prompt").and_then(|v| v.as_str()) {
422 return Some(new_prompt.to_string());
423 }
424 }
425 }
426 None
427 }
428}
429
430/// Render the always-on `<env>` grounding block.

Callers 1

prepare_turn_contextMethod · 0.80

Calls 4

cloneMethod · 0.45
fireMethod · 0.45
getMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected