Skip to content

Llm

NormalizedChatGoogleGenerativeAI

Bases: ChatGoogleGenerativeAI


              flowchart TD
              src.tradingagents.llm.NormalizedChatGoogleGenerativeAI[NormalizedChatGoogleGenerativeAI]

              

              click src.tradingagents.llm.NormalizedChatGoogleGenerativeAI href "" "src.tradingagents.llm.NormalizedChatGoogleGenerativeAI"
            

Flatten Gemini 3 list-content responses to a plain string.

Gemini 3 returns message.content as [{'type': 'text', 'text': '...'}]; downstream prompt concatenation expects plain strings.

Methods:

Name Description
invoke

Invoke the chat model and normalize the response content.

invoke

invoke(prompt_input: object, config: object = None, **kwargs: object) -> object

Invoke the chat model and normalize the response content.

Parameters:

Name Type Description Default

prompt_input

object

The input prompt for the chat model.

required

config

object | None

Configuration for the invocation. Defaults to None.

None

**kwargs

object

Additional keyword arguments.

{}

Returns:

Name Type Description
object object

The chat response object with normalized string content.

Source code in src/tradingagents/llm.py
def invoke(self, prompt_input: object, config: object = None, **kwargs: object) -> object:
    """Invoke the chat model and normalize the response content.

    Args:
        prompt_input (object): The input prompt for the chat model.
        config (object | None, optional): Configuration for the invocation.
            Defaults to None.
        **kwargs (object): Additional keyword arguments.

    Returns:
        object: The chat response object with normalized string content.
    """
    response = super().invoke(prompt_input, config, **kwargs)
    content = response.content
    if isinstance(content, list):
        response.content = "\n".join(
            item["text"]
            if isinstance(item, dict) and item.get("type") == "text"
            else item
            if isinstance(item, str)
            else ""
            for item in content
        ).strip()
    return response