acontext 0.1.0__py3-none-any.whl → 0.1.2__py3-none-any.whl
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/resources/async_disks.py +2 -0
- acontext/resources/async_sessions.py +42 -0
- acontext/resources/sessions.py +51 -8
- acontext/types/session.py +25 -1
- {acontext-0.1.0.dist-info → acontext-0.1.2.dist-info}/METADATA +2 -2
- {acontext-0.1.0.dist-info → acontext-0.1.2.dist-info}/RECORD +7 -7
- {acontext-0.1.0.dist-info → acontext-0.1.2.dist-info}/WHEEL +2 -2
|
@@ -180,6 +180,47 @@ class AsyncSessionsAPI:
|
|
|
180
180
|
)
|
|
181
181
|
return GetTasksOutput.model_validate(data)
|
|
182
182
|
|
|
183
|
+
async def get_session_summary(
|
|
184
|
+
self,
|
|
185
|
+
session_id: str,
|
|
186
|
+
*,
|
|
187
|
+
limit: int | None = None,
|
|
188
|
+
) -> str:
|
|
189
|
+
"""Get a summary of all tasks in a session as a formatted string.
|
|
190
|
+
|
|
191
|
+
Args:
|
|
192
|
+
session_id: The UUID of the session.
|
|
193
|
+
limit: Maximum number of tasks to include in the summary. Defaults to None (all tasks).
|
|
194
|
+
|
|
195
|
+
Returns:
|
|
196
|
+
A formatted string containing the session summary with all task information.
|
|
197
|
+
"""
|
|
198
|
+
tasks_output = await self.get_tasks(session_id, limit=limit, time_desc=False)
|
|
199
|
+
tasks = tasks_output.items
|
|
200
|
+
|
|
201
|
+
if not tasks:
|
|
202
|
+
return ""
|
|
203
|
+
|
|
204
|
+
parts: list[str] = []
|
|
205
|
+
for task in tasks:
|
|
206
|
+
task_lines = [
|
|
207
|
+
f'<task id="{task.order}" description="{task.data.task_description}">'
|
|
208
|
+
]
|
|
209
|
+
if task.data.progresses:
|
|
210
|
+
task_lines.append("<progress>")
|
|
211
|
+
for i, p in enumerate(task.data.progresses, 1):
|
|
212
|
+
task_lines.append(f"{i}. {p}")
|
|
213
|
+
task_lines.append("</progress>")
|
|
214
|
+
if task.data.user_preferences:
|
|
215
|
+
task_lines.append("<user_preference>")
|
|
216
|
+
for i, pref in enumerate(task.data.user_preferences, 1):
|
|
217
|
+
task_lines.append(f"{i}. {pref}")
|
|
218
|
+
task_lines.append("</user_preference>")
|
|
219
|
+
task_lines.append("</task>")
|
|
220
|
+
parts.append("\n".join(task_lines))
|
|
221
|
+
|
|
222
|
+
return "\n".join(parts)
|
|
223
|
+
|
|
183
224
|
async def store_message(
|
|
184
225
|
self,
|
|
185
226
|
session_id: str,
|
|
@@ -294,6 +335,7 @@ class AsyncSessionsAPI:
|
|
|
294
335
|
Each strategy is a dict with 'type' and 'params' keys.
|
|
295
336
|
Examples:
|
|
296
337
|
- Remove tool results: [{"type": "remove_tool_result", "params": {"keep_recent_n_tool_results": 3}}]
|
|
338
|
+
- Middle out: [{"type": "middle_out", "params": {"token_reduce_to": 5000}}]
|
|
297
339
|
- Token limit: [{"type": "token_limit", "params": {"limit_tokens": 20000}}]
|
|
298
340
|
Defaults to None.
|
|
299
341
|
pin_editing_strategies_at_message: Message ID to pin editing strategies at.
|
acontext/resources/sessions.py
CHANGED
|
@@ -180,6 +180,47 @@ class SessionsAPI:
|
|
|
180
180
|
)
|
|
181
181
|
return GetTasksOutput.model_validate(data)
|
|
182
182
|
|
|
183
|
+
def get_session_summary(
|
|
184
|
+
self,
|
|
185
|
+
session_id: str,
|
|
186
|
+
*,
|
|
187
|
+
limit: int | None = None,
|
|
188
|
+
) -> str:
|
|
189
|
+
"""Get a summary of all tasks in a session as a formatted string.
|
|
190
|
+
|
|
191
|
+
Args:
|
|
192
|
+
session_id: The UUID of the session.
|
|
193
|
+
limit: Maximum number of tasks to include in the summary. Defaults to None (all tasks).
|
|
194
|
+
|
|
195
|
+
Returns:
|
|
196
|
+
A formatted string containing the session summary with all task information.
|
|
197
|
+
"""
|
|
198
|
+
tasks_output = self.get_tasks(session_id, limit=limit, time_desc=False)
|
|
199
|
+
tasks = tasks_output.items
|
|
200
|
+
|
|
201
|
+
if not tasks:
|
|
202
|
+
return ""
|
|
203
|
+
|
|
204
|
+
parts: list[str] = []
|
|
205
|
+
for task in tasks:
|
|
206
|
+
task_lines = [
|
|
207
|
+
f'<task id="{task.order}" description="{task.data.task_description}">'
|
|
208
|
+
]
|
|
209
|
+
if task.data.progresses:
|
|
210
|
+
task_lines.append("<progress>")
|
|
211
|
+
for i, p in enumerate(task.data.progresses, 1):
|
|
212
|
+
task_lines.append(f"{i}. {p}")
|
|
213
|
+
task_lines.append("</progress>")
|
|
214
|
+
if task.data.user_preferences:
|
|
215
|
+
task_lines.append("<user_preference>")
|
|
216
|
+
for i, pref in enumerate(task.data.user_preferences, 1):
|
|
217
|
+
task_lines.append(f"{i}. {pref}")
|
|
218
|
+
task_lines.append("</user_preference>")
|
|
219
|
+
task_lines.append("</task>")
|
|
220
|
+
parts.append("\n".join(task_lines))
|
|
221
|
+
|
|
222
|
+
return "\n".join(parts)
|
|
223
|
+
|
|
183
224
|
def store_message(
|
|
184
225
|
self,
|
|
185
226
|
session_id: str,
|
|
@@ -294,6 +335,7 @@ class SessionsAPI:
|
|
|
294
335
|
Each strategy is a dict with 'type' and 'params' keys.
|
|
295
336
|
Examples:
|
|
296
337
|
- Remove tool results: [{"type": "remove_tool_result", "params": {"keep_recent_n_tool_results": 3}}]
|
|
338
|
+
- Middle out: [{"type": "middle_out", "params": {"token_reduce_to": 5000}}]
|
|
297
339
|
- Token limit: [{"type": "token_limit", "params": {"limit_tokens": 20000}}]
|
|
298
340
|
Defaults to None.
|
|
299
341
|
pin_editing_strategies_at_message: Message ID to pin editing strategies at.
|
|
@@ -320,7 +362,9 @@ class SessionsAPI:
|
|
|
320
362
|
if edit_strategies is not None:
|
|
321
363
|
params["edit_strategies"] = json.dumps(edit_strategies)
|
|
322
364
|
if pin_editing_strategies_at_message is not None:
|
|
323
|
-
params["pin_editing_strategies_at_message"] =
|
|
365
|
+
params["pin_editing_strategies_at_message"] = (
|
|
366
|
+
pin_editing_strategies_at_message
|
|
367
|
+
)
|
|
324
368
|
data = self._requester.request(
|
|
325
369
|
"GET", f"/session/{session_id}/messages", params=params or None
|
|
326
370
|
)
|
|
@@ -366,20 +410,19 @@ class SessionsAPI:
|
|
|
366
410
|
"""
|
|
367
411
|
data = self._requester.request("GET", f"/session/{session_id}/token_counts")
|
|
368
412
|
return TokenCounts.model_validate(data)
|
|
413
|
+
|
|
369
414
|
def messages_observing_status(self, session_id: str) -> MessageObservingStatus:
|
|
370
415
|
"""Get message observing status counts for a session.
|
|
371
|
-
|
|
416
|
+
|
|
372
417
|
Returns the count of messages by their observing status:
|
|
373
418
|
observed, in_process, and pending.
|
|
374
|
-
|
|
419
|
+
|
|
375
420
|
Args:
|
|
376
421
|
session_id: The UUID of the session.
|
|
377
|
-
|
|
422
|
+
|
|
378
423
|
Returns:
|
|
379
|
-
MessageObservingStatus object containing observed, in_process,
|
|
424
|
+
MessageObservingStatus object containing observed, in_process,
|
|
380
425
|
pending counts and updated_at timestamp.
|
|
381
426
|
"""
|
|
382
|
-
data = self._requester.request(
|
|
383
|
-
"GET", f"/session/{session_id}/observing_status"
|
|
384
|
-
)
|
|
427
|
+
data = self._requester.request("GET", f"/session/{session_id}/observing_status")
|
|
385
428
|
return MessageObservingStatus.model_validate(data)
|
acontext/types/session.py
CHANGED
|
@@ -89,10 +89,34 @@ class TokenLimitStrategy(TypedDict):
|
|
|
89
89
|
params: TokenLimitParams
|
|
90
90
|
|
|
91
91
|
|
|
92
|
+
class MiddleOutParams(TypedDict):
|
|
93
|
+
"""Parameters for the middle_out edit strategy.
|
|
94
|
+
|
|
95
|
+
Attributes:
|
|
96
|
+
token_reduce_to: Target token count to reduce the prompt to. Required parameter.
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
token_reduce_to: int
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class MiddleOutStrategy(TypedDict):
|
|
103
|
+
"""Edit strategy to reduce prompt size by removing middle messages.
|
|
104
|
+
|
|
105
|
+
Example:
|
|
106
|
+
{"type": "middle_out", "params": {"token_reduce_to": 5000}}
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
type: Literal["middle_out"]
|
|
110
|
+
params: MiddleOutParams
|
|
111
|
+
|
|
112
|
+
|
|
92
113
|
# Union type for all edit strategies
|
|
93
114
|
# When adding new strategies, add them to this Union: EditStrategy = Union[RemoveToolResultStrategy, OtherStrategy, ...]
|
|
94
115
|
EditStrategy = Union[
|
|
95
|
-
RemoveToolResultStrategy,
|
|
116
|
+
RemoveToolResultStrategy,
|
|
117
|
+
RemoveToolCallParamsStrategy,
|
|
118
|
+
TokenLimitStrategy,
|
|
119
|
+
MiddleOutStrategy,
|
|
96
120
|
]
|
|
97
121
|
|
|
98
122
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: acontext
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Python SDK for the Acontext API
|
|
5
5
|
Keywords: acontext,sdk,client,api
|
|
6
6
|
Requires-Dist: httpx>=0.28.1
|
|
@@ -10,8 +10,8 @@ Requires-Dist: pydantic>=2.12.3
|
|
|
10
10
|
Requires-Dist: urllib3>=2.6.3
|
|
11
11
|
Requires-Python: >=3.10
|
|
12
12
|
Project-URL: Homepage, https://github.com/memodb-io/Acontext
|
|
13
|
-
Project-URL: Issues, https://github.com/memodb-io/Acontext/issues
|
|
14
13
|
Project-URL: Repository, https://github.com/memodb-io/Acontext
|
|
14
|
+
Project-URL: Issues, https://github.com/memodb-io/Acontext/issues
|
|
15
15
|
Description-Content-Type: text/markdown
|
|
16
16
|
|
|
17
17
|
## acontext client for python
|
|
@@ -13,15 +13,15 @@ acontext/messages.py,sha256=oNRZStfhcPFt6DPOfs_-Q7R1Xui6dOMr3wmpmC8pzvE,2310
|
|
|
13
13
|
acontext/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
14
|
acontext/resources/__init__.py,sha256=Oww11t9hmwdNFK2nC8YW9mf4BBSz5YLPAXAWLlZuNTs,935
|
|
15
15
|
acontext/resources/async_blocks.py,sha256=e_iJpgcAdwS2tXQ16MMCnySlddp5JV3BadN_EyqZSF4,5555
|
|
16
|
-
acontext/resources/async_disks.py,sha256=
|
|
17
|
-
acontext/resources/async_sessions.py,sha256=
|
|
16
|
+
acontext/resources/async_disks.py,sha256=iwCTam-fdoL3SKLqEVkTi3Pk90PsqNvsGBQECcPIHRc,9060
|
|
17
|
+
acontext/resources/async_sessions.py,sha256=0SuNzuLSG4wKyJa_QCIP5pKkvzW6VDe5yHNRDdqoPrw,16317
|
|
18
18
|
acontext/resources/async_skills.py,sha256=VoeqO9Z6E7qPCE2tMJaO7coONaCKCoLJRANQ5yWVbiE,4666
|
|
19
19
|
acontext/resources/async_spaces.py,sha256=b8DNG2L43B6iSgfmH8M-0cxAp681IjSCjw-4alfjV2A,6712
|
|
20
20
|
acontext/resources/async_tools.py,sha256=RbGaF2kX65Mun-q-Fp5H1J8waWTLIdCOfbdY19jpn1o,1091
|
|
21
21
|
acontext/resources/async_users.py,sha256=m0nK_Luo6Uuvw2azGx8Wg2cXnipnTnyheolr79fX16Y,2020
|
|
22
22
|
acontext/resources/blocks.py,sha256=HJdAy5HdyTcHCYCPmqNdvApYKZ6aWs-ORIi_wQt3TUM,5447
|
|
23
23
|
acontext/resources/disks.py,sha256=pvxs9gdVBothuy0LSkPmuS061nNOgJX3iffypqLHW1Y,9032
|
|
24
|
-
acontext/resources/sessions.py,sha256=
|
|
24
|
+
acontext/resources/sessions.py,sha256=xHvT-CQHXhTc6BHHwpW_jyzMkxccSuTIdpLpTjS_NRc,16056
|
|
25
25
|
acontext/resources/skills.py,sha256=ZECLUfy4QWHnzk9nnq1VvEeFTx-u7NvEhECfbq5Reiw,4615
|
|
26
26
|
acontext/resources/spaces.py,sha256=Ktvkkn3Jj7CZoKMbn6fYuo0zqImoCWj2EnMsnL2q-0A,6571
|
|
27
27
|
acontext/resources/tools.py,sha256=II_185B0HYKSP43hizE6C1zs7kjkkPLKihuEG8s-DRY,1046
|
|
@@ -30,12 +30,12 @@ acontext/types/__init__.py,sha256=L6g545qLolIVoo3ltlsOeZOr8T72lTrg9bOK-q1Mw0c,19
|
|
|
30
30
|
acontext/types/block.py,sha256=CzKByunk642rWXNNnh8cx67UzKLKDAxODmC_whwjP90,1078
|
|
31
31
|
acontext/types/common.py,sha256=5kLwzszlIofz8qZ9-Wj_zcBBiF22mAWgH9uWPkcgWCE,327
|
|
32
32
|
acontext/types/disk.py,sha256=nMjyXLUre4Xuu_YfBbzzdRQDRxB8qX1Zx9LsNqGCi9E,2223
|
|
33
|
-
acontext/types/session.py,sha256=
|
|
33
|
+
acontext/types/session.py,sha256=JeIlnjT6Gs2t4kZu5DKjus9KeCc-Vgjj7RH1x-JqYyY,11597
|
|
34
34
|
acontext/types/skill.py,sha256=VlLp5NpsJSpyoQTlTuV6jJ4G6ArHr1SDpcqEmFkHyeY,2364
|
|
35
35
|
acontext/types/space.py,sha256=9BkGBYGeQDVwYTmPLoIjMY-IUdQzjrt8I7CXca2_5Vc,2600
|
|
36
36
|
acontext/types/tool.py,sha256=-mVn-vgk2SENK0Ubt-ZgWFZxKa-ddABqcAgXQ69YY-E,805
|
|
37
37
|
acontext/types/user.py,sha256=JjE0xZDwUAs2BL741U7NINyyPAso64A1YmgMBPqSuvo,1331
|
|
38
38
|
acontext/uploads.py,sha256=6twnqQOY_eerNuEjeSKsE_3S0IfJUiczXtAy4aXqDl8,1379
|
|
39
|
-
acontext-0.1.
|
|
40
|
-
acontext-0.1.
|
|
41
|
-
acontext-0.1.
|
|
39
|
+
acontext-0.1.2.dist-info/WHEEL,sha256=XV0cjMrO7zXhVAIyyc8aFf1VjZ33Fen4IiJk5zFlC3g,80
|
|
40
|
+
acontext-0.1.2.dist-info/METADATA,sha256=dIwbYqoDjMXrc9QjiL_u5usSy7IgVgrdLMn6ZVaBHCU,888
|
|
41
|
+
acontext-0.1.2.dist-info/RECORD,,
|