|
21 | 21 | from trpc_agent_sdk.context import InvocationContext |
22 | 22 |
|
23 | 23 | from .._base_code_executor import BaseCodeExecutor |
| 24 | +from .._base_code_executor import DEFAULT_CODE_BLOCK_DELIMITERS |
24 | 25 | from .._types import CodeBlock |
25 | 26 | from .._types import CodeBlockDelimiter |
26 | 27 | from .._types import CodeExecutionInput |
|
36 | 37 | _BASH_DELIMITER = CodeBlockDelimiter(start="```bash\n", end="\n```") |
37 | 38 |
|
38 | 39 |
|
39 | | -def _cube_default_code_block_delimiters() -> list[CodeBlockDelimiter]: |
40 | | - """Default delimiters for :class:`CubeCodeExecutor`. |
41 | | -
|
42 | | - Reuses :attr:`BaseCodeExecutor.code_block_delimiters` so the parent's |
43 | | - defaults (currently ``tool_code`` + ``python``) stay the single |
44 | | - source of truth, then appends a ``bash`` fence so text-path |
45 | | - extraction matches what :meth:`CubeCodeExecutor.execute_code` can |
46 | | - actually run (see :meth:`_select_interpreter`). Returns a fresh list |
47 | | - on every call to keep per-instance defaults independent of one |
48 | | - another. |
49 | | - """ |
50 | | - parent_default = BaseCodeExecutor.model_fields["code_block_delimiters"].default |
51 | | - return [*parent_default, _BASH_DELIMITER] |
52 | | - |
53 | | - |
54 | 40 | class CubeCodeExecutor(BaseCodeExecutor): |
55 | 41 | """A code executor that runs blocks inside a Cube/E2B remote sandbox. |
56 | 42 |
|
@@ -84,13 +70,8 @@ class CubeCodeExecutor(BaseCodeExecutor): |
84 | 70 | stateful: bool = Field(default=False, frozen=True, exclude=True) |
85 | 71 | optimize_data_file: bool = Field(default=False, frozen=True, exclude=True) |
86 | 72 |
|
87 | | - # Extend the inherited default with a ``bash`` fence so text-path |
88 | | - # extraction matches what ``execute_code`` can actually run (see |
89 | | - # ``_select_interpreter``). The factory reads the parent's default |
90 | | - # at call time so the base list stays the single source of truth; |
91 | | - # callers may still override via the ``code_block_delimiters`` field |
92 | | - # at construction time. |
93 | | - code_block_delimiters: list[CodeBlockDelimiter] = Field(default_factory=_cube_default_code_block_delimiters, ) |
| 73 | + code_block_delimiters: list[CodeBlockDelimiter] = Field( |
| 74 | + default_factory=lambda: [*DEFAULT_CODE_BLOCK_DELIMITERS, _BASH_DELIMITER]) |
94 | 75 |
|
95 | 76 | # `_client` is `Optional` because :meth:`close` / :meth:`destroy` |
96 | 77 | # legitimately drop the handle post-construction. `_cfg` has no such |
|
0 commit comments