Skip to main content

Modular links library for developing agent communication.

Project description

PyPI version Python versions License Wheel

Overview

ModLink is a flexible Python framework for building agents and actions. It defines interfaces for both natural language and computer interactions, enabling each agent to surface a set of context-specific actions.

See the PATTERN.md for definitions used in ModLink.

Usage

For specific usage, see the examples directory.

After defining your agent and actions, you can integrate additional tools. For instance, you can use AgentArgParser to enable command-line interaction with your agents.

cd modlink
poetry install
poetry shell
python example/agent.py -h
usage: agent.py [-h] {breaker,case,concat,filter,pad,replace,timestamp} ...

Edits text state

positional arguments:
  {breaker,case,concat,filter,pad,replace,timestamp}
                        Actions to perform.
    breaker             Breaks the text into lines using predefined character widths.
    case                Changes the case of the text.
    concat              Concatenates a string on the end of an existing text
    filter              Filters the text based on character types.
    pad                 Pads the text with text.
    replace             Replaces the text with a new value.
    timestamp           Adds a timestamp to the text.

options:
  -h, --help            show this help message and exit

python example/agent.py concat --text " I am here now"
INFO:root:Parsed action: {'action': 'concat', 'text': ' I am here now'}
Action result: 9035 Village Dr, Yosemite Valley, CA 95389, U.S.A. I am here now

Example

from modlink import Agent, agent_name
from modlink.tools.agent_arg_parser import AgentArgParser
import logging

from example.context import ExampleContext


@agent_name(
    name="example-agent",
    role="Edits text state",
)
class ExampleAgent(Agent[ExampleContext]):
    """
    An example implementation of an Agent.
    """

    def attach(self, context: ExampleContext):
        super().attach(context)

        # Add all the actions from a package to the agent
        self._action_registry.add_package("example.actions")

        # Alternatively, add actions individually
        # self._action_registry.add_action(ReplaceAction)


if __name__ == "__main__":
    # Run with python agent.py
    logging.basicConfig(level=logging.DEBUG)

    agent = ExampleAgent()
    agent.attach(ExampleContext())
    result = AgentArgParser(agent).parse_and_perform()
    print(f"Action result: {result}")
    agent.detach()
from pydantic import Field
from modlink.action import Action, action_name

from example.context import ExampleContext


@action_name(
    name="concat",
    description="Concatenates a string on the end of an existing text",
)
class ConcatAction(Action):
    text: str = Field(description="The text to concatenate.")

    def perform(self, context: ExampleContext) -> str:
        context.text += self.text
        return context.text

Contributing

We welcome contributions! If you'd like to contribute, please see our CONTRIBUTING.md for more information.

License

ModLink is licensed under the MIT License. See the LICENSE file for more details.

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

modlink-0.1.0a9.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

modlink-0.1.0a9-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

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