langflow icon indicating copy to clipboard operation
langflow copied to clipboard

Changing Agent Provider

Open orange472 opened this issue 1 year ago • 2 comments

Bug Description

Changing the provider of an Agent doesn't update the component fields.

For example, after selecting "Google Generative AI", the flow can not find certain attributes: Failed to initialize language model: Attribute max_output_tokens not found in AgentComponent.

The graph can not run as a result.

Reproduction

async def test_google_gen_agent(self):
    from langflow.components.agents import AgentComponent
    from langflow.components.inputs import ChatInput
    from langflow.components.outputs import ChatOutput
    from langflow.graph.graph.base import Graph

    GOOGLE_AI_API_KEY = os.getenv("GOOGLE_AI_API_KEY")
    self.assertIsNotNone(GOOGLE_AI_API_KEY)

    chatIn = ChatInput()
    chatIn.set(input_value="Hey Google")
    agent = AgentComponent()
    agent.set(input_value=chatIn.message_response)
    agent.set(**{"agent_llm": "Google Generative AI", "api_key": GOOGLE_AI_API_KEY})
    chatOut = ChatOutput(_id="output")
    chatOut.set(input_value=agent.message_response)

    graph = Graph(start=chatIn, end=chatOut)
    results = await graph.arun(inputs=[], outputs=["output"])

Expected behavior

The Agent class is updated with all necessary fields, such as "max_output_tokens" for the Google Generative AI Agent, and the graph is able to run with the selected agent provider.

Who can help?

No response

Operating System

macOS Sequoia 15.3.1

Langflow Version

1.4.1

Python Version

3.10

Screenshot

No response

Flow File

No response

orange472 avatar May 25 '25 21:05 orange472

The issue where changing the agent provider to "Google Generative AI" does not update the component fields—resulting in a missing max_output_tokens attribute—is likely due to the necessary provider-specific fields not being correctly included or updated in the AgentComponent's configuration when the provider is changed.

Here's what is happening:

  • The AgentComponent is designed to update its fields dynamically based on the selected provider, using logic in its update_build_config method. This method should add provider-specific fields (like max_output_tokens for Google Generative AI) and remove fields from other providers when you switch providers. This is managed through a structure like MODEL_PROVIDERS_DICT, which defines what fields each provider requires [source].
  • If the Google Generative AI provider's entry in MODEL_PROVIDERS_DICT does not include max_output_tokens in its fields, or if the update logic does not properly add these fields to the component's configuration, you will see errors like the one you described [source].

How to resolve:

  1. Check MODEL_PROVIDERS_DICT: Ensure that the entry for "Google Generative AI" includes all required fields, especially max_output_tokens, in its fields dictionary.

  2. Review update_build_config logic: Confirm that when you change the provider, the method correctly removes fields from the previous provider and adds all fields from the new provider. The relevant logic should look like this:

    if field_value in provider_configs:
        fields_to_add, fields_to_delete = provider_configs[field_value]
        for fields in fields_to_delete:
            self.delete_fields(build_config, fields)
        build_config.update(fields_to_add)
    

    This ensures that only the correct fields for the selected provider are present [source].

  3. Workaround: If you need an immediate fix, you can manually add the missing field(s) to the agent configuration after changing the provider, or ensure your code sets all required attributes for the selected provider.

Summary:
The missing max_output_tokens attribute is likely due to incomplete provider-specific field updates when switching to Google Generative AI. Review and update the provider configuration and the update logic to ensure all necessary fields are present for each provider. This should resolve the error and allow the graph to run as expected.

To continue talking to Dosu, mention @dosu-bot.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar May 25 '25 22:05 dosubot[bot]

Hi @orange472

Testing in version 1.6, this parameter exists, see:

Image

Could you please update to the latest version and check?

lice-reis avatar Oct 07 '25 13:10 lice-reis