Skip to content

Conversation

@copybara-service
Copy link

feat: Adding OnModelErrorCallback

This Changelist (CL) introduces new error handling mechanisms for LLM model calls and tool invocations within the Agent Development Kit.

Specifically, it adds:

  • OnModelErrorCallback: An interface for handling errors that occur during an LLM model call.
  • OnToolErrorCallback: An interface for handling errors during a tool invocation.

These callbacks allow for asynchronous or synchronous handling of errors, providing an opportunity to override the error with a custom response or result. The LlmAgent class is updated to support these new callbacks, and they are integrated into BaseLlmFlow and Functions to be triggered upon model or tool failures, respectively. Plugin-defined error callbacks are given precedence over agent-defined ones.

Additionally, the CL introduces canonical methods (canonicalBeforeAgentCallbacks, canonicalAfterAgentCallbacks, etc.) to BaseAgent and LlmAgent to simplify accessing callback lists, and updates Javadoc for existing callback interfaces. New tests are included to verify the functionality and precedence of the error callbacks.

This Changelist (CL) introduces new error handling mechanisms for LLM model calls and tool invocations within the Agent Development Kit.

Specifically, it adds:
*   **`OnModelErrorCallback`**: An interface for handling errors that occur during an LLM model call.
*   **`OnToolErrorCallback`**: An interface for handling errors during a tool invocation.

These callbacks allow for asynchronous or synchronous handling of errors, providing an opportunity to override the error with a custom response or result. The `LlmAgent` class is updated to support these new callbacks, and they are integrated into `BaseLlmFlow` and `Functions` to be triggered upon model or tool failures, respectively. Plugin-defined error callbacks are given precedence over agent-defined ones.

Additionally, the CL introduces `canonical` methods (`canonicalBeforeAgentCallbacks`, `canonicalAfterAgentCallbacks`, etc.) to `BaseAgent` and `LlmAgent` to simplify accessing callback lists, and updates Javadoc for existing callback interfaces. New tests are included to verify the functionality and precedence of the error callbacks.

PiperOrigin-RevId: 858648691
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant