Skip to content

Commit b0e4afe

Browse files
committed
feat: enhance APIADDRequest with custom_tags, info, and is_feedback fields
- Add custom_tags field for user-defined tags (e.g., ['Travel', 'family']) that can be used as search filters - Add info field for additional metadata (agent_id, app_id, source_type, etc.) with all keys usable as search filters - Add is_feedback field to indicate if the request represents user feedback - Reorganize fields with category comments for better readability - Mark async_mode as required with default value 'async' - Mark mem_cube_id, memory_content, doc_path, and source as deprecated - Enhance field descriptions for better API documentation
1 parent 1043377 commit b0e4afe

File tree

1 file changed

+101
-11
lines changed

1 file changed

+101
-11
lines changed

src/memos/api/product_models.py

Lines changed: 101 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,112 @@ class APISearchRequest(BaseRequest):
199199
class APIADDRequest(BaseRequest):
200200
"""Request model for creating memories."""
201201

202+
# ==== Basic identifiers ====
202203
user_id: str = Field(None, description="User ID")
203-
mem_cube_id: str | None = Field(None, description="Cube ID")
204+
session_id: str | None = Field(
205+
None,
206+
description="Session ID. If not provided, a default session will be used.",
207+
)
208+
# ==== Single-cube writing (Deprecated) ====
209+
mem_cube_id: str | None = Field(
210+
None,
211+
description="(Deprecated) Target cube ID for this add request (optional for developer API).",
212+
)
213+
214+
# ==== Multi-cube writing ====
204215
writable_cube_ids: list[str] | None = Field(
205216
None, description="List of cube IDs user can write for multi-cube add"
206217
)
207-
messages: list[MessageDict] | None = Field(None, description="List of messages to store.")
208-
memory_content: str | None = Field(None, description="Memory content to store")
209-
doc_path: str | None = Field(None, description="Path to document to store")
210-
source: str | None = Field(None, description="Source of the memory")
211-
chat_history: list[MessageDict] | None = Field(None, description="Chat history")
212-
session_id: str | None = Field(None, description="Session id")
213-
operation: list[PermissionDict] | None = Field(
214-
None, description="operation ids for multi cubes"
218+
219+
# ==== Async control ====
220+
async_mode: Literal["async", "sync"] = Field(
221+
"async",
222+
description=(
223+
"Whether to add memory in async mode. "
224+
"Use 'async' to enqueue background add (non-blocking), "
225+
"or 'sync' to add memories in the current call. "
226+
"Default: 'async'."
227+
),
215228
)
216-
async_mode: Literal["async", "sync"] | None = Field(
217-
None, description="Whether to add memory in async mode"
229+
230+
# ==== Business tags & info ====
231+
custom_tags: list[str] | None = Field(
232+
None,
233+
description=(
234+
"Custom tags for this add request, e.g. ['Travel', 'family']. "
235+
"These tags can be used as filters in search."
236+
),
237+
)
238+
239+
info: dict[str, str] | None = Field(
240+
None,
241+
description=(
242+
"Additional metadata for the add request. "
243+
"All keys can be used as filters in search. "
244+
"Example: "
245+
"{'agent_id': 'xxxxxx', "
246+
"'app_id': 'xxxx', "
247+
"'source_type': 'web', "
248+
"'source_url': 'https://www.baidu.com', "
249+
"'source_content': '西湖是杭州最著名的景点'}."
250+
),
251+
)
252+
253+
# ==== Input content ====
254+
messages: list[MessageDict] | None = Field(
255+
None,
256+
description=(
257+
"List of messages to store. Supports: "
258+
"- system / user / assistant messages with 'content' and 'chat_time'; "
259+
"- tool messages including: "
260+
" * tool_description (name, description, parameters), "
261+
" * tool_input (call_id, name, argument), "
262+
" * raw tool messages where content is str or list[str], "
263+
" * tool_output with structured output items "
264+
" (input_text / input_image / input_file, etc.). "
265+
"Also supports pure input items when there is no dialog."
266+
),
267+
)
268+
269+
# pure input (no role)
270+
# e.g. {\"type\": \"input_text\", \"text\": \"你好\"} etc。
271+
# If there is no dialog, higher-level code can wrap raw inputs into MessageDict.
272+
273+
# ==== Chat history ====
274+
chat_history: list[MessageDict] | None = Field(
275+
None,
276+
description=(
277+
"Historical chat messages used internally by algorithms. "
278+
"If None, internal stored history will be used; "
279+
"if provided (even an empty list), this value will be used as-is."
280+
),
281+
)
282+
283+
# ==== Feedback flag ====
284+
is_feedback: bool = Field(
285+
False,
286+
description=("Whether this request represents user feedback. Default: False."),
287+
)
288+
289+
# ==== Backward compatibility fields (will delete later) ====
290+
memory_content: str | None = Field(
291+
None,
292+
description="(Deprecated) Plain memory content to store. Prefer using `messages`.",
293+
)
294+
doc_path: str | None = Field(
295+
None,
296+
description="(Deprecated / internal) Path to document to store.",
297+
)
298+
source: str | None = Field(
299+
None,
300+
description=(
301+
"(Deprecated) Simple source tag of the memory. "
302+
"Prefer using `info.source_type` / `info.source_url`."
303+
),
304+
)
305+
operation: list[PermissionDict] | None = Field(
306+
None,
307+
description=("(Internal) Operation definitions for multi-cube write permissions."),
218308
)
219309

220310

0 commit comments

Comments
 (0)