• Injects session state values into an instruction template.

    This method is intended to be used in InstructionProvider based instruction and global_instruction which are called with readonly_context.

    Example:

    import { injectSessionState } from './utils/instructions-utils';

    async function buildInstruction(readonlyContext: ReadonlyContext): Promise<string> {
    return await injectSessionState(
    'You can inject a state variable like {var_name} or an artifact ' +
    '{artifact.file_name} into the instruction template.',
    readonlyContext
    );
    }

    const agent = new LlmAgent({
    model: "gemini-2.0-flash",
    name: "agent",
    instruction: buildInstruction,
    });

    Parameters

    • template: string

      The instruction template with {variable} placeholders

    • readonlyContext: ReadonlyContext

      The read-only context containing session data

    Returns Promise<string>

    The instruction template with values populated