GlobalInstructionPlugin

Prepends an app-wide instruction (such as a common identity or set of rules) to the system instruction of every model request so all agents in the app share it. Mirrors Python ADK's GlobalInstructionPlugin.

val company = GlobalInstructionPlugin("You work for Acme.")
val rules = GlobalInstructionPlugin({ context -> loadRules(context.userId) }, name = "rules")
InMemoryRunner(agent = agent, plugins = listOf(company, rules))

Constructors

Link copied to clipboard
constructor(globalInstruction: String, name: String = DEFAULT_NAME)

Creates a plugin that applies globalInstruction, filling in session state placeholders such as {user_name} for each request, as an agent's text instruction does. An instruction that resolves to an empty string leaves the request unchanged. If a placeholder names a missing state variable, beforeModel throws IllegalArgumentException unless the placeholder is marked optional, as in {nickname?}.

constructor(instructionProvider: suspend (ReadonlyContext) -> String?, name: String = DEFAULT_NAME)

Creates a plugin that applies the instruction instructionProvider returns for each request, with no placeholders filled in. A null or empty instruction leaves the request unchanged.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val name: String

The unique name of the plugin.

Functions

Link copied to clipboard
open suspend fun afterAgent(context: CallbackContext): CallbackChoice<Unit, Content>

Callback executed after a specific agent finishes its processing.

Link copied to clipboard
open suspend fun afterModel(context: CallbackContext, response: LlmResponse): LlmResponse

Callback executed after an LLM response is received.

Link copied to clipboard
open suspend fun afterRun(invocationContext: InvocationContext)

Callback executed after the ADK runner completes its execution, or after the caller stops collecting early (for example with first() or take(n)) or its collector throws.

Link copied to clipboard
open suspend fun afterTool(context: ToolContext, tool: BaseTool, args: Map<String, Any?>, result: Map<String, Any?>): Map<String, Any?>

Callback executed after a tool runs, or after a before-tool callback answers the call in its place.

Link copied to clipboard

Callback executed before a specific agent starts processing.

Link copied to clipboard
open suspend override fun beforeModel(context: CallbackContext, request: LlmRequest): CallbackChoice<LlmRequest, LlmResponse>

Callback executed before an LLM request is sent.

Link copied to clipboard
open suspend fun beforeRun(invocationContext: InvocationContext): CallbackChoice<Unit, Content>

Callback executed before the ADK runner starts the main execution loop.

Link copied to clipboard
open suspend fun beforeTool(context: ToolContext, tool: BaseTool, args: Map<String, Any?>): CallbackChoice<Map<String, Any?>, Map<String, Any?>>

Callback executed before a tool is invoked.

Link copied to clipboard
open override fun close()

Method executed when the runner is closed.

Link copied to clipboard
open suspend fun onEvent(invocationContext: InvocationContext, event: Event): Event

Callback executed when an event is yielded by an agent during execution.

Link copied to clipboard
open suspend fun onModelError(context: CallbackContext, request: LlmRequest, error: Throwable): CallbackChoice<Unit, LlmResponse>

Callback executed when an error occurs during an LLM interaction.

Link copied to clipboard
open suspend fun onRunError(invocationContext: InvocationContext, error: Throwable)

Callback executed when the ADK runner run fails, or when afterRun fails after the caller stopped collecting early.

Link copied to clipboard
open suspend fun onToolError(context: ToolContext, tool: BaseTool, args: Map<String, Any?>, error: Throwable): CallbackChoice<Unit, Map<String, Any?>>

Callback executed when an error occurs during a tool invocation.

Link copied to clipboard
open suspend fun onUserMessage(invocationContext: InvocationContext, userMessage: Content): Content

Callback executed when a user message is received before an invocation starts.