AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Create_agent With ProviderStrategy Binds Empty Tools List And Breaks OpenAI-Compatible Providers

When using create_agent(response_format=MySchema) without any user tools, LangChain's ProviderStrategy still calls model.bind_tools([]), sending an empty tools array to the provider. OpenAI-compatible providers such as vLLM v0.20.0+ reject this with 'tools must not be an empty array', causing agent invocation to fail.

highConfidence 85%LangChainAffected V1.2.13

Origin Analysis

ProviderStrategy in langchain.agents unconditionally binds the tools list, even when it is empty, instead of omitting tool binding or using provider-native structured output. The empty list is passed to model.bind_tools([]), which serializes to an invalid API payload for providers that validate that tools must contain at least one item or be omitted entirely.
1. Install langchain==1.2.13, langchain-openai==1.1.12, and use an OpenAI-compatible provider that rejects empty tools (e.g. vLLM v0.20.0+). 2. Run the following code: ```python from pydantic import BaseModel from langchain.agents import create_agent from langchain_openai import ChatOpenAI class MySchema(BaseModel): answer: str model = ChatOpenAI( model="...", base_url="http://openai-compatible-provider/v1", api_key="test", ) agent = create_agent( model=model, response_format=MySchema, ) agent.invoke({"messages": [{"role": "user", "content": "hello"}]}) ``` 3. Observe the error: {'error': ValueError('`tools` must not be an empty array. Either provide at least one tool or omit the field entirely.')}

Fixing Code Block

Edge Case Audit

This fix assumes the underlying model supports `with_structured_output`; if not, the fallback `model.bind(response_format=response_format)` may still fail or silently ignore the schema, causing unstructured responses. Providers with different structured output mechanisms (e.g. Anthropic) may require tool-calling style even without user tools. Rollback: revert this patch and temporarily provide a dummy tool as a workaround. Test with vLLM and other OpenAI-compatible backends before production deployment. The change is stateless per model binding and does not introduce concurrency or multi-threading issues, but upgrading langchain-core may alter BaseChatModel APIs (e.g., `bind_tools` signature), so keep this helper synchronized.

Ecosystem Topology