mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-30 03:00:41 -04:00
refactor(backend/copilot): remove unused cwd param from get_sdk_supplement
The cwd argument was already ignored (del cwd on entry) — kept only for call-site compatibility. Remove it entirely and update all three call sites: sdk/service.py, sdk/service_test.py, and test/copilot/dry_run_loop_test.py.
This commit is contained in:
@@ -334,7 +334,7 @@ def _generate_tool_documentation() -> str:
|
||||
_LOCAL_STORAGE_SUPPLEMENT: str | None = None
|
||||
|
||||
|
||||
def get_sdk_supplement(use_e2b: bool, cwd: str = "") -> str:
|
||||
def get_sdk_supplement(use_e2b: bool) -> str:
|
||||
"""Get the supplement for SDK mode (Claude Agent SDK).
|
||||
|
||||
SDK mode does NOT include tool documentation because Claude automatically
|
||||
@@ -352,12 +352,10 @@ def get_sdk_supplement(use_e2b: bool, cwd: str = "") -> str:
|
||||
|
||||
Args:
|
||||
use_e2b: Whether E2B cloud sandbox is being used
|
||||
cwd: Unused — kept for call-site compatibility.
|
||||
|
||||
Returns:
|
||||
The supplement string to append to the system prompt
|
||||
"""
|
||||
del cwd # intentionally unused — see docstring
|
||||
if use_e2b:
|
||||
return _get_cloud_sandbox_supplement()
|
||||
global _LOCAL_STORAGE_SUPPLEMENT
|
||||
|
||||
@@ -16,18 +16,13 @@ class TestGetSdkSupplementStaticPlaceholder:
|
||||
importlib.reload(prompting)
|
||||
|
||||
def test_local_mode_uses_placeholder_not_uuid(self):
|
||||
result = prompting.get_sdk_supplement(
|
||||
use_e2b=False, cwd="/tmp/copilot-real-uuid"
|
||||
)
|
||||
result = prompting.get_sdk_supplement(use_e2b=False)
|
||||
assert "/tmp/copilot-<session-id>" in result
|
||||
assert "real-uuid" not in result
|
||||
|
||||
def test_local_mode_is_idempotent(self):
|
||||
first = prompting.get_sdk_supplement(use_e2b=False, cwd="/tmp/a")
|
||||
second = prompting.get_sdk_supplement(use_e2b=False, cwd="/tmp/b")
|
||||
assert (
|
||||
first == second
|
||||
), "Supplement must be identical regardless of cwd argument"
|
||||
first = prompting.get_sdk_supplement(use_e2b=False)
|
||||
second = prompting.get_sdk_supplement(use_e2b=False)
|
||||
assert first == second, "Supplement must be identical across calls"
|
||||
|
||||
def test_e2b_mode_uses_home_user(self):
|
||||
result = prompting.get_sdk_supplement(use_e2b=True)
|
||||
|
||||
@@ -419,7 +419,7 @@ async def _reduce_context(
|
||||
# Subsequent retry or compaction failed: drop transcript entirely.
|
||||
# Return retry_target so the caller compresses DB messages to that budget.
|
||||
logger.warning(
|
||||
"%s Dropping transcript, rebuilding from DB messages" " (target_tokens=%d)",
|
||||
"%s Dropping transcript, rebuilding from DB messages (target_tokens=%d)",
|
||||
log_prefix,
|
||||
retry_target,
|
||||
)
|
||||
@@ -1161,7 +1161,7 @@ async def _build_query_message(
|
||||
history_context = _format_conversation_context(compressed)
|
||||
if history_context:
|
||||
logger.info(
|
||||
"[SDK] [%s] Fallback context built: compressed=%s," " context_bytes=%d",
|
||||
"[SDK] [%s] Fallback context built: compressed=%s, context_bytes=%d",
|
||||
session_id[:8],
|
||||
was_compressed,
|
||||
len(history_context),
|
||||
@@ -2358,7 +2358,7 @@ async def stream_chat_completion_sdk(
|
||||
graphiti_supplement = get_graphiti_supplement() if graphiti_enabled else ""
|
||||
system_prompt = (
|
||||
base_system_prompt
|
||||
+ get_sdk_supplement(use_e2b=use_e2b, cwd=sdk_cwd)
|
||||
+ get_sdk_supplement(use_e2b=use_e2b)
|
||||
+ graphiti_supplement
|
||||
)
|
||||
|
||||
|
||||
@@ -165,8 +165,8 @@ class TestPromptSupplement:
|
||||
from backend.copilot.prompting import get_sdk_supplement
|
||||
|
||||
# Test both local and E2B modes
|
||||
local_supplement = get_sdk_supplement(use_e2b=False, cwd="/tmp/test")
|
||||
e2b_supplement = get_sdk_supplement(use_e2b=True, cwd="")
|
||||
local_supplement = get_sdk_supplement(use_e2b=False)
|
||||
e2b_supplement = get_sdk_supplement(use_e2b=True)
|
||||
|
||||
# Should NOT have tool list section
|
||||
assert "## AVAILABLE TOOLS" not in local_supplement
|
||||
@@ -237,9 +237,9 @@ class TestPromptSupplement:
|
||||
for tool_name, tool in TOOL_REGISTRY.items():
|
||||
if not tool.is_available:
|
||||
continue
|
||||
assert (
|
||||
f"`{tool_name}`" in docs
|
||||
), f"Tool '{tool_name}' missing from baseline supplement"
|
||||
assert f"`{tool_name}`" in docs, (
|
||||
f"Tool '{tool_name}' missing from baseline supplement"
|
||||
)
|
||||
|
||||
def test_pause_task_scheduled_before_transcript_upload(self):
|
||||
"""Pause is scheduled as a background task before transcript upload begins.
|
||||
|
||||
@@ -50,7 +50,7 @@ from backend.copilot.tools import TOOL_REGISTRY
|
||||
from backend.copilot.tools.run_agent import RunAgentInput
|
||||
|
||||
# Resolved once for the whole module so individual tests stay fast.
|
||||
_SDK_SUPPLEMENT = get_sdk_supplement(use_e2b=False, cwd="/tmp/test")
|
||||
_SDK_SUPPLEMENT = get_sdk_supplement(use_e2b=False)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -193,9 +193,9 @@ class TestRunAgentToolSchema:
|
||||
"""dry_run must be in the run_agent LLM schema so the LLM can request
|
||||
per-call dry runs in normal sessions."""
|
||||
params = cast(dict[str, Any], schema["function"].get("parameters", {}))
|
||||
assert "dry_run" in params.get(
|
||||
"properties", {}
|
||||
), "dry_run must be exposed in the run_agent LLM schema"
|
||||
assert "dry_run" in params.get("properties", {}), (
|
||||
"dry_run must be exposed in the run_agent LLM schema"
|
||||
)
|
||||
assert "dry_run" not in params.get("required", [])
|
||||
|
||||
def test_wait_for_result_in_schema(self, schema: ChatCompletionToolParam):
|
||||
@@ -226,9 +226,9 @@ class TestRunBlockToolSchema:
|
||||
"""dry_run must NOT be in the run_block LLM schema — it is session-level."""
|
||||
params = cast(dict[str, Any], schema["function"].get("parameters", {}))
|
||||
props = params.get("properties", {})
|
||||
assert (
|
||||
"dry_run" not in props
|
||||
), "dry_run must not be exposed in the run_block LLM schema"
|
||||
assert "dry_run" not in props, (
|
||||
"dry_run must not be exposed in the run_block LLM schema"
|
||||
)
|
||||
assert "dry_run" not in params.get("required", [])
|
||||
|
||||
def test_block_id_and_input_data_are_required(
|
||||
@@ -265,9 +265,9 @@ class TestRunAgentInputModel:
|
||||
from backend.copilot.tools.run_agent import RunAgentTool
|
||||
|
||||
tool = RunAgentTool()
|
||||
assert "dry_run" in tool.parameters.get(
|
||||
"properties", {}
|
||||
), "dry_run must be exposed in the LLM tool schema"
|
||||
assert "dry_run" in tool.parameters.get("properties", {}), (
|
||||
"dry_run must be exposed in the LLM tool schema"
|
||||
)
|
||||
|
||||
def test_dry_run_accepts_true(self):
|
||||
model = RunAgentInput(username_agent_slug="user/agent", dry_run=True)
|
||||
@@ -341,9 +341,9 @@ class TestGuideWorkflowOrdering:
|
||||
"""Step 7 (Save/create_agent) must appear before step 8 (Dry-run)."""
|
||||
create_pos = guide_content.index("create_agent")
|
||||
dry_run_pos = guide_content.index("dry_run=True")
|
||||
assert (
|
||||
create_pos < dry_run_pos
|
||||
), "create_agent must appear before dry_run=True in the workflow"
|
||||
assert create_pos < dry_run_pos, (
|
||||
"create_agent must appear before dry_run=True in the workflow"
|
||||
)
|
||||
|
||||
def test_dry_run_before_inspect_in_verification_section(self, guide_content: str):
|
||||
"""In the verification loop section, Dry-run step must come before
|
||||
@@ -352,9 +352,9 @@ class TestGuideWorkflowOrdering:
|
||||
section = guide_content[section_start:]
|
||||
dry_run_pos = section.index("**Dry-run**")
|
||||
inspect_pos = section.index("**Inspect")
|
||||
assert (
|
||||
dry_run_pos < inspect_pos
|
||||
), "Dry-run step must come before Inspect & fix in the verification loop"
|
||||
assert dry_run_pos < inspect_pos, (
|
||||
"Dry-run step must come before Inspect & fix in the verification loop"
|
||||
)
|
||||
|
||||
def test_fix_before_repeat_in_verification_section(self, guide_content: str):
|
||||
"""The Fix step must come before the Repeat step."""
|
||||
@@ -377,9 +377,9 @@ class TestGuideWorkflowOrdering:
|
||||
section = guide_content[section_start:]
|
||||
# The section should contain numbered items 1 through 5
|
||||
for step_num in range(1, 6):
|
||||
assert (
|
||||
f"{step_num}. " in section
|
||||
), f"Missing numbered step {step_num} in verification workflow"
|
||||
assert f"{step_num}. " in section, (
|
||||
f"Missing numbered step {step_num} in verification workflow"
|
||||
)
|
||||
|
||||
def test_workflow_steps_are_in_numbered_order(self, guide_content: str):
|
||||
"""The main workflow steps (1-9) must appear in ascending order."""
|
||||
@@ -395,9 +395,9 @@ class TestGuideWorkflowOrdering:
|
||||
if match:
|
||||
step_positions.append((step_num, match.start()))
|
||||
# Verify at least steps 1-9 are present and in order
|
||||
assert (
|
||||
len(step_positions) >= 9
|
||||
), f"Expected 9 workflow steps, found {len(step_positions)}"
|
||||
assert len(step_positions) >= 9, (
|
||||
f"Expected 9 workflow steps, found {len(step_positions)}"
|
||||
)
|
||||
for i in range(1, len(step_positions)):
|
||||
prev_num, prev_pos = step_positions[i - 1]
|
||||
curr_num, curr_pos = step_positions[i]
|
||||
|
||||
Reference in New Issue
Block a user