jupyter-ai-persona-manager


Namejupyter-ai-persona-manager JSON
Version 0.0.3 PyPI version JSON
download
home_pageNone
SummaryThe core manager & registry for AI personas in Jupyter AI
upload_time2025-10-08 18:30:08
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseBSD 3-Clause License Copyright (c) 2025, Project Jupyter All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords jupyter jupyterlab jupyterlab-extension
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # jupyter_ai_persona_manager

[![Github Actions Status](https://github.com/jupyter-ai-contrib/jupyter-ai-persona-manager/workflows/Build/badge.svg)](https://github.com/jupyter-ai-contrib/jupyter-ai-persona-manager/actions/workflows/build.yml)

The core manager & registry for AI personas in Jupyter AI.

This package provides the foundational infrastructure for managing AI personas in Jupyter AI chat environments. It includes:

- **BasePersona**: Abstract base class for creating custom AI personas
- **PersonaManager**: Registry and lifecycle management for personas
- **PersonaAwareness**: Awareness integration for multi-user chat environments
- **Entry Point Support**: Automatic discovery of personas via Python entry points

AI personas are analogous to "bots" in other chat applications, allowing different AI assistants to coexist in the same chat environment. Each persona can have unique behavior, models, and capabilities.

## Adding a New Persona via Entry Points

To create and register a custom AI persona:

### 1. Create Your Persona Class

```python
from jupyter_ai_persona_manager import BasePersona, PersonaDefaults
from jupyterlab_chat.models import Message

class MyCustomPersona(BasePersona):
    @property
    def defaults(self):
        return PersonaDefaults(
            name="MyPersona",
            description="A helpful custom assistant",
            avatar_path="/api/ai/static/custom-avatar.svg",
            system_prompt="You are a helpful assistant specialized in...",
        )

    async def process_message(self, message: Message):
        # Your custom logic here
        response = f"Hello! You said: {message.body}"
        self.send_message(response)
```

### 2. Register via Entry Points

Add to your package's `pyproject.toml`:

```toml
[project.entry-points."jupyter_ai.personas"]
my-custom-persona = "my_package.personas:MyCustomPersona"
```

### 3. Install and Restart

```bash
pip install your-package
# Restart JupyterLab to load the new persona
```

Your persona will automatically appear in Jupyter AI chats and can be @-mentioned by name.

## Loading Personas from .jupyter Directory

For development and local customization, personas can be loaded from the `.jupyter/personas/` directory:

### Directory Structure

```
.jupyter/
└── personas/
    ├── my_custom_persona.py
    ├── research_assistant.py
    └── debug_helper.py
```

### File Requirements

- Place Python files in `.jupyter/personas/` (not directly in `.jupyter/`)
- Filename must contain "persona" (case-insensitive)
- Cannot start with `_` or `.` (treated as private/hidden)
- Must contain a class inheriting from `BasePersona`

### Example Local Persona

**File: `.jupyter/personas/my_persona.py`**

```python
from jupyter_ai_persona_manager import BasePersona, PersonaDefaults
from jupyterlab_chat.models import Message

class MyLocalPersona(BasePersona):
    @property
    def defaults(self):
        return PersonaDefaults(
            name="Local Dev Assistant",
            description="A persona for local development",
            avatar_path="/api/ai/static/jupyternaut.svg",
            system_prompt="You help with local development tasks.",
        )

    async def process_message(self, message: Message):
        self.send_message(f"Local persona received: {message.body}")
```

### Refreshing Personas

Use the `/refresh-personas` slash command in any chat to reload personas without restarting JupyterLab:

```
/refresh-personas
```

This allows for iterative development - modify your local persona files and refresh to see changes immediately.

Development install:

```
micromamba install uv jupyterlab nodejs=22
jlpm
jlpm dev:install
```

## Requirements

- JupyterLab >= 4.0.0

## Install

To install the extension, execute:

```bash
pip install jupyter_ai_persona_manager
```

## Uninstall

To remove the extension, execute:

```bash
pip uninstall jupyter_ai_persona_manager
```

## Troubleshoot

If you are seeing the frontend extension, but it is not working, check
that the server extension is enabled:

```bash
jupyter server extension list
```

If the server extension is installed and enabled, but you are not seeing
the frontend extension, check the frontend extension is installed:

```bash
jupyter labextension list
```

## Contributing

### Development install

Note: You will need NodeJS to build the extension package.

The `jlpm` command is JupyterLab's pinned version of
[yarn](https://yarnpkg.com/) that is installed with JupyterLab. You may use
`yarn` or `npm` in lieu of `jlpm` below.

```bash
# Clone the repo to your local environment
# Change directory to the jupyter_ai_persona_manager directory
# Install package in development mode
pip install -e ".[test]"
# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Server extension must be manually installed in develop mode
jupyter server extension enable jupyter_ai_persona_manager
# Rebuild extension Typescript source after making changes
jlpm build
```

You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.

```bash
# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm watch
# Run JupyterLab in another terminal
jupyter lab
```

With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).

By default, the `jlpm build` command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:

```bash
jupyter lab build --minimize=False
```

### Development uninstall

```bash
# Server extension must be manually disabled in develop mode
jupyter server extension disable jupyter_ai_persona_manager
pip uninstall jupyter_ai_persona_manager
```

In development mode, you will also need to remove the symlink created by `jupyter labextension develop`
command. To find its location, you can run `jupyter labextension list` to figure out where the `labextensions`
folder is located. Then you can remove the symlink named `@jupyter-ai/persona-manager` within that folder.

### Testing the extension

#### Server tests

This extension is using [Pytest](https://docs.pytest.org/) for Python code testing.

Install test dependencies (needed only once):

```sh
pip install -e ".[test]"
# Each time you install the Python package, you need to restore the front-end extension link
jupyter labextension develop . --overwrite
```

To execute them, run:

```sh
pytest -vv -r ap --cov jupyter_ai_persona_manager
```

#### Frontend tests

This extension is using [Jest](https://jestjs.io/) for JavaScript code testing.

To execute them, execute:

```sh
jlpm
jlpm test
```

#### Integration tests

This extension uses [Playwright](https://playwright.dev/docs/intro) for the integration tests (aka user level tests).
More precisely, the JupyterLab helper [Galata](https://github.com/jupyterlab/jupyterlab/tree/master/galata) is used to handle testing the extension in JupyterLab.

More information are provided within the [ui-tests](./ui-tests/README.md) README.

### Packaging the extension

See [RELEASE](RELEASE.md)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "jupyter-ai-persona-manager",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "jupyter, jupyterlab, jupyterlab-extension",
    "author": null,
    "author_email": "Project Jupyter <jupyter@googlegroups.com>",
    "download_url": "https://files.pythonhosted.org/packages/40/46/29d68398296565ee71c404c701c3ec5f1828a59edf4aaa5597e98a1663ae/jupyter_ai_persona_manager-0.0.3.tar.gz",
    "platform": null,
    "description": "# jupyter_ai_persona_manager\n\n[![Github Actions Status](https://github.com/jupyter-ai-contrib/jupyter-ai-persona-manager/workflows/Build/badge.svg)](https://github.com/jupyter-ai-contrib/jupyter-ai-persona-manager/actions/workflows/build.yml)\n\nThe core manager & registry for AI personas in Jupyter AI.\n\nThis package provides the foundational infrastructure for managing AI personas in Jupyter AI chat environments. It includes:\n\n- **BasePersona**: Abstract base class for creating custom AI personas\n- **PersonaManager**: Registry and lifecycle management for personas\n- **PersonaAwareness**: Awareness integration for multi-user chat environments\n- **Entry Point Support**: Automatic discovery of personas via Python entry points\n\nAI personas are analogous to \"bots\" in other chat applications, allowing different AI assistants to coexist in the same chat environment. Each persona can have unique behavior, models, and capabilities.\n\n## Adding a New Persona via Entry Points\n\nTo create and register a custom AI persona:\n\n### 1. Create Your Persona Class\n\n```python\nfrom jupyter_ai_persona_manager import BasePersona, PersonaDefaults\nfrom jupyterlab_chat.models import Message\n\nclass MyCustomPersona(BasePersona):\n    @property\n    def defaults(self):\n        return PersonaDefaults(\n            name=\"MyPersona\",\n            description=\"A helpful custom assistant\",\n            avatar_path=\"/api/ai/static/custom-avatar.svg\",\n            system_prompt=\"You are a helpful assistant specialized in...\",\n        )\n\n    async def process_message(self, message: Message):\n        # Your custom logic here\n        response = f\"Hello! You said: {message.body}\"\n        self.send_message(response)\n```\n\n### 2. Register via Entry Points\n\nAdd to your package's `pyproject.toml`:\n\n```toml\n[project.entry-points.\"jupyter_ai.personas\"]\nmy-custom-persona = \"my_package.personas:MyCustomPersona\"\n```\n\n### 3. Install and Restart\n\n```bash\npip install your-package\n# Restart JupyterLab to load the new persona\n```\n\nYour persona will automatically appear in Jupyter AI chats and can be @-mentioned by name.\n\n## Loading Personas from .jupyter Directory\n\nFor development and local customization, personas can be loaded from the `.jupyter/personas/` directory:\n\n### Directory Structure\n\n```\n.jupyter/\n\u2514\u2500\u2500 personas/\n    \u251c\u2500\u2500 my_custom_persona.py\n    \u251c\u2500\u2500 research_assistant.py\n    \u2514\u2500\u2500 debug_helper.py\n```\n\n### File Requirements\n\n- Place Python files in `.jupyter/personas/` (not directly in `.jupyter/`)\n- Filename must contain \"persona\" (case-insensitive)\n- Cannot start with `_` or `.` (treated as private/hidden)\n- Must contain a class inheriting from `BasePersona`\n\n### Example Local Persona\n\n**File: `.jupyter/personas/my_persona.py`**\n\n```python\nfrom jupyter_ai_persona_manager import BasePersona, PersonaDefaults\nfrom jupyterlab_chat.models import Message\n\nclass MyLocalPersona(BasePersona):\n    @property\n    def defaults(self):\n        return PersonaDefaults(\n            name=\"Local Dev Assistant\",\n            description=\"A persona for local development\",\n            avatar_path=\"/api/ai/static/jupyternaut.svg\",\n            system_prompt=\"You help with local development tasks.\",\n        )\n\n    async def process_message(self, message: Message):\n        self.send_message(f\"Local persona received: {message.body}\")\n```\n\n### Refreshing Personas\n\nUse the `/refresh-personas` slash command in any chat to reload personas without restarting JupyterLab:\n\n```\n/refresh-personas\n```\n\nThis allows for iterative development - modify your local persona files and refresh to see changes immediately.\n\nDevelopment install:\n\n```\nmicromamba install uv jupyterlab nodejs=22\njlpm\njlpm dev:install\n```\n\n## Requirements\n\n- JupyterLab >= 4.0.0\n\n## Install\n\nTo install the extension, execute:\n\n```bash\npip install jupyter_ai_persona_manager\n```\n\n## Uninstall\n\nTo remove the extension, execute:\n\n```bash\npip uninstall jupyter_ai_persona_manager\n```\n\n## Troubleshoot\n\nIf you are seeing the frontend extension, but it is not working, check\nthat the server extension is enabled:\n\n```bash\njupyter server extension list\n```\n\nIf the server extension is installed and enabled, but you are not seeing\nthe frontend extension, check the frontend extension is installed:\n\n```bash\njupyter labextension list\n```\n\n## Contributing\n\n### Development install\n\nNote: You will need NodeJS to build the extension package.\n\nThe `jlpm` command is JupyterLab's pinned version of\n[yarn](https://yarnpkg.com/) that is installed with JupyterLab. You may use\n`yarn` or `npm` in lieu of `jlpm` below.\n\n```bash\n# Clone the repo to your local environment\n# Change directory to the jupyter_ai_persona_manager directory\n# Install package in development mode\npip install -e \".[test]\"\n# Link your development version of the extension with JupyterLab\njupyter labextension develop . --overwrite\n# Server extension must be manually installed in develop mode\njupyter server extension enable jupyter_ai_persona_manager\n# Rebuild extension Typescript source after making changes\njlpm build\n```\n\nYou can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.\n\n```bash\n# Watch the source directory in one terminal, automatically rebuilding when needed\njlpm watch\n# Run JupyterLab in another terminal\njupyter lab\n```\n\nWith the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).\n\nBy default, the `jlpm build` command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:\n\n```bash\njupyter lab build --minimize=False\n```\n\n### Development uninstall\n\n```bash\n# Server extension must be manually disabled in develop mode\njupyter server extension disable jupyter_ai_persona_manager\npip uninstall jupyter_ai_persona_manager\n```\n\nIn development mode, you will also need to remove the symlink created by `jupyter labextension develop`\ncommand. To find its location, you can run `jupyter labextension list` to figure out where the `labextensions`\nfolder is located. Then you can remove the symlink named `@jupyter-ai/persona-manager` within that folder.\n\n### Testing the extension\n\n#### Server tests\n\nThis extension is using [Pytest](https://docs.pytest.org/) for Python code testing.\n\nInstall test dependencies (needed only once):\n\n```sh\npip install -e \".[test]\"\n# Each time you install the Python package, you need to restore the front-end extension link\njupyter labextension develop . --overwrite\n```\n\nTo execute them, run:\n\n```sh\npytest -vv -r ap --cov jupyter_ai_persona_manager\n```\n\n#### Frontend tests\n\nThis extension is using [Jest](https://jestjs.io/) for JavaScript code testing.\n\nTo execute them, execute:\n\n```sh\njlpm\njlpm test\n```\n\n#### Integration tests\n\nThis extension uses [Playwright](https://playwright.dev/docs/intro) for the integration tests (aka user level tests).\nMore precisely, the JupyterLab helper [Galata](https://github.com/jupyterlab/jupyterlab/tree/master/galata) is used to handle testing the extension in JupyterLab.\n\nMore information are provided within the [ui-tests](./ui-tests/README.md) README.\n\n### Packaging the extension\n\nSee [RELEASE](RELEASE.md)\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License\n        \n        Copyright (c) 2025, Project Jupyter\n        All rights reserved.\n        \n        Redistribution and use in source and binary forms, with or without\n        modification, are permitted provided that the following conditions are met:\n        \n        1. Redistributions of source code must retain the above copyright notice, this\n           list of conditions and the following disclaimer.\n        \n        2. Redistributions in binary form must reproduce the above copyright notice,\n           this list of conditions and the following disclaimer in the documentation\n           and/or other materials provided with the distribution.\n        \n        3. Neither the name of the copyright holder nor the names of its\n           contributors may be used to endorse or promote products derived from\n           this software without specific prior written permission.\n        \n        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.",
    "summary": "The core manager & registry for AI personas in Jupyter AI",
    "version": "0.0.3",
    "project_urls": {
        "Bug Tracker": "https://github.com/jupyter-ai-contrib/jupyter-ai-persona-manager/issues",
        "Homepage": "https://github.com/jupyter-ai-contrib/jupyter-ai-persona-manager",
        "Repository": "https://github.com/jupyter-ai-contrib/jupyter-ai-persona-manager.git"
    },
    "split_keywords": [
        "jupyter",
        " jupyterlab",
        " jupyterlab-extension"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4241d3d85c4a74bec7b9ca697932ba6980ba41d3be3c85176240068bcbaa5382",
                "md5": "f910fb4442712bc2ed9ec420cd78ecc6",
                "sha256": "2f20d82b043d59e4749fc20d0e8f28a656a5924cf1fad3dc029ed6b3c99113ba"
            },
            "downloads": -1,
            "filename": "jupyter_ai_persona_manager-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f910fb4442712bc2ed9ec420cd78ecc6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 40712,
            "upload_time": "2025-10-08T18:30:07",
            "upload_time_iso_8601": "2025-10-08T18:30:07.215447Z",
            "url": "https://files.pythonhosted.org/packages/42/41/d3d85c4a74bec7b9ca697932ba6980ba41d3be3c85176240068bcbaa5382/jupyter_ai_persona_manager-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "404629d68398296565ee71c404c701c3ec5f1828a59edf4aaa5597e98a1663ae",
                "md5": "12b0a1ddfeb5d39d689d9c341d3685b7",
                "sha256": "30c929a931d0bd21488eb5268a9d2d839baee2f4d5c7c1f7f2294f9af3a774f1"
            },
            "downloads": -1,
            "filename": "jupyter_ai_persona_manager-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "12b0a1ddfeb5d39d689d9c341d3685b7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 149699,
            "upload_time": "2025-10-08T18:30:08",
            "upload_time_iso_8601": "2025-10-08T18:30:08.610066Z",
            "url": "https://files.pythonhosted.org/packages/40/46/29d68398296565ee71c404c701c3ec5f1828a59edf4aaa5597e98a1663ae/jupyter_ai_persona_manager-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-08 18:30:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jupyter-ai-contrib",
    "github_project": "jupyter-ai-persona-manager",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "jupyter-ai-persona-manager"
}
        
Elapsed time: 2.20269s