pub struct FileCallbackHandler {
pub color: Option<String>,
/* private fields */
}Expand description
Callback Handler that writes to a file.
This handler supports writing callback output to a file. It can be used to log chain execution to a file for debugging or auditing purposes.
§Example
ⓘ
use agent_chain_core::callbacks::FileCallbackHandler;
// Using with mode string (recommended, matches Python API)
let handler = FileCallbackHandler::with_mode("output.txt", "a")?;
// Using with append boolean
let handler = FileCallbackHandler::new("output.txt", false)?;Fields§
§color: Option<String>The color to use for the text (not used for file output but kept for API compatibility).
Implementations§
Source§impl FileCallbackHandler
impl FileCallbackHandler
Sourcepub fn with_color<P: AsRef<Path>>(
filename: P,
mode: &str,
color: impl Into<String>,
) -> Result<Self>
pub fn with_color<P: AsRef<Path>>( filename: P, mode: &str, color: impl Into<String>, ) -> Result<Self>
Create a new FileCallbackHandler with a specific color.
§Arguments
filename- Path to the output file.mode- File open mode (e.g., “w”, “a”). Defaults to “a”.color- Default text color for output.
Trait Implementations§
Source§impl BaseCallbackHandler for FileCallbackHandler
impl BaseCallbackHandler for FileCallbackHandler
Source§fn name(&self) -> &str
fn name(&self) -> &str
Get a unique name for this handler.
Note: This is a Rust-specific addition for debugging purposes.
Source§fn raise_error(&self) -> bool
fn raise_error(&self) -> bool
Whether to raise an error if an exception occurs.
Source§fn run_inline(&self) -> bool
fn run_inline(&self) -> bool
Whether to run the callback inline.
Source§fn ignore_llm(&self) -> bool
fn ignore_llm(&self) -> bool
Whether to ignore LLM callbacks.
Source§fn ignore_retry(&self) -> bool
fn ignore_retry(&self) -> bool
Whether to ignore retry callbacks.
Source§fn ignore_chain(&self) -> bool
fn ignore_chain(&self) -> bool
Whether to ignore chain callbacks.
Source§fn ignore_agent(&self) -> bool
fn ignore_agent(&self) -> bool
Whether to ignore agent callbacks.
Source§fn ignore_retriever(&self) -> bool
fn ignore_retriever(&self) -> bool
Whether to ignore retriever callbacks.
Source§fn ignore_chat_model(&self) -> bool
fn ignore_chat_model(&self) -> bool
Whether to ignore chat model callbacks.
Source§fn ignore_custom_event(&self) -> bool
fn ignore_custom_event(&self) -> bool
Whether to ignore custom events.
Source§impl CallbackManagerMixin for FileCallbackHandler
impl CallbackManagerMixin for FileCallbackHandler
Source§fn on_chain_start(
&mut self,
serialized: &HashMap<String, Value>,
_inputs: &HashMap<String, Value>,
_run_id: Uuid,
_parent_run_id: Option<Uuid>,
_tags: Option<&[String]>,
metadata: Option<&HashMap<String, Value>>,
)
fn on_chain_start( &mut self, serialized: &HashMap<String, Value>, _inputs: &HashMap<String, Value>, _run_id: Uuid, _parent_run_id: Option<Uuid>, _tags: Option<&[String]>, metadata: Option<&HashMap<String, Value>>, )
Run when a chain starts running.
Source§fn on_llm_start(
&mut self,
serialized: &HashMap<String, Value>,
prompts: &[String],
run_id: Uuid,
parent_run_id: Option<Uuid>,
tags: Option<&[String]>,
metadata: Option<&HashMap<String, Value>>,
)
fn on_llm_start( &mut self, serialized: &HashMap<String, Value>, prompts: &[String], run_id: Uuid, parent_run_id: Option<Uuid>, tags: Option<&[String]>, metadata: Option<&HashMap<String, Value>>, )
Run when LLM starts running.
Source§fn on_chat_model_start(
&mut self,
serialized: &HashMap<String, Value>,
messages: &[Vec<BaseMessage>],
run_id: Uuid,
parent_run_id: Option<Uuid>,
tags: Option<&[String]>,
metadata: Option<&HashMap<String, Value>>,
)
fn on_chat_model_start( &mut self, serialized: &HashMap<String, Value>, messages: &[Vec<BaseMessage>], run_id: Uuid, parent_run_id: Option<Uuid>, tags: Option<&[String]>, metadata: Option<&HashMap<String, Value>>, )
Run when a chat model starts running.
Source§impl ChainManagerMixin for FileCallbackHandler
impl ChainManagerMixin for FileCallbackHandler
Source§fn on_agent_action(
&mut self,
action: &Value,
_run_id: Uuid,
_parent_run_id: Option<Uuid>,
_color: Option<&str>,
)
fn on_agent_action( &mut self, action: &Value, _run_id: Uuid, _parent_run_id: Option<Uuid>, _color: Option<&str>, )
Handle agent action by writing the action log.
Source§fn on_agent_finish(
&mut self,
finish: &Value,
_run_id: Uuid,
_parent_run_id: Option<Uuid>,
_color: Option<&str>,
)
fn on_agent_finish( &mut self, finish: &Value, _run_id: Uuid, _parent_run_id: Option<Uuid>, _color: Option<&str>, )
Handle agent finish by writing the finish log.
Source§impl Debug for FileCallbackHandler
impl Debug for FileCallbackHandler
Source§impl Drop for FileCallbackHandler
impl Drop for FileCallbackHandler
Source§impl LLMManagerMixin for FileCallbackHandler
impl LLMManagerMixin for FileCallbackHandler
Source§fn on_llm_new_token(
&mut self,
token: &str,
run_id: Uuid,
parent_run_id: Option<Uuid>,
chunk: Option<&Value>,
)
fn on_llm_new_token( &mut self, token: &str, run_id: Uuid, parent_run_id: Option<Uuid>, chunk: Option<&Value>, )
Run on new output token. Only available when streaming is enabled.
Source§fn on_llm_end(
&mut self,
response: &ChatResult,
run_id: Uuid,
parent_run_id: Option<Uuid>,
)
fn on_llm_end( &mut self, response: &ChatResult, run_id: Uuid, parent_run_id: Option<Uuid>, )
Run when LLM ends running.
Source§impl RunManagerMixin for FileCallbackHandler
impl RunManagerMixin for FileCallbackHandler
Auto Trait Implementations§
impl Freeze for FileCallbackHandler
impl RefUnwindSafe for FileCallbackHandler
impl Send for FileCallbackHandler
impl Sync for FileCallbackHandler
impl Unpin for FileCallbackHandler
impl UnwindSafe for FileCallbackHandler
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