Skip to content

Commit 434dffb

Browse files
authored
Update session.py
1 parent f2f1cf4 commit 434dffb

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

‎python_agent_harness/session.py‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
import threading
1515
import time
1616
from collections.abc import Callable
17-
from typing import Any
17+
from typing import TYPE_CHECKING, Any
1818

1919
from . import config
20-
from .client import Client
20+
from .client import Client, LLMClient
2121
from .mcp.config import MCPConfig
2222
from .mcp.manager import MCPManager
2323
from .models import AgentMode
@@ -31,6 +31,9 @@
3131
from .tools.filesystem import cleanup_spooled_files
3232
from .tools.mcp import mcp_tools_from_manager
3333

34+
if TYPE_CHECKING:
35+
from .tools.base import ToolRuntime
36+
3437

3538
def _tool_excluded(pattern: str, name: str) -> bool:
3639
"""True when *pattern* excludes tool *name*.
@@ -85,15 +88,15 @@ class Session:
8588
def __init__(
8689
self,
8790
project_dir: str,
88-
client: Client,
91+
client: LLMClient,
8992
model: str,
9093
system_prompt: str | None = None,
9194
subagent_system_prompt: str | None = None,
9295
temperature: float = config.TEMPERATURE,
9396
max_tokens: int | None = config.MAX_TOKENS,
9497
reasoning_effort: str | None = None,
9598
stream: bool = True,
96-
subagent_client: Client | None = None,
99+
subagent_client: LLMClient | None = None,
97100
subagent_temperature: float | None = None,
98101
subagent_max_tokens: int | None = None,
99102
subagent_reasoning_effort: str | None = None,
@@ -172,7 +175,7 @@ def __init__(
172175
# down a sibling's in-flight request on a shared client. The
173176
# active clones are tracked so cancel()/close() can reach them.
174177
self._subagent_clients_lock = threading.Lock()
175-
self._active_subagent_clients: list[Client] = []
178+
self._active_subagent_clients: list[LLMClient] = []
176179
# guards _skill_index_cache: parallel readonly tool threads
177180
# (e.g. multiple Skill calls in one round) can hit the lazy
178181
# cache build simultaneously — double-checked locking prevents
@@ -880,3 +883,13 @@ def summarize_conversation(self) -> str:
880883
self.last_messages.append(Msg(role="assistant", content=summary))
881884
self.auto_save(self.last_messages, self.system_prompt)
882885
return "Summary appended."
886+
887+
888+
if TYPE_CHECKING:
889+
# static conformance: Session must satisfy the ToolRuntime interface
890+
# that ToolContext proxies to (it is passed as ``ToolContext(self)``).
891+
# pyright fails here if Session ever drifts from that surface — e.g.
892+
# a renamed run_subagent — instead of the mismatch surfacing only as
893+
# a runtime AttributeError inside a tool.
894+
def _assert_session_is_tool_runtime(s: Session) -> ToolRuntime:
895+
return s

0 commit comments

Comments
 (0)