acontext 0.0.7__tar.gz → 0.0.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {acontext-0.0.7 → acontext-0.0.8}/PKG-INFO +1 -1
- {acontext-0.0.7 → acontext-0.0.8}/pyproject.toml +1 -1
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/messages.py +4 -4
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/resources/async_sessions.py +12 -2
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/resources/async_spaces.py +1 -1
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/resources/sessions.py +17 -5
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/resources/spaces.py +1 -1
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/types/session.py +66 -3
- {acontext-0.0.7 → acontext-0.0.8}/README.md +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/__init__.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/_constants.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/_utils.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/agent/__init__.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/agent/base.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/agent/disk.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/async_client.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/client.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/client_types.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/errors.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/py.typed +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/resources/__init__.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/resources/async_blocks.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/resources/async_disks.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/resources/async_tools.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/resources/blocks.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/resources/disks.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/resources/tools.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/types/__init__.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/types/block.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/types/disk.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/types/space.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/types/tool.py +0 -0
- {acontext-0.0.7 → acontext-0.0.8}/src/acontext/uploads.py +0 -0
|
@@ -31,22 +31,22 @@ class AcontextMessage:
|
|
|
31
31
|
Represents an Acontext-format message payload.
|
|
32
32
|
"""
|
|
33
33
|
|
|
34
|
-
role: Literal["user", "assistant"
|
|
34
|
+
role: Literal["user", "assistant"]
|
|
35
35
|
parts: list[MessagePart]
|
|
36
36
|
meta: Mapping[str, Any] | None = None
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
def build_acontext_message(
|
|
40
40
|
*,
|
|
41
|
-
role: Literal["user", "assistant"
|
|
41
|
+
role: Literal["user", "assistant"],
|
|
42
42
|
parts: Sequence[MessagePart | str | Mapping[str, Any]],
|
|
43
43
|
meta: Mapping[str, Any] | None = None,
|
|
44
44
|
) -> AcontextMessage:
|
|
45
45
|
"""
|
|
46
46
|
Construct an Acontext-format message blob and associated multipart files.
|
|
47
47
|
"""
|
|
48
|
-
if role not in {"user", "assistant"
|
|
49
|
-
raise ValueError("role must be one of {'user', 'assistant'
|
|
48
|
+
if role not in {"user", "assistant"}:
|
|
49
|
+
raise ValueError("role must be one of {'user', 'assistant'}")
|
|
50
50
|
|
|
51
51
|
normalized_parts = [normalize_message_part(part) for part in parts]
|
|
52
52
|
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
import json
|
|
4
4
|
from collections.abc import Mapping
|
|
5
5
|
from dataclasses import asdict
|
|
6
|
-
from typing import Any, BinaryIO, Literal
|
|
6
|
+
from typing import Any, BinaryIO, Literal, Optional, List
|
|
7
7
|
|
|
8
8
|
from .._utils import build_params
|
|
9
9
|
from ..client_types import AsyncRequesterProtocol
|
|
10
10
|
from ..messages import AcontextMessage
|
|
11
11
|
from ..types.session import (
|
|
12
|
+
EditStrategy,
|
|
12
13
|
GetMessagesOutput,
|
|
13
14
|
GetTasksOutput,
|
|
14
15
|
LearningStatus,
|
|
@@ -264,6 +265,7 @@ class AsyncSessionsAPI:
|
|
|
264
265
|
with_asset_public_url: bool | None = None,
|
|
265
266
|
format: Literal["acontext", "openai", "anthropic"] = "openai",
|
|
266
267
|
time_desc: bool | None = None,
|
|
268
|
+
edit_strategies: Optional[List[EditStrategy]] = None,
|
|
267
269
|
) -> GetMessagesOutput:
|
|
268
270
|
"""Get messages for a session.
|
|
269
271
|
|
|
@@ -272,8 +274,14 @@ class AsyncSessionsAPI:
|
|
|
272
274
|
limit: Maximum number of messages to return. Defaults to None.
|
|
273
275
|
cursor: Cursor for pagination. Defaults to None.
|
|
274
276
|
with_asset_public_url: Whether to include presigned URLs for assets. Defaults to None.
|
|
275
|
-
format: The format of the messages. Defaults to "
|
|
277
|
+
format: The format of the messages. Defaults to "openai".
|
|
276
278
|
time_desc: Order by created_at descending if True, ascending if False. Defaults to None.
|
|
279
|
+
edit_strategies: Optional list of edit strategies to apply before format conversion.
|
|
280
|
+
Each strategy is a dict with 'type' and 'params' keys.
|
|
281
|
+
Examples:
|
|
282
|
+
- Remove tool results: [{"type": "remove_tool_result", "params": {"keep_recent_n_tool_results": 3}}]
|
|
283
|
+
- Token limit: [{"type": "token_limit", "params": {"limit_tokens": 20000}}]
|
|
284
|
+
Defaults to None.
|
|
277
285
|
|
|
278
286
|
Returns:
|
|
279
287
|
GetMessagesOutput containing the list of messages and pagination information.
|
|
@@ -289,6 +297,8 @@ class AsyncSessionsAPI:
|
|
|
289
297
|
time_desc=time_desc,
|
|
290
298
|
)
|
|
291
299
|
)
|
|
300
|
+
if edit_strategies is not None:
|
|
301
|
+
params["edit_strategies"] = json.dumps(edit_strategies)
|
|
292
302
|
data = await self._requester.request(
|
|
293
303
|
"GET", f"/session/{session_id}/messages", params=params or None
|
|
294
304
|
)
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
import json
|
|
4
4
|
from collections.abc import Mapping
|
|
5
5
|
from dataclasses import asdict
|
|
6
|
-
from typing import Any, BinaryIO, Literal
|
|
6
|
+
from typing import Any, BinaryIO, Literal, Optional, List
|
|
7
7
|
|
|
8
8
|
from .._utils import build_params
|
|
9
9
|
from ..client_types import RequesterProtocol
|
|
10
10
|
from ..messages import AcontextMessage
|
|
11
11
|
from ..types.session import (
|
|
12
|
+
EditStrategy,
|
|
12
13
|
GetMessagesOutput,
|
|
13
14
|
GetTasksOutput,
|
|
14
15
|
LearningStatus,
|
|
@@ -71,12 +72,14 @@ class SessionsAPI:
|
|
|
71
72
|
self,
|
|
72
73
|
*,
|
|
73
74
|
space_id: str | None = None,
|
|
75
|
+
disable_task_tracking: bool | None = None,
|
|
74
76
|
configs: Mapping[str, Any] | None = None,
|
|
75
77
|
) -> Session:
|
|
76
78
|
"""Create a new session.
|
|
77
79
|
|
|
78
80
|
Args:
|
|
79
81
|
space_id: Optional space ID to associate with the session. Defaults to None.
|
|
82
|
+
disable_task_tracking: Whether to disable task tracking for this session. Defaults to None (server default: False).
|
|
80
83
|
configs: Optional session configuration dictionary. Defaults to None.
|
|
81
84
|
|
|
82
85
|
Returns:
|
|
@@ -85,6 +88,8 @@ class SessionsAPI:
|
|
|
85
88
|
payload: dict[str, Any] = {}
|
|
86
89
|
if space_id:
|
|
87
90
|
payload["space_id"] = space_id
|
|
91
|
+
if disable_task_tracking is not None:
|
|
92
|
+
payload["disable_task_tracking"] = disable_task_tracking
|
|
88
93
|
if configs is not None:
|
|
89
94
|
payload["configs"] = configs
|
|
90
95
|
data = self._requester.request("POST", "/session", json_data=payload)
|
|
@@ -264,6 +269,7 @@ class SessionsAPI:
|
|
|
264
269
|
with_asset_public_url: bool | None = None,
|
|
265
270
|
format: Literal["acontext", "openai", "anthropic"] = "openai",
|
|
266
271
|
time_desc: bool | None = None,
|
|
272
|
+
edit_strategies: Optional[List[EditStrategy]] = None,
|
|
267
273
|
) -> GetMessagesOutput:
|
|
268
274
|
"""Get messages for a session.
|
|
269
275
|
|
|
@@ -272,8 +278,14 @@ class SessionsAPI:
|
|
|
272
278
|
limit: Maximum number of messages to return. Defaults to None.
|
|
273
279
|
cursor: Cursor for pagination. Defaults to None.
|
|
274
280
|
with_asset_public_url: Whether to include presigned URLs for assets. Defaults to None.
|
|
275
|
-
format: The format of the messages. Defaults to "
|
|
281
|
+
format: The format of the messages. Defaults to "openai".
|
|
276
282
|
time_desc: Order by created_at descending if True, ascending if False. Defaults to None.
|
|
283
|
+
edit_strategies: Optional list of edit strategies to apply before format conversion.
|
|
284
|
+
Each strategy is a dict with 'type' and 'params' keys.
|
|
285
|
+
Examples:
|
|
286
|
+
- Remove tool results: [{"type": "remove_tool_result", "params": {"keep_recent_n_tool_results": 3}}]
|
|
287
|
+
- Token limit: [{"type": "token_limit", "params": {"limit_tokens": 20000}}]
|
|
288
|
+
Defaults to None.
|
|
277
289
|
|
|
278
290
|
Returns:
|
|
279
291
|
GetMessagesOutput containing the list of messages and pagination information.
|
|
@@ -289,6 +301,8 @@ class SessionsAPI:
|
|
|
289
301
|
time_desc=time_desc,
|
|
290
302
|
)
|
|
291
303
|
)
|
|
304
|
+
if edit_strategies is not None:
|
|
305
|
+
params["edit_strategies"] = json.dumps(edit_strategies)
|
|
292
306
|
data = self._requester.request(
|
|
293
307
|
"GET", f"/session/{session_id}/messages", params=params or None
|
|
294
308
|
)
|
|
@@ -332,7 +346,5 @@ class SessionsAPI:
|
|
|
332
346
|
Returns:
|
|
333
347
|
TokenCounts object containing total_tokens.
|
|
334
348
|
"""
|
|
335
|
-
data = self._requester.request(
|
|
336
|
-
"GET", f"/session/{session_id}/token_counts"
|
|
337
|
-
)
|
|
349
|
+
data = self._requester.request("GET", f"/session/{session_id}/token_counts")
|
|
338
350
|
return TokenCounts.model_validate(data)
|
|
@@ -1,10 +1,67 @@
|
|
|
1
1
|
"""Type definitions for session, message, and task resources."""
|
|
2
2
|
|
|
3
|
-
from typing import Any
|
|
3
|
+
from typing import Any, Literal, NotRequired, TypedDict, Union
|
|
4
4
|
|
|
5
5
|
from pydantic import BaseModel, Field
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
class RemoveToolResultParams(TypedDict, total=False):
|
|
9
|
+
"""Parameters for the remove_tool_result edit strategy.
|
|
10
|
+
|
|
11
|
+
Attributes:
|
|
12
|
+
keep_recent_n_tool_results: Number of most recent tool results to keep with original content.
|
|
13
|
+
Defaults to 3 if not specified.
|
|
14
|
+
tool_result_placeholder: Custom text to replace old tool results with.
|
|
15
|
+
Defaults to "Done" if not specified.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
keep_recent_n_tool_results: NotRequired[int]
|
|
19
|
+
tool_result_placeholder: NotRequired[str]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class RemoveToolResultStrategy(TypedDict):
|
|
23
|
+
"""Edit strategy to replace old tool results with placeholder text.
|
|
24
|
+
|
|
25
|
+
Example:
|
|
26
|
+
{"type": "remove_tool_result", "params": {"keep_recent_n_tool_results": 5, "tool_result_placeholder": "Cleared"}}
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
type: Literal["remove_tool_result"]
|
|
30
|
+
params: RemoveToolResultParams
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class TokenLimitParams(TypedDict):
|
|
34
|
+
"""Parameters for the token_limit edit strategy.
|
|
35
|
+
|
|
36
|
+
Attributes:
|
|
37
|
+
limit_tokens: Maximum number of tokens to keep. Required parameter.
|
|
38
|
+
Messages will be removed from oldest to newest until total tokens <= limit_tokens.
|
|
39
|
+
Tool-call and tool-result pairs are always removed together.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
limit_tokens: int
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class TokenLimitStrategy(TypedDict):
|
|
46
|
+
"""Edit strategy to truncate messages based on token count.
|
|
47
|
+
|
|
48
|
+
Removes oldest messages until the total token count is within the specified limit.
|
|
49
|
+
Maintains tool-call/tool-result pairing - when removing a message with tool-calls,
|
|
50
|
+
the corresponding tool-result messages are also removed.
|
|
51
|
+
|
|
52
|
+
Example:
|
|
53
|
+
{"type": "token_limit", "params": {"limit_tokens": 20000}}
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
type: Literal["token_limit"]
|
|
57
|
+
params: TokenLimitParams
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# Union type for all edit strategies
|
|
61
|
+
# When adding new strategies, add them to this Union: EditStrategy = Union[RemoveToolResultStrategy, OtherStrategy, ...]
|
|
62
|
+
EditStrategy = Union[RemoveToolResultStrategy, TokenLimitStrategy]
|
|
63
|
+
|
|
64
|
+
|
|
8
65
|
class Asset(BaseModel):
|
|
9
66
|
"""Asset model representing a file asset."""
|
|
10
67
|
|
|
@@ -35,7 +92,7 @@ class Message(BaseModel):
|
|
|
35
92
|
id: str = Field(..., description="Message UUID")
|
|
36
93
|
session_id: str = Field(..., description="Session UUID")
|
|
37
94
|
parent_id: str | None = Field(None, description="Parent message UUID")
|
|
38
|
-
role: str = Field(..., description="Message role: 'user'
|
|
95
|
+
role: str = Field(..., description="Message role: 'user' or 'assistant'")
|
|
39
96
|
meta: dict[str, Any] = Field(..., description="Message metadata")
|
|
40
97
|
parts: list[Part] = Field(..., description="List of message parts")
|
|
41
98
|
task_id: str | None = Field(None, description="Task UUID if associated with a task")
|
|
@@ -52,6 +109,9 @@ class Session(BaseModel):
|
|
|
52
109
|
|
|
53
110
|
id: str = Field(..., description="Session UUID")
|
|
54
111
|
project_id: str = Field(..., description="Project UUID")
|
|
112
|
+
disable_task_tracking: bool = Field(
|
|
113
|
+
False, description="Whether task tracking is disabled for this session"
|
|
114
|
+
)
|
|
55
115
|
space_id: str | None = Field(None, description="Space UUID, optional")
|
|
56
116
|
configs: dict[str, Any] | None = Field(
|
|
57
117
|
None, description="Session configuration dictionary"
|
|
@@ -138,4 +198,7 @@ class LearningStatus(BaseModel):
|
|
|
138
198
|
class TokenCounts(BaseModel):
|
|
139
199
|
"""Response model for token counts."""
|
|
140
200
|
|
|
141
|
-
total_tokens: int = Field(
|
|
201
|
+
total_tokens: int = Field(
|
|
202
|
+
...,
|
|
203
|
+
description="Total token count for all text and tool-call parts in a session",
|
|
204
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|