Skip to content

Support extra args to llm invocations with prebuilt agents #5155

@yash025

Description

@yash025

Checked other resources

  • This is a bug, not a usage question. For questions, please use GitHub Discussions.
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

llm = ChatOpenAI(
            api_key="xyz",  # Placeholder, AuthN headers will be used
            base_url=base_url,
            timeout=300,
            max_retries=3,
            seed=111
        )

agent = create_react_agent(
            model=llm_manager.get_llm(),
            tools=filtered_tools,
            debug=False,
            prompt=system_prompt,
            pre_model_hook=summarization_node,  # Use SummarizationNode
            checkpointer=checkpointer,
        )
        response = await agent.ainvoke(
            {"messages": [HumanMessage(content=prompt)]},
            config=config,
            extra_headers=proxy_header,
        )

Error Message and Stack Trace (if applicable)

Description

  • I'm trying to pass additional args to agent which is used for all the llm calls, it don't work.
  • It works, if I directly do llm.ainvoke(prompt, extra_headers=proxy_header)
  • I have to create agent everytime now, for every request the agent receives.

System Info

langgraph = "0.3.31"
langchain-openai = "^0.3.4"
langchain-core = "^0.3.34"
langgraph-sdk = "^0.1.51"
jupyter = "^1.1.1"
langchain = "^0.3.18"
langfuse = "^2.59.2"
mcp = "^1.6.0"
langchain-mcp-adapters = "0.1.7"
langmem="0.0.27"

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions