> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentscope.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Python

> Run ReMe in the host Python process and manage its lifecycle directly.

Use Python integration when the host application needs in-process access and should own ReMe's startup, jobs, and shutdown. For process isolation or a language-neutral boundary, use a shared [ReMe service](/reme/latest/en/integration/services) instead.

## Install ReMe

ReMe requires Python 3.11 or newer:

```bash theme={null}
pip install "reme-ai[core]"
```

## Run ReMe In Process

Load the default configuration, create one `ReMe` application, and bracket every job call with `start()` and `close()`:

```python theme={null}
import asyncio

from reme import ReMe
from reme.config import resolve_app_config


async def main():
    config = resolve_app_config(workspace_dir=".reme")
    app = ReMe(**config)

    await app.start()
    try:
        result = await app.run_job(
            "search",
            query="project decisions",
            limit=5,
        )
        if not result.success:
            raise RuntimeError(result.answer)
        print(result.answer)
    finally:
        await app.close()


asyncio.run(main())
```

`resolve_app_config()` loads ReMe's default jobs and components, then deep-merges the supplied overrides. Constructing `ReMe` from only `workspace_dir` would create an application without the default job definitions.

## Call Jobs

`run_job(name, **kwargs)` is asynchronous and returns a response with `success`, `answer`, and `metadata`. Job names and parameters come from the resolved configuration. Within the started application above, record a conversation with:

```python theme={null}
result = await app.run_job(
    "auto_memory",
    session_id="conversation-42",
    messages=[
        {"role": "user", "content": "Remember that releases happen on Friday."},
        {"role": "assistant", "content": "Understood."},
    ],
)
```

Model-backed jobs such as `auto_memory` require the LLM environment described in the [Quick Start model setup](/reme/latest/en/quickstart#5-enable-memory-refinement-when-needed).

## Lifecycle Rules

* Reuse one application for related calls instead of constructing it per request.
* Call `start()` before `run_job()` so indexes, watchers, and scheduled jobs are initialized.
* Always call `close()` during host shutdown; a `try` / `finally` block is the safest boundary.
* Use a stable `session_id` for repeated updates to the same conversation.
* Do not start a separate `reme start` process for the same in-process application.

ReMe provides the memory result. The host application still decides when to recall, what is durable enough to record, and how returned memory affects an answer.

## AgentScope

When you build an AgentScope agent, use its first-party `ReMeMiddleware` instead of constructing `ReMe` directly. The middleware embeds ReMe in the AgentScope process and can reuse AgentScope chat and embedding models. It writes conversations through `auto_memory` and supports automatic retrieval and the `memory_search` tool.

Install the integration with `pip install "agentscope[reme]"`. AgentScope does not close middleware automatically, so call `await memory.close()` during application shutdown. Read the [AgentScope long-term memory guide](/versions/2.0.6dev/en/building-blocks/long-term-memory#reme) for the complete example, control modes, and session behavior.
