Skip to content

Commit bb9be16

Browse files
author
SentienceDEV
committed
fix circular import
1 parent 37eb0ce commit bb9be16

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

sentience/tools/context.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
if TYPE_CHECKING:
99
from ..agent_runtime import AgentRuntime
10-
11-
from .filesystem import FileSandbox
10+
from .filesystem import FileSandbox
1211

1312

1413
class BackendCapabilities(BaseModel):
@@ -38,12 +37,14 @@ class ToolContext:
3837
def __init__(
3938
self,
4039
runtime: AgentRuntime,
41-
files: FileSandbox | None = None,
40+
files: "FileSandbox" | None = None,
4241
base_dir: Path | None = None,
4342
) -> None:
4443
self.runtime = runtime
4544
if files is None:
4645
root = base_dir or (Path.cwd() / ".sentience" / "files")
46+
from .filesystem import FileSandbox
47+
4748
files = FileSandbox(root)
4849
self.files = files
4950

sentience/tools/filesystem.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
from pathlib import Path
44

55
from pydantic import BaseModel, Field
6+
from typing import TYPE_CHECKING
67

7-
from .context import ToolContext
8+
if TYPE_CHECKING:
9+
from .context import ToolContext
810
from .registry import ToolRegistry
911

1012

@@ -92,7 +94,7 @@ def register_filesystem_tools(
9294
) -> ToolRegistry:
9395
"""Register sandboxed filesystem tools."""
9496

95-
def _get_files(ctx: ToolContext | None) -> FileSandbox:
97+
def _get_files(ctx: "ToolContext" | None) -> FileSandbox:
9698
if ctx is not None:
9799
return ctx.files
98100
if sandbox is not None:
@@ -105,7 +107,7 @@ def _get_files(ctx: ToolContext | None) -> FileSandbox:
105107
output_model=ReadFileOutput,
106108
description="Read a file from the sandbox.",
107109
)
108-
async def read_file(ctx: ToolContext | None, params: ReadFileInput) -> ReadFileOutput:
110+
async def read_file(ctx: "ToolContext" | None, params: ReadFileInput) -> ReadFileOutput:
109111
files = _get_files(ctx)
110112
return ReadFileOutput(content=files.read_text(params.path))
111113

@@ -115,7 +117,7 @@ async def read_file(ctx: ToolContext | None, params: ReadFileInput) -> ReadFileO
115117
output_model=WriteFileOutput,
116118
description="Write a file to the sandbox.",
117119
)
118-
async def write_file(ctx: ToolContext | None, params: WriteFileInput) -> WriteFileOutput:
120+
async def write_file(ctx: "ToolContext" | None, params: WriteFileInput) -> WriteFileOutput:
119121
files = _get_files(ctx)
120122
written = files.write_text(params.path, params.content, overwrite=params.overwrite)
121123
return WriteFileOutput(path=params.path, bytes_written=written)
@@ -126,7 +128,7 @@ async def write_file(ctx: ToolContext | None, params: WriteFileInput) -> WriteFi
126128
output_model=AppendFileOutput,
127129
description="Append text to a file in the sandbox.",
128130
)
129-
async def append_file(ctx: ToolContext | None, params: AppendFileInput) -> AppendFileOutput:
131+
async def append_file(ctx: "ToolContext" | None, params: AppendFileInput) -> AppendFileOutput:
130132
files = _get_files(ctx)
131133
written = files.append_text(params.path, params.content)
132134
return AppendFileOutput(path=params.path, bytes_written=written)
@@ -137,7 +139,7 @@ async def append_file(ctx: ToolContext | None, params: AppendFileInput) -> Appen
137139
output_model=ReplaceFileOutput,
138140
description="Replace text in a file in the sandbox.",
139141
)
140-
async def replace_file(ctx: ToolContext | None, params: ReplaceFileInput) -> ReplaceFileOutput:
142+
async def replace_file(ctx: "ToolContext" | None, params: ReplaceFileInput) -> ReplaceFileOutput:
141143
files = _get_files(ctx)
142144
replaced = files.replace_text(params.path, params.old, params.new)
143145
return ReplaceFileOutput(path=params.path, replaced=replaced)

0 commit comments

Comments
 (0)