|
1 | 1 | from __future__ import annotations as _annotations |
2 | 2 |
|
3 | 3 | import os |
| 4 | +from collections.abc import Callable, Sequence |
4 | 5 | from importlib.util import find_spec |
5 | 6 | from pathlib import Path |
6 | | -from typing import TYPE_CHECKING |
| 7 | +from typing import TYPE_CHECKING, Any, TypeAlias, cast |
7 | 8 |
|
8 | 9 | from acp.schema import ModelInfo, SessionMode |
9 | 10 | from codex_auth_helper import create_codex_chat_openai |
|
19 | 20 |
|
20 | 21 | if TYPE_CHECKING: |
21 | 22 | from langchain_acp import CompiledAgentGraph |
| 23 | + from langchain_core.tools import BaseTool |
| 24 | + |
| 25 | +DeepAgentTool: TypeAlias = "BaseTool | Callable[..., Any] | dict[str, Any]" |
22 | 26 |
|
23 | 27 | __all__ = ( |
24 | 28 | "AVAILABLE_MODELS", |
@@ -167,7 +171,9 @@ def _session_workspace_root(session: AcpSessionContext) -> Path: |
167 | 171 | return session.cwd.resolve() / _SESSION_ROOT_NAME |
168 | 172 |
|
169 | 173 |
|
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]]: |
171 | 177 | del root |
172 | 178 |
|
173 | 179 | def _list_workspace_files() -> str: |
@@ -206,15 +212,16 @@ def graph_from_session(session: AcpSessionContext) -> CompiledAgentGraph: |
206 | 212 | mode_id = session.session_mode_id or DEFAULT_MODE_ID or "ask" |
207 | 213 | from deepagents import create_deep_agent |
208 | 214 |
|
| 215 | + tools: Sequence[DeepAgentTool] = [ |
| 216 | + *_bind_workspace_tools(workspace_root), |
| 217 | + *cast(Sequence[DeepAgentTool], native_plan_tools()), |
| 218 | + ] |
209 | 219 | return create_deep_agent( |
210 | 220 | model=create_codex_chat_openai( |
211 | 221 | model_name, |
212 | 222 | instructions=codex_instructions(mode_id=mode_id), |
213 | 223 | ), |
214 | | - tools=[ |
215 | | - *_bind_workspace_tools(workspace_root), |
216 | | - *native_plan_tools(), |
217 | | - ], # type: ignore[arg-type] |
| 224 | + tools=tools, |
218 | 225 | interrupt_on={"write_file": True}, |
219 | 226 | name=f"deepagents-{mode_id}-{session.cwd.name}", |
220 | 227 | ) |
|
0 commit comments