Skip to main content

Python SDK for interacting with the Mentat agent

Project description

Mentat SDK

A Python client SDK for interacting with the Mentat web server.

Features

  • Configuration Management: Access server configuration
  • Notifications: Create notifications with possible responses and handle user interactions
  • Commands: Execute commands received from the server and report progress

Installation

Using Poetry (recommended)

poetry add mentat-sdk

Using pip

pip install mentat-sdk

Quick Start

import logging
from mentat_sdk import MentatClient, MentatLogger

# Initialize a logger
logger = MentatLogger("my_app")

# Create a client instance
client = MentatClient(
    host="0.0.0.0",  # Default host
    port=8765,       # Default port
    log_level=logging.INFO
)

# Access configuration
config = client.config
logger.info(f"Server configuration: {config}")

# Create a notification
notification_id = client.create_notification(
    title="System Update Available",
    description="A new system update is available. Would you like to install it now?",
    possible_responses=["Accept", "Decline"],
    response_callback=lambda notification_id, response: logger.info(f"User selected: {response}")
)

# Check for notification response later
has_response, response = client.get_notification_response(notification_id)
if has_response:
    logger.info(f"Response received: {response}")

Working with Commands

Register handlers for commands from the server:

from mentat_sdk import MentatLogger

# Initialize a logger
logger = MentatLogger("command_handler")

def handle_system_restart(command_id, parameters):
    # Acknowledge the command
    client.acknowledge_command(
        command_id=command_id,
        has_progress_percentage=True,
        progress_steps={
            "0": "Starting",
            "1": "Shutting down services",
            "2": "Restarting system",
            "3": "Done"
        }
    )
    
    try:
        # Update progress
        client.update_command_progress(
            command_id=command_id,
            progress_step="Starting",
            progress_step_status="started",
            progress_percentage=10
        )
        
        # ... perform the actual work ...
        
        # Complete the command
        client.command_executed(command_id)
    except Exception as e:
        logger.error(f"Command execution failed: {e}")
        # Report error
        client.command_execution_error(command_id, str(e))

# Register the handler
client.register_command_handler("system_restart", handle_system_restart)

Full Example

See the tests/running.py file for a complete example of using the SDK.

License

MIT

For Contributors

Development Setup

  1. Clone the repository

    git clone https://github.com/ylan-skoz/mentat-sdk.git
    cd mentat-sdk
    
  2. Install dependencies with Poetry

    poetry install
    
  3. Run tests

    poetry run pytest
    

Releasing a New Version

This package uses GitHub Actions for automated testing and deployment to PyPI. To release a new version:

  1. Update version in both files:

    • pyproject.toml: Update the version field
    • mentat_sdk/__init__.py: Update the __version__ variable
  2. Create a git tag with the version number:

    git tag v0.1.1
    git push origin v0.1.1
    
  3. The GitHub Actions workflow will automatically:

    • Run tests against multiple Python versions
    • Build the package
    • Publish to PyPI if all tests pass

Note: You'll need a PyPI API token stored as a GitHub repository secret named PYPI_API_TOKEN.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mentat_sdk-0.1.1.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mentat_sdk-0.1.1-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file mentat_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: mentat_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mentat_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f1698ec35f06cb42ff592e542910e567be5307b1afcd0da500ec13920d984f08
MD5 afa7d87801f83e05233b48c45192172b
BLAKE2b-256 33f4bf2deb70f4032d4a9d3305a3d70e9fc7abb6d870851defac6bf0cd5933d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for mentat_sdk-0.1.1.tar.gz:

Publisher: publish.yml on ylan-skoz/mentat-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mentat_sdk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mentat_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mentat_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 56a5259e91b10fff4ec222c8fe9400e0c0cb7c02b666f9400898ee01c169ecd5
MD5 6e762b6db822b00f43dc3c3c78f544b3
BLAKE2b-256 bd2c0036ed9f63f5f99154af29cca6ac374783bb33582b186ce9b5fb76ca380f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mentat_sdk-0.1.1-py3-none-any.whl:

Publisher: publish.yml on ylan-skoz/mentat-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page