agents icon indicating copy to clipboard operation
agents copied to clipboard

add_to_chat_ctx Parameter in generate_reply

Open narendra-bluebash opened this issue 3 weeks ago • 1 comments

Feature Type

Would make my life easier

Feature Description

Feature Request: Add add_to_chat_ctx_user and add_to_chat_ctx_assistant Parameters in generate_reply

Summary: Introduce two new optional boolean parameters, add_to_chat_ctx_user and add_to_chat_ctx_assistant, in the generate_reply method of the AgentSession class. These flags will control whether the respective user and assistant messages are appended to the internal chat context.

Motivation / Use Case: Currently, both user inputs and assistant replies are automatically added to the chat context. However, in some cases — such as when performing silent reasoning, system-internal calls, or generating ephemeral outputs — it’s useful to generate replies without updating parts of the context.

Proposed Change:

  • Update the method signature to include:

    async def generate_reply(
        self,
        add_to_chat_ctx_user: bool = True,
        add_to_chat_ctx_assistant: bool = True,
        ...
    ):
    
  • Default values ensure backward compatibility (both remain True by default).

  • When either flag is False, the respective message (user or assistant) should not be appended to the internal chat context.

Benefits:

  • Allows selective control of context updates.
  • Prevents context pollution during background tasks or tool invocations.
  • Enables ephemeral reasoning, one-off response previews, and internal message generation without altering the conversation state.

Example Usage:

# Generate a temporary system reply without adding it to chat context
reply = await session.generate_reply(
    input="Summarize the conversation so far",
    add_to_chat_ctx_user=False,
    add_to_chat_ctx_assistant=False
)

Expected Outcome: The assistant generates and returns the reply, but neither the user input nor the assistant response is stored in the session’s conversation context.

Workarounds / Alternatives

No response

Additional Context

No response

narendra-bluebash avatar Nov 13 '25 07:11 narendra-bluebash