Interface for loop interceptors that run after agent inference
Interceptors can inject or modify LLM message context to influence subsequent agent behavior (e.g., add tool results, error messages, continuation prompts).
description: string
Description of what this interceptor does
intercept(context: InterceptorContext): Promise<InterceptorResult>
Execute the interceptor's custom logic to influence agent behavior.
This method is called after the LLM generates a response. You are provided an InterceptorContext containing the conversation messages, LLM response, available tools, and other context. Use your custom logic to determine if the agent should continue or complete the loop.
Modifying Message Context: To influence subsequent agent behavior,
inject or modify messages in context.messages:
- Add new messages:
context.messages.push(newMessage)(auto-emits TaskMessageEvent) - Modify existing messages: Use unshift, splice, pop, shift, or direct assignment
Event Emission:
- If you modify existing message history, you MUST emit TaskHistoryChangedEvent
via
context.eventSubject.next({ type: "history_changed" })to notify that this interceptor changed the history - You MAY also emit custom events to meet your specific needs