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
-
Clone the repository
git clone https://github.com/ylan-skoz/mentat-sdk.git cd mentat-sdk
-
Install dependencies with Poetry
poetry install -
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:
-
Update version in both files:
pyproject.toml: Update theversionfieldmentat_sdk/__init__.py: Update the__version__variable
-
Create a git tag with the version number:
git tag v0.1.1 git push origin v0.1.1
-
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1698ec35f06cb42ff592e542910e567be5307b1afcd0da500ec13920d984f08
|
|
| MD5 |
afa7d87801f83e05233b48c45192172b
|
|
| BLAKE2b-256 |
33f4bf2deb70f4032d4a9d3305a3d70e9fc7abb6d870851defac6bf0cd5933d6
|
Provenance
The following attestation bundles were made for mentat_sdk-0.1.1.tar.gz:
Publisher:
publish.yml on ylan-skoz/mentat-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mentat_sdk-0.1.1.tar.gz -
Subject digest:
f1698ec35f06cb42ff592e542910e567be5307b1afcd0da500ec13920d984f08 - Sigstore transparency entry: 188500023
- Sigstore integration time:
-
Permalink:
ylan-skoz/mentat-sdk@f604824fad7cf1428cb606c5ad1e7782ebca1aa4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ylan-skoz
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f604824fad7cf1428cb606c5ad1e7782ebca1aa4 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56a5259e91b10fff4ec222c8fe9400e0c0cb7c02b666f9400898ee01c169ecd5
|
|
| MD5 |
6e762b6db822b00f43dc3c3c78f544b3
|
|
| BLAKE2b-256 |
bd2c0036ed9f63f5f99154af29cca6ac374783bb33582b186ce9b5fb76ca380f
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mentat_sdk-0.1.1-py3-none-any.whl -
Subject digest:
56a5259e91b10fff4ec222c8fe9400e0c0cb7c02b666f9400898ee01c169ecd5 - Sigstore transparency entry: 188500025
- Sigstore integration time:
-
Permalink:
ylan-skoz/mentat-sdk@f604824fad7cf1428cb606c5ad1e7782ebca1aa4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ylan-skoz
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f604824fad7cf1428cb606c5ad1e7782ebca1aa4 -
Trigger Event:
push
-
Statement type: