Skip to content

Commit 97e1ccc

Browse files
committed
fix typecheck
1 parent 4722813 commit 97e1ccc

3 files changed

Lines changed: 37 additions & 22 deletions

File tree

examples/langchain/deepagents_graph.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from __future__ import annotations as _annotations
22

33
import os
4+
from collections.abc import Callable, Sequence
45
from importlib.util import find_spec
56
from pathlib import Path
6-
from typing import TYPE_CHECKING
7+
from typing import TYPE_CHECKING, Any, TypeAlias, cast
78

89
from acp.schema import ModelInfo, SessionMode
910
from codex_auth_helper import create_codex_chat_openai
@@ -19,6 +20,9 @@
1920

2021
if TYPE_CHECKING:
2122
from langchain_acp import CompiledAgentGraph
23+
from langchain_core.tools import BaseTool
24+
25+
DeepAgentTool: TypeAlias = "BaseTool | Callable[..., Any] | dict[str, Any]"
2226

2327
__all__ = (
2428
"AVAILABLE_MODELS",
@@ -167,7 +171,9 @@ def _session_workspace_root(session: AcpSessionContext) -> Path:
167171
return session.cwd.resolve() / _SESSION_ROOT_NAME
168172

169173

170-
def _bind_workspace_tools(root: Path) -> tuple[object, object, object]:
174+
def _bind_workspace_tools(
175+
root: Path,
176+
) -> tuple[Callable[[], str], Callable[[str], str], Callable[[str, str], str]]:
171177
del root
172178

173179
def _list_workspace_files() -> str:
@@ -206,15 +212,16 @@ def graph_from_session(session: AcpSessionContext) -> CompiledAgentGraph:
206212
mode_id = session.session_mode_id or DEFAULT_MODE_ID or "ask"
207213
from deepagents import create_deep_agent
208214

215+
tools: Sequence[DeepAgentTool] = [
216+
*_bind_workspace_tools(workspace_root),
217+
*cast(Sequence[DeepAgentTool], native_plan_tools()),
218+
]
209219
return create_deep_agent(
210220
model=create_codex_chat_openai(
211221
model_name,
212222
instructions=codex_instructions(mode_id=mode_id),
213223
),
214-
tools=[
215-
*_bind_workspace_tools(workspace_root),
216-
*native_plan_tools(),
217-
], # type: ignore[arg-type]
224+
tools=tools,
218225
interrupt_on={"write_file": True},
219226
name=f"deepagents-{mode_id}-{session.cwd.name}",
220227
)

packages/helpers/codex-auth-helper/src/codex_auth_helper/factory.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,21 @@ def create_codex_chat_openai(
9090
"`model_kwargs['instructions']`, not both."
9191
)
9292
chat_model_kwargs["instructions"] = instructions
93+
chat_openai_kwargs: dict[str, Any] = {
94+
"model": model_name,
95+
"async_client": async_root_client.chat.completions,
96+
"client": sync_root_client.chat.completions,
97+
"include_response_headers": include_response_headers,
98+
"model_kwargs": chat_model_kwargs,
99+
"output_version": output_version,
100+
"reasoning": reasoning,
101+
"root_async_client": async_root_client,
102+
"root_client": sync_root_client,
103+
"store": False,
104+
"temperature": temperature,
105+
"use_previous_response_id": use_previous_response_id,
106+
"use_responses_api": True,
107+
}
93108
return ChatOpenAI(
94-
model_name=model_name,
95-
async_client=async_root_client.chat.completions,
96-
client=sync_root_client.chat.completions,
97-
include_response_headers=include_response_headers,
98-
model_kwargs=chat_model_kwargs,
99-
output_version=output_version,
100-
reasoning=reasoning,
101-
root_async_client=async_root_client,
102-
root_client=sync_root_client,
103-
store=False,
104-
temperature=temperature,
105-
use_previous_response_id=use_previous_response_id,
106-
use_responses_api=True,
109+
**chat_openai_kwargs,
107110
)

tests/pydantic/test_models.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations as _annotations
22

33
import asyncio
4-
from typing import Any, cast
4+
from typing import Any, Protocol, cast
55

66
import pytest
77
from acp.exceptions import RequestError
@@ -42,6 +42,10 @@
4242
)
4343

4444

45+
class _AdapterWithConfig(Protocol):
46+
_config: Any
47+
48+
4549
def _passthrough_tools(
4650
ctx: RunContext[None],
4751
tool_defs: list[ToolDefinition],
@@ -460,7 +464,8 @@ def route_plan_progress(
460464
adapter.on_connect(client)
461465

462466
session = asyncio.run(adapter.new_session(cwd=str(tmp_path), mcp_servers=[]))
463-
stored_session = cast(Any, adapter)._config.session_store.get(session.session_id)
467+
adapter_config = cast(_AdapterWithConfig, adapter)._config
468+
stored_session = adapter_config.session_store.get(session.session_id)
464469
assert stored_session is not None
465470
stored_session.plan_markdown = "# Plan\n\n1. Implement the first item\n2. Verify it\n"
466471
stored_session.plan_entries = [
@@ -475,7 +480,7 @@ def route_plan_progress(
475480
status="pending",
476481
).model_dump(mode="json"),
477482
]
478-
cast(Any, adapter)._config.session_store.save(stored_session)
483+
adapter_config.session_store.save(stored_session)
479484
client.updates.clear()
480485

481486
asyncio.run(

0 commit comments

Comments
 (0)