Skip to main content

Sirji messaging protocol implementation to create, validate and parse messages.

Project description

Sirji Logo

Sirji is an agentic AI framework for software development.

Built with ❤️ by True Sparrow

GitHub License GitHub commit activity GitHub Issues or Pull Requests PyPI sirji-messages

GitHub Repo stars GitHub forks GitHub watchers

Sirji Messages

sirji-messages is a PyPI package that implements the Sirji messaging protocol with the following highlights:

  • Message Factory: A factory that provides a Message class for a given action.
  • Message Parser: Parse structured message strings into Python dictionaries for easy access to the message components.
  • Allowed Response Templates: Provides the part of the system prompt describing allowed Response Templates for a given agent pair.
  • Custom Exceptions: A set of custom exceptions thrown by the message parser.
  • Enums for Agents and Actions: Provides easy auto-completion while writing code.

Installation

Setup Virtual Environment

We recommend setting up a virtual environment to isolate Python dependencies, ensuring project-specific packages without conflicting with system-wide installations.

python3 -m venv venv
source venv/bin/activate

Install Package

Install the package from PyPi:

pip install sirji-messages

Usage

Message Factory

A factory that provides a Message class for a given action.

from sirji_messages import MessageFactory, ActionEnum

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

# Generate message using passed template variables
message_str = message_class().generate({
            "from_agent_id": "EXECUTOR",
            "to_agent_id": "CODER",
            "summary": "Empty",
            "body": "Done."})
            
print(f"Generated RESPONSE message:\n{message_str}")

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: EXECUTOR
TO: CODER
ACTION: RESPONSE
SUMMARY: Welcome to sirji-messages
BODY: Welcome to sirji-messages. Here's how you can start.
***"""

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

Allowed Response Templates

Provides the part of the system prompt describing allowed Response Templates for a given agent pair.

from sirji_messages import allowed_response_templates, AgentEnum

# Generate allowed response templates
response_templates_str = allowed_response_templates(AgentEnum.ANY, AgentEnum.EXECUTOR)
print(response_templates_str)

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 Agents and Actions

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.INVOKE_AGENT
agent = AgentEnum.ORCHESTRATOR

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

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

For Contributors

  1. Fork and clone the repository.
  2. Create and activate the virtual environment as described above.
  3. Install the package in editable mode by running the following command from repository root:
pip install -e .

Running Tests and Coverage Analysis

Follow the above mentioned steps for "contributors", before running the test cases.

# 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.28.tar.gz (20.2 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.28-py3-none-any.whl (46.6 kB view details)

Uploaded Python 3

File details

Details for the file sirji_messages-0.0.28.tar.gz.

File metadata

  • Download URL: sirji_messages-0.0.28.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for sirji_messages-0.0.28.tar.gz
Algorithm Hash digest
SHA256 68b6deb844248fef045ac8f21c2c55d016c485160e4eef7e177d8525a6646fa8
MD5 9d1753dbebd6d0c0dfbe2c4e06493966
BLAKE2b-256 e28cbddd454dca9c45609ea28f1bd9e767164d81d189ef8d6b1cb681535d1c47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sirji_messages-0.0.28-py3-none-any.whl
Algorithm Hash digest
SHA256 e01faa38897bf3482efaa2892276af568ed6d46d25d624c46c9892979a71546e
MD5 d90dd87dde123ff5803af4a949a84ea9
BLAKE2b-256 db9d1b7692cc49dc46e7c48431f737a0c0e7ef84091ff2bf1e33140a23f025ae

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