Repository: google/adk-go
File: agent/llmagent/llmagent.go (Go)

Code before:
	// The first callback that returns non-nil LLMResponse/error makes
	// LLMAgent **skip** the actual model call and yields the callback result
	// instead.
	//
	// This provides an opportunity to inspect, log, or modify the `LLMRequest`
	// object. It can also be used to implement caching by returning a cached
	// `LLMResponse`, which would skip the actual model call.
	BeforeModel []BeforeModelCallback
	Model       llm.Model
	// AfterModel callbacks are executed sequentially right after a response is
	// received from the model.
	//
	// The first callback that returns non-nil LLMResponse/error **replaces**
	// the actual model response/error and stops execution of the remaining
	// callbacks.
	//
	// This is the ideal place to log model responses, collect metrics on token
	// usage, or perform post-processing on the raw `LLMResponse`.
	AfterModel []AfterModelCallback

	// Instruction is set for the LLM model guiding the agent's behavior.
	//
	// These instructions can contain placeholders like {variable_name} that
	// will be resolved at runtime using session state and context.
	//
	// {var} is used to insert the value of the state variable named var.
	// {artifact.var} is used to insert the text content of the artifact named var.
	// State key identifier should be match "^[a-zA-Z_][a-zA-Z0-9_]*$".
	// Otherwise it will be treated as a literal.
	//
	// If the state variable or artifact does not exist, the agent will raise an
	// error. If you want to ignore the error, you can append a ? to the
	// variable name as in {var?}.
	Instruction string
	// InstructionProvider allows to create instructions dynamically based on
	// the agent context.
	//
	// It takes precedence over the Instruction field if both are set.
	//
	// When InstructionProvider is used, ADK will NOT inject session state
	// placeholders into the instruction. You can use
	// llmagent.InjectSessionState() helper for that.
	InstructionProvider InstructionProvider

	// GlobalInstruction is the instruction for all agents in the entire
	// agent tree.
	//
	// ONLY the GlobalInstruction in the root agent will take effect.
	//
	// For example: GlobalInstruction can make all agents have a stable identity
	// or personality.

Review comment (suggestion):
Godoc rendering is pretty limited compared to markdown, but I think this paragraph will read better if "lists" syntax is used instead of one continued paragraph. https://tip.golang.org/doc/comment#lists 

Code after:

	a.Agent = baseAgent
	a.AgentType = agentinternal.TypeLLMAgent

	return a, nil
}

type Config struct {
	Name        string
	Description string
	SubAgents   []agent.Agent

	BeforeAgentCallbacks []agent.BeforeAgentCallback
	AfterAgentCallbacks  []agent.AfterAgentCallback

	GenerateContentConfig *genai.GenerateContentConfig

	// BeforeModelCallbacks are executed sequentially right before a request is
	// sent to the model.
	//
	// The first callback that returns non-nil LLMResponse/error makes
	// LLMAgent **skip** the actual model call and yields the callback result
	// instead.
	//
	// This provides an opportunity to inspect, log, or modify the `LLMRequest`
	// object. It can also be used to implement caching by returning a cached
	// `LLMResponse`, which would skip the actual model call.
	BeforeModelCallbacks []BeforeModelCallback
	Model                model.LLM
	// AfterModelCallbacks are executed sequentially right after a response is
	// received from the model.
	//
	// The first callback that returns non-nil LLMResponse/error **replaces**
	// the actual model response/error and stops execution of the remaining
	// callbacks.
	//
	// This is the ideal place to log model responses, collect metrics on token
	// usage, or perform post-processing on the raw `LLMResponse`.
	AfterModelCallbacks []AfterModelCallback

	// Instruction is set for the LLM model guiding the agent's behavior.
	//
	// The string is treated as a template:
	//  - There can be placeholders like {key_name} that will be resolved by ADK
	//    at runtime using session state and context.
	//  - key_name must match "^[a-zA-Z_][a-zA-Z0-9_]*$", otherwise it will be
	//    treated as a literal.
	//  - {artifact.key_name} can be used to insert the text content of the
	//    artifact named key_name.
	//
	// If the state variable or artifact does not exist, the agent will raise an