pub struct CustomTaskHandler { /* private fields */ }Expand description
TaskHandler that injects a custom prompt into the agent loop.
When a TaskKind::Custom task is due, CustomTaskHandler
reads the "task" field from the task’s JSON config, sanitises it with
crate::sanitize_task_prompt_checked, and sends the resulting string on the
provided mpsc::Sender. The agent loop receives the prompt and processes it as a
new user message.
Sending is best-effort: if the channel is full or closed, the error is logged at
warn level and Ok(()) is returned so the scheduler continues running.
Injection pattern detection: if the prompt contains a known injection marker,
SchedulerError::PromptInjectionBlocked is returned and no message is sent.
§Examples
use tokio::sync::mpsc;
use zeph_scheduler::CustomTaskHandler;
let (tx, mut rx) = mpsc::channel(8);
let handler = CustomTaskHandler::new(tx);
use zeph_scheduler::TaskHandler;
handler
.execute(&serde_json::json!({"task": "Generate a daily report"}))
.await
.expect("handler should not fail");
let prompt = rx.recv().await.unwrap();
assert_eq!(prompt, "Generate a daily report");Implementations§
Source§impl CustomTaskHandler
impl CustomTaskHandler
Sourcepub fn new(tx: Sender<String>) -> Self
pub fn new(tx: Sender<String>) -> Self
Create a new handler that sends prompts on tx.
task_name is included in SchedulerError::PromptInjectionBlocked when
an injection pattern is detected, enabling structured log correlation.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CustomTaskHandler
impl RefUnwindSafe for CustomTaskHandler
impl Send for CustomTaskHandler
impl Sync for CustomTaskHandler
impl Unpin for CustomTaskHandler
impl UnsafeUnpin for CustomTaskHandler
impl UnwindSafe for CustomTaskHandler
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more