MCPcopy
hub / github.com/mem0ai/mem0 / add

Function add

cli/python/src/mem0_cli/app.py:255–316  ·  view source on GitHub ↗

Add a memory from text, messages, file, or stdin. Examples: mem0 add "I prefer dark mode" --user-id alice echo "text" | mem0 add -u alice mem0 add --file msgs.json -u alice -o json

(
    text: str | None = typer.Argument(None, help="Text content to add as a memory."),
    user_id: str | None = typer.Option(
        None, "--user-id", "-u", help="Scope to user.", rich_help_panel="Scope"
    ),
    agent_id: str | None = typer.Option(
        None, "--agent-id", help="Scope to agent.", rich_help_panel="Scope"
    ),
    app_id: str | None = typer.Option(
        None, "--app-id", help="Scope to app.", rich_help_panel="Scope"
    ),
    run_id: str | None = typer.Option(
        None, "--run-id", help="Scope to run.", rich_help_panel="Scope"
    ),
    messages: str | None = typer.Option(None, "--messages", help="Conversation messages as JSON."),
    file: Path | None = typer.Option(None, "--file", "-f", help="Read messages from JSON file."),
    metadata: str | None = typer.Option(None, "--metadata", "-m", help="Custom metadata as JSON."),
    immutable: bool = typer.Option(False, "--immutable", help="Prevent future updates."),
    no_infer: bool = typer.Option(False, "--no-infer", help="Skip inference, store raw."),
    expires: str | None = typer.Option(None, "--expires", help="Expiration date (YYYY-MM-DD)."),
    categories: str | None = typer.Option(
        None, "--categories", help="Categories (JSON array or comma-separated)."
    ),
    output: str = typer.Option(
        "text", "--output", "-o", help="Output format: text, json, quiet.", rich_help_panel="Output"
    ),
    api_key: str | None = typer.Option(
        None,
        "--api-key",
        help="Override API key.",
        envvar="MEM0_API_KEY",
        rich_help_panel="Connection",
    ),
    base_url: str | None = typer.Option(
        None, "--base-url", help="Override API base URL.", rich_help_panel="Connection"
    ),
)

Source from the content-addressed store, hash-verified

253
254@app.command(rich_help_panel="Memory")
255def add(
256 text: str | None = typer.Argument(None, help="Text content to add as a memory."),
257 user_id: str | None = typer.Option(
258 None, "--user-id", "-u", help="Scope to user.", rich_help_panel="Scope"
259 ),
260 agent_id: str | None = typer.Option(
261 None, "--agent-id", help="Scope to agent.", rich_help_panel="Scope"
262 ),
263 app_id: str | None = typer.Option(
264 None, "--app-id", help="Scope to app.", rich_help_panel="Scope"
265 ),
266 run_id: str | None = typer.Option(
267 None, "--run-id", help="Scope to run.", rich_help_panel="Scope"
268 ),
269 messages: str | None = typer.Option(None, "--messages", help="Conversation messages as JSON."),
270 file: Path | None = typer.Option(None, "--file", "-f", help="Read messages from JSON file."),
271 metadata: str | None = typer.Option(None, "--metadata", "-m", help="Custom metadata as JSON."),
272 immutable: bool = typer.Option(False, "--immutable", help="Prevent future updates."),
273 no_infer: bool = typer.Option(False, "--no-infer", help="Skip inference, store raw."),
274 expires: str | None = typer.Option(None, "--expires", help="Expiration date (YYYY-MM-DD)."),
275 categories: str | None = typer.Option(
276 None, "--categories", help="Categories (JSON array or comma-separated)."
277 ),
278 output: str = typer.Option(
279 "text", "--output", "-o", help="Output format: text, json, quiet.", rich_help_panel="Output"
280 ),
281 api_key: str | None = typer.Option(
282 None,
283 "--api-key",
284 help="Override API key.",
285 envvar="MEM0_API_KEY",
286 rich_help_panel="Connection",
287 ),
288 base_url: str | None = typer.Option(
289 None, "--base-url", help="Override API base URL.", rich_help_panel="Connection"
290 ),
291) -> None:
292 """Add a memory from text, messages, file, or stdin.
293
294 Examples:
295 mem0 add "I prefer dark mode" --user-id alice
296 echo "text" | mem0 add -u alice
297 mem0 add --file msgs.json -u alice -o json
298 """
299 from mem0_cli.commands.memory import cmd_add
300
301 backend, config = _get_backend_and_config(api_key, base_url)
302 ids = _resolve_ids(config, user_id=user_id, agent_id=agent_id, app_id=app_id, run_id=run_id)
303
304 cmd_add(
305 backend,
306 text,
307 **ids,
308 messages=messages,
309 file=file,
310 metadata=metadata,
311 immutable=immutable,
312 no_infer=no_infer,

Callers

nothing calls this directly

Calls 3

cmd_addFunction · 0.90
_get_backend_and_configFunction · 0.85
_resolve_idsFunction · 0.85

Tested by

no test coverage detected