Skip to content

Add Transient Model Input Context to RunConfig #5990

@nicolasmota

Description

@nicolasmota

Support Transient Per-Invocation Model Input Context

Required Information

Is your feature request related to a specific problem?

Yes.

Some host applications need to provide request-scoped context to an ADK agent for a single invocation without persisting that context into session.events.

Examples include:

  • User profile or entitlement context fetched at request time.
  • Notification or trigger metadata relevant only to the current turn.
  • External conversation summaries managed outside ADK.
  • Middleware-generated context that should guide the model but should not become part of durable conversation history.

Today, applications usually need to work around this by appending synthetic events to the session or by encoding extra context into the user message. Both options are undesirable:

  • Appending events pollutes persistent history and can affect future turns.
  • Encoding context into the user message mixes application metadata with end-user input.
  • Neither option clearly expresses "visible to the model for this invocation only".

Describe the Solution You'd Like

I would like ADK to expose a first-class way to pass transient model input context for a single runner invocation.

The API could live on RunConfig, for example as a field that accepts a list of google.genai.types.Content objects. These contents would be included when ADK builds the LLM request for the current invocation, but they would not be appended to session.events.

Expected behavior:

  • model_input_context is visible to the model during the current invocation.
  • It is not persisted in session history.
  • It remains stable across multiple LLM calls in the same invocation, including tool-call loops.
  • It works with include_contents="default" and include_contents="none".
  • It preserves normal session event semantics for actual user/model/tool events.

Impact on your work

This enables applications that manage request-scoped context outside ADK to pass that context into an agent safely, without mutating durable ADK session history.

In my use case, a service layer needs to inject contextual information into the agent flow while keeping the persisted session clean and representative of actual conversation events.

This is important for correctness, observability, replay, and session lifecycle behavior.

Willingness to contribute

Yes. I am willing to help contribute a focused implementation if maintainers agree this API belongs in ADK.


Recommended Information

Describe Alternatives You've Considered

  1. Appending synthetic events with SessionService.append_event()

    This makes the context visible to the model, but it persists the context into session.events. That is not appropriate for one-turn context and can affect future invocations.

  2. Prefixing the user message with context

    This keeps session history simpler, but it conflates application-provided context with the actual user input. It also requires every caller to implement its own formatting convention.

  3. Using get_session_config

    get_session_config controls which persisted events are fetched, but it does not provide a way to add non-persistent context to the current model input.

Proposed API / Implementation

One possible API shape:

from google.adk.agents.run_config import RunConfig
from google.genai import types

run_config = RunConfig(
    model_input_context=[
        types.UserContent("Relevant request-scoped context for this turn")
    ]
)

runner.run(
    user_id=user_id,
    session_id=session_id,
    new_message=types.UserContent("User question"),
    run_config=run_config,
)

Expected model input:

user: Relevant request-scoped context for this turn
user: User question

Expected persisted session events:

user: User question
model: Agent response

A possible implementation direction would be:

  • Add model_input_context: Optional[list[types.Content]] to RunConfig.
  • When building LlmRequest.contents, deep-copy and insert the transient context before the invocation user content.
  • Do not append these contents to session.events.
  • Keep instruction-related content insertion separate so transient context does not accidentally move after tool/function responses.

Additional Context

This should be covered by tests for:

  • Transient context is sent to the model and not persisted.
  • Transient context keeps its position across tool-call loops.
  • Transient context works with include_contents="none" in a multi-agent flow.
  • the selected API accepts transient types.Content values.

Metadata

Metadata

Labels

core[Component] This issue is related to the core interface and implementation
No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions