instrukt.agent.callback.InstruktCallbackHandler

class instrukt.agent.callback.InstruktCallbackHandler(*, ctx: Context)[source]

Bases: AsyncCallbackHandler, RetrieverManagerMixin, BaseModel

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param ctx: Context [Required]
async on_agent_action(action: AgentAction, **kwargs: Any) Any[source]

Run on agent action.

async on_agent_finish(finish: AgentFinish, **kwargs: Any) Any[source]

Run on agent end.

async on_chain_end(outputs: Dict[str, Any], **kwargs: Any) Any[source]

Run when chain ends running.

async on_chain_error(error: Exception | KeyboardInterrupt, **kwargs: Any) Any[source]

Run when chain errors.

async on_chain_start(serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any) Any[source]

Run when chain starts running.

async on_chat_model_start(serialized: Dict[str, Any], messages: List[List[BaseMessage]], *, run_id: UUID, parent_run_id: UUID | None = None, tags: List[str] | None = None, metadata: Dict[str, Any] | None = None, **kwargs: Any) Any

Run when a chat model starts running.

async on_llm_end(response: LLMResult, **kwargs: Any) Any[source]

Run when LLM ends running.

async on_llm_error(error: Exception | KeyboardInterrupt, **kwargs: Any) Any[source]

Run when LLM errors.

async on_llm_new_token(token: str, **kwargs: Any) Any[source]

Run on new LLM token. Only available when streaming is enabled.

async on_llm_start(serialized: Dict[str, Any], prompts: List[str], **kwargs: Any) Any[source]

Run when LLM starts running.

async on_retriever_end(documents: Sequence[Document], *, run_id: UUID, parent_run_id: UUID | None = None, **kwargs: Any) Any[source]

Run on retriever end.

async on_retriever_error(error: Exception | KeyboardInterrupt, *, run_id: UUID, parent_run_id: UUID | None = None, tags: List[str] | None = None, **kwargs: Any) None

Run on retriever error.

async on_retriever_start(serialized: Dict[str, Any], query: str, *, run_id: UUID, parent_run_id: UUID | None = None, tags: List[str] | None = None, metadata: Dict[str, Any] | None = None, **kwargs: Any) None

Run on retriever start.

async on_retry(retry_state: RetryCallState, *, run_id: UUID, parent_run_id: UUID | None = None, **kwargs: Any) Any

Run on a retry event.

async on_text(text: str, **kwargs: Any) Any[source]

Run on arbitrary text.

async on_tool_end(output: str, observation_prefix: str | None = None, llm_prefix: str | None = None, name: str = '', **kwargs: Any) Any[source]

Run when tool ends running.

async on_tool_error(error: Exception | KeyboardInterrupt, **kwargs: Any) Any[source]

Run when tool errors.

async on_tool_start(serialized: Dict[str, Any], input_str: str, **kwargs: Any) Any[source]

Run when tool starts running.

property ignore_agent: bool

Whether to ignore agent callbacks.

property ignore_chain: bool

Whether to ignore chain callbacks.

property ignore_chat_model: bool

Whether to ignore chat model callbacks.

property ignore_llm: bool

Whether to ignore LLM callbacks.

property ignore_retriever: bool

Whether to ignore retriever callbacks.

property ignore_retry: bool

Whether to ignore retry callbacks.

raise_error: bool = False
run_inline: bool = False
model Config[source]

Bases: object

arbitrary_types_allowed = True