Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions core/src/main/java/com/google/adk/agents/Callbacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,33 @@ public interface AfterModelCallback extends AfterModelCallbackBase {
Maybe<LlmResponse> call(CallbackContext callbackContext, LlmResponse llmResponse);
}

/** An extended callback interface for streaming LLM responses. */
public interface StreamingAfterModelCallback extends AfterModelCallback {
/**
* Invoked repeatedly for each significant chunk during a live stream.
*
* @param callbackContext Callback context.
* @param llmResponse LLM response chunk.
* @return modified response chunk, or empty to keep original.
*/
Maybe<LlmResponse> callInStream(CallbackContext callbackContext, LlmResponse llmResponse);

/**
* Invoked once at turn completion.
*
* @param callbackContext Callback context.
* @param finalResponse The final, aggregated LLM response.
* @return modified final response, or empty to keep original.
*/
Maybe<LlmResponse> callAtStreamEnd(CallbackContext callbackContext, LlmResponse finalResponse);

/** Defaults to the end-of-stream behavior. */
@Override
default Maybe<LlmResponse> call(CallbackContext callbackContext, LlmResponse llmResponse) {
return callAtStreamEnd(callbackContext, llmResponse);
}
}

/**
* Helper interface to allow for sync afterModelCallback. The function is wrapped into an async
* one before being processed further.
Expand Down