[Bug] DeepAgents plugin: `_build_bound_model` drops `bind_kwargs` (incl. `response_format`) on `bind()` → `bind_tools()` sequence
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
Línea de trabajo
Comienza en temporalio/contrib/deepagents/_activity.py, en _DeepAgentsActivities._build_bound_model, e inspecciona la secuencia bind() y luego bind_tools() descrita en el issue. Verifica que bind_kwargs, incluidos response_format y tool_choice, sigan asociados después de enlazar las herramientas. Se considera completado cuando la solicitud al proveedor conserva esos kwargs y sigue incluyendo los esquemas de las herramientas; añade o actualiza cobertura específica si el repositorio tiene tests para esta activity.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
What are you really trying to do?
Run a deep agent through the Temporal DeepAgents plugin (create_temporal_deep_agent) with a native structured output: response_format=ProviderStrategy(PydanticModel) against an OpenAI-compatible endpoint (in our case an LLM gateway proxying Azure OpenAI). The goal is a durable agent whose final answer is schema-validated JSON.
Describe the bug
response_format never reaches the provider: the worker-side activity _DeepAgentsActivities._build_bound_model (temporalio/contrib/deepagents/_activity.py) rebuilds the model as:
model = self._model_provider(input.model_name)
if input.bind_kwargs:
model = model.bind(**input.bind_kwargs) # response_format bound here
if input.tool_schemas:
model = model.bind_tools(input.tool_schemas)
In langchain-core, BaseChatModel.bind() returns a _ChatModelBinding (a RunnableBinding). That object has no bind_tools of its own, so attribute lookup delegates to the unbound model via RunnableBinding.__getattr__. The resulting binding therefore contains only tools: every kwarg from the earlier bind(**bind_kwargs) — including response_format — is silently dropped.
Consequence: the API request is sent with tools but without response_format, the model answers in free text/markdown, and langchain's ProviderStrategyBinding.parse fails with:
Failed to parse structured output for tool 'EmailNeed': Native structured output
expected valid JSON for EmailNeed, but parsing failed:
Expecting value: line 1 column 1 (char 0).
Note this is not limited to ProviderStrategy/response_format: any bind_kwargs is lost. With ToolStrategy, tool_choice="any" (which forces the structured-output tool call) travels the same path and is dropped too.
Evidence: the Temporal workflow history shows the activity input of deepagents.invoke_model containing bind_kwargs.response_format (so the workflow side correctly forwards it), while the provider request did not contain it — verified by replaying the exact bind() → bind_tools() sequence against the endpoint.
Minimal Reproduction
Pure langchain-core mechanism (no Temporal server needed):
from langchain_openai import ChatOpenAI
model = ChatOpenAI(model="...", api_key="...", base_url="https://...") # any OpenAI-compatible endpoint
response_format = {
"type": "json_schema",
"json_schema": {
"name": "EmailNeed",
"schema": {
"type": "object",
"properties": {"request": {"type": "string"}},
"required": ["request"],
},
},
}
tool = {
"type": "function",
"function": {
"name": "memory_recall",
"description": "search memory",
"parameters": {
"type": "object",
"properties": {"query": {"type": "string"}},
"required": ["query"],
},
},
}
# Sequence performed by _DeepAgentsActivities._build_bound_model
# (temporalio/contrib/deepagents/_activity.py)
final = model.bind(response_format=response_format).bind_tools([tool])
print(final.kwargs) # -> {'tools': [...]} ... response_format is gone
Full stack: a workflow created with create_temporal_deep_agent(..., response_format=ProviderStrategy(SomeModel)) against an OpenAI-compatible provider, run on a dev server with the worker-side model_provider returning a ChatOpenAI. The workflow fails on the final model call with the error above; the deepagents.invoke_model activity input in the event history contains bind_kwargs with response_format, proving it is lost worker-side.
Environment/Versions
- OS and processor: Linux x86_64
- SDK version: temporalio 1.33.0 (latest at time of writing;
mainstill contains the affected code), langchain 1.4.1, langchain-core 1.6.3, langchain-openai 1.6.2 - Temporal dev server via Docker Compose; worker + workflow run locally (not building from source)
Additional context
Suggested fix: reverse the two operations in _build_bound_model, since RunnableBinding.bind merges kwargs ({**self.kwargs, **kwargs}):
def _build_bound_model(self, input: ModelActivityInput) -> Any:
model = self._model_provider(input.model_name)
if input.tool_schemas:
model = model.bind_tools(input.tool_schemas)
if input.bind_kwargs:
model = model.bind(**input.bind_kwargs)
return model
(Alternatively, merge everything into a single bind.) The symptom is easy to misattribute to the LLM "ignoring" the response format, since the request succeeds — it just lacks the parameter.
Related upstream behavior worth noting for anyone hitting the next step: once response_format is actually forwarded, langchain-openai switches to chat.completions.parse(), which requires all tools to be strict; convert_to_openai_tool returns pre-formatted OpenAI tool dicts unchanged, so dict tool schemas are never strictified. We worked around both locally by overriding bind() to return a binding whose bind_tools merges the previously bound kwargs and strictifies dict tools when response_format is present.
- Lenguaje dominante
- Python
- Estrellas
- 1.2k
- Forks
- 245
- Merge medio
- 3 d 22 h
- PR fusionados (30 d)
- 42
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de temporalio/sdk-python
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
temporalio/sdk-python#1897 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
temporalio/sdk-python#496 ·
Los mantenedores suelen responder en 1 día
-
[Bug] Local activity resolutions regrouped on replay since 1.32.0, delivering the wrong payloadPosiblemente ocupada @Sushisource la tomó hace 2 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 52/100
temporalio/sdk-python#1881 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[Bug] Heartbeat Task Slot information is not pulled when MetricBuffer is configuredPosiblemente ocupada @Sushisource la tomó hace 22 días. Abiertobug
temporalio/sdk-python#1817 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Cloud CI Skips Nexus TestsQuizá libre de nuevo @tconley1428 la tomó hace 50 días y no hay ningún pull request abierto. Abierto
temporalio/sdk-python#1704 · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de temporalio/sdk-python
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
letsencrypt/cp-cps#353 ·
-
Marble Madness II is missingAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
PedestrianDynamics/pyFDS-Evac#394 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
DOI-USGS/pywatershed#421 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
python-pillow/Pillow#10087 · 1 comentario ·
Los mantenedores suelen responder en 1 día