Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions sdk/memory-core/python/tencentdb_agent_memory/v3/skill_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from ..errors import ParamError

_V3 = "/v3/skill"
_UNSET = object()

# ── Numeric error codes returned in envelope.code for /v3/skill/*. ──
SKILL_ERROR_CODE: Dict[str, int] = {
Expand Down Expand Up @@ -178,19 +179,23 @@ def __init__(
def with_defaults(
self,
*,
team_id: Optional[str] = None,
agent_id: Optional[str] = None,
user_id: Optional[str] = None,
task_id: Optional[str] = None,
team_id: Any = _UNSET,
agent_id: Any = _UNSET,
user_id: Any = _UNSET,
task_id: Any = _UNSET,
) -> "SkillClient":
"""Return a clone sharing the transport but with overridden defaults."""
"""Clone this client with selected defaults overridden.

Pass ``None`` to clear a default; omitted arguments retain their
current values.
"""
clone = object.__new__(SkillClient)
clone._stub = self._stub
clone._defaults = _SkillDefaults(
team_id if team_id is not None else self._defaults.team_id,
agent_id if agent_id is not None else self._defaults.agent_id,
user_id if user_id is not None else self._defaults.user_id,
task_id if task_id is not None else self._defaults.task_id,
self._defaults.team_id if team_id is _UNSET else team_id,
self._defaults.agent_id if agent_id is _UNSET else agent_id,
self._defaults.user_id if user_id is _UNSET else user_id,
self._defaults.task_id if task_id is _UNSET else task_id,
)
return clone

Expand Down Expand Up @@ -617,18 +622,23 @@ def __init__(
def with_defaults(
self,
*,
team_id: Optional[str] = None,
agent_id: Optional[str] = None,
user_id: Optional[str] = None,
task_id: Optional[str] = None,
team_id: Any = _UNSET,
agent_id: Any = _UNSET,
user_id: Any = _UNSET,
task_id: Any = _UNSET,
) -> "AsyncSkillClient":
"""Clone this client with selected defaults overridden.

Pass ``None`` to clear a default; omitted arguments retain their
current values.
"""
clone = object.__new__(AsyncSkillClient)
clone._stub = self._stub
clone._defaults = _SkillDefaults(
team_id if team_id is not None else self._defaults.team_id,
agent_id if agent_id is not None else self._defaults.agent_id,
user_id if user_id is not None else self._defaults.user_id,
task_id if task_id is not None else self._defaults.task_id,
self._defaults.team_id if team_id is _UNSET else team_id,
self._defaults.agent_id if agent_id is _UNSET else agent_id,
self._defaults.user_id if user_id is _UNSET else user_id,
self._defaults.task_id if task_id is _UNSET else task_id,
)
return clone

Expand Down
106 changes: 106 additions & 0 deletions sdk/memory-core/python/tests/test_v3_skill_defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import asyncio
from typing import Any, Dict, List, Optional, Tuple

from tencentdb_agent_memory.v3.skill_client import (
AsyncSkillClient,
SkillClient,
)


class RecordingStub:
def __init__(self) -> None:
self.calls: List[Tuple[str, Dict[str, Any]]] = []

def post(
self,
path: str,
body: Dict[str, Any],
timeout: Optional[float] = None,
) -> Dict[str, Any]:
self.calls.append((path, body))
return {}

def close(self) -> None:
return None


class AsyncRecordingStub:
def __init__(self) -> None:
self.calls: List[Tuple[str, Dict[str, Any]]] = []

async def post(
self,
path: str,
body: Dict[str, Any],
timeout: Optional[float] = None,
) -> Dict[str, Any]:
self.calls.append((path, body))
return {}

async def close(self) -> None:
return None


def test_sync_with_defaults_distinguishes_omitted_from_none() -> None:
stub = RecordingStub()
client = SkillClient(
stub=stub,
team_id="team-1",
agent_id="agent-1",
user_id="user-1",
task_id="task-1",
)

client.with_defaults().list()
client.with_defaults(team_id=None, task_id=None).list()

assert stub.calls[0] == (
"/v3/skill/list",
{
"team_id": "team-1",
"agent_id": "agent-1",
"user_id": "user-1",
"task_id": "task-1",
},
)
assert stub.calls[1] == (
"/v3/skill/list",
{
"agent_id": "agent-1",
"user_id": "user-1",
},
)


def test_async_with_defaults_distinguishes_omitted_from_none() -> None:
stub = AsyncRecordingStub()
client = AsyncSkillClient(
stub=stub,
team_id="team-1",
agent_id="agent-1",
user_id="user-1",
task_id="task-1",
)

async def run() -> None:
await client.with_defaults().list()
await client.with_defaults(agent_id=None, task_id=None).list()

asyncio.run(run())

assert stub.calls[0] == (
"/v3/skill/list",
{
"team_id": "team-1",
"agent_id": "agent-1",
"user_id": "user-1",
"task_id": "task-1",
},
)
assert stub.calls[1] == (
"/v3/skill/list",
{
"team_id": "team-1",
"user_id": "user-1",
},
)