Skip to main content

Message Mediator.

Project description

sirji-messages

sirji-messages is a comprehensive Python package for creating, parsing, validating, and managing message interactions based on permissions in multi-agent systems or applications.

Installation

pip install sirji-messages

Features and Usage

Message Parsing

Parse structured message strings into Python dictionaries for easy access to the message components.

from sirji_messages import message_parse

# Example message string to parse
message_str = """```
FROM: CODER
TO: USER
ACTION: INFORM
DETAILS: Welcome to sirji-messages. Here's how you can start.
```"""

# Parsing the message
message = message_parse(message_str)
print(message)

Permission Validation

Determine if a specified action is allowed between two agents based on predefined permission rules.

from sirji_messages import permissions_dict, validate_permission, AgentEnum

# Example check if a CODER can QUESTION a USER
is_allowed = validate_permission("CODER", "USER", "QUESTION")
print(f"Is allowed: {is_allowed}")

# Get a direct look at permissions dictionary for CODER sending to USER
print(permissions_dict[(AgentEnum.CODER, AgentEnum.USER)])

Handling Custom Exceptions

Efficiently manage parsing and validation errors with custom exceptions for improved error handling and debugging.

from sirji_messages import MessageParsingError, MessageValidationError, message_parse

try:
    # Attempt parsing an incorrectly formatted message
    message_parse("INCORRECT_FORMAT")
except MessageParsingError as e:
    print(f"Parsing Error: {e}")
except MessageValidationError as e:
    print(f"Validation Error: {e}")

Enums for Intuitive References

Use enums (ActionEnum, AgentEnum) to reference actions and agent types programmatically, enhancing code clarity and reducing errors.

from sirji_messages import ActionEnum, AgentEnum

# Example usage of enums for action and agent reference
action = ActionEnum.ACKNOWLEDGE
agent = AgentEnum.CODER

# Accessing enum properties
print(f"Action: {action.name}, Agent: {agent.full_name}")

# Access to enums using [] is also possible
action = ActionEnum['ACKNOWLEDGE']
agent = AgentEnum['CODER']

Factories for Dynamic Message and Prompt Creation

Utilize factories (MessageFactory, AgentSystemPromptFactory) to instantiate message and prompt classes dynamically based on enums. It simplifies creating custom messages or retrieving specific system prompts without hardcoding class names.

from sirji_messages import MessageFactory, ActionEnum, AgentSystemPromptFactory, AgentEnum

# Message class instantiation from an action enum
message_class = MessageFactory[ActionEnum.INFORM.name]
print(f"Sample INFORM message:\n{message_class().sample()}")

# Generate message using passed template variables
print(f"Generated INFORM message:\n"{message_class().generate({"details": "Some sample information."})}")

# System prompt class instantiation from an agent enum
prompt_class = AgentSystemPromptFactory[AgentEnum.CODER.name]
print(f"CODER system prompt: {prompt_class().system_prompt()}")

Running Tests and Coverage Analysis

Tests can be run, and coverage can be analyzed in a few simple steps:

# Install testing dependencies
pip install pytest coverage

# Execute tests
pytest

# Measure coverage, excluding test files
coverage run --omit="tests/*" -m pytest
coverage report

License

Distributed under the MIT License. See LICENSE for more information.

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

sirji-messages-0.0.2.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

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

sirji_messages-0.0.2-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

Details for the file sirji-messages-0.0.2.tar.gz.

File metadata

  • Download URL: sirji-messages-0.0.2.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.5

File hashes

Hashes for sirji-messages-0.0.2.tar.gz
Algorithm Hash digest
SHA256 d913439fb374aed7d7ceb591df7144db1fab14e648e1d1b62c60be0524dceb22
MD5 2a721030c7d5f33d8a7f6b69732abea0
BLAKE2b-256 242d9b4626ecf4ef42966d5588a1b09c99e832c5ef64b799fee2ba362583b441

See more details on using hashes here.

File details

Details for the file sirji_messages-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: sirji_messages-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 31.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.5

File hashes

Hashes for sirji_messages-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ad214f568fe4518dc6341c6325c2978f5044b24922fa3fa0af2d9326a574a033
MD5 64bb21827fb7b79bb166b56611f20411
BLAKE2b-256 6a03f17cd199d96e5b45181563b64cdffdc8313b1ae278c86f3c6fd368d8ab63

See more details on using hashes here.

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