Modular links library for developing agent communication.
Project description
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
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 modlink-0.1.0a9.tar.gz.
File metadata
- Download URL: modlink-0.1.0a9.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.13.2 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5366ec0b8fd98b78c1b436f1adef02142163d14e9b50428a1c12379575bb55c
|
|
| MD5 |
3ba01b559d31d968a1fe83d4a58d6907
|
|
| BLAKE2b-256 |
9cdb9f887b6b544a8bed44e551cc4c040ea03d7505e10b7e2304727d84b85169
|
File details
Details for the file modlink-0.1.0a9-py3-none-any.whl.
File metadata
- Download URL: modlink-0.1.0a9-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.13.2 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2b10f0ea9d8e88cfc0e2e2036b06d9fbf85312e5998f7d4e47bc77a214f1c88
|
|
| MD5 |
bdb4e45d51aa5a705bc0c883ab3cf5c3
|
|
| BLAKE2b-256 |
5289454789c0a9f1078c49dde991bcb105edb209ad6c9a3c87727d970531aecb
|