Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Bug] DeepAgents plugin: `_build_bound_model` drops `bind_kwargs` (incl. `response_format`) on `bind()` → `bind_tools()` sequence

未关闭 适合新手
#1,896 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

从 temporalio/contrib/deepagents/_activity.py 中的 _DeepAgentsActivities._build_bound_model 开始,检查 issue 中描述的 bind() 然后 bind_tools() 序列。验证在绑定工具后,bind_kwargs(包括 response_format 和 tool_choice)仍然保持附加状态。完成的标准是 provider request 保留这些 kwargs,同时仍包含 tool schemas;如果 repository 中有针对该 activity 的测试,请添加或更新有针对性的覆盖。

由索引模型根据 Issue 内容生成。

描述

bug
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; main still 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.

主要语言
Python
星标
1.2k
派生
245
平均合并
2 天 17 小时
30 天内合并 PR
38

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

temporalio/sdk-python 的其他 Issue

查看 temporalio/sdk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。