A lightweight AI workflow builder
Project description
Aitor
Aitor is a Python framework for building intelligent, memory-enabled agents (aitors) that can execute complex workflows. It provides a robust foundation for creating asynchronous, task-based applications with a focus on clean architecture and developer experience.
Features
- Memory-Enabled Agents: Create stateful agents that maintain memory between interactions.
- Directed Acyclic Graph (DAG) Workflows: Design complex task dependencies with simple syntax.
- Async Support: Built-in asynchronous processing with both blocking and non-blocking APIs.
- Thread Safety: Secure memory access across concurrent operations.
- Visualization: Built-in workflow visualization tools.
Installation
pip install aitor
Quick Start
Creating a Basic Aitor
import asyncio
from typing import List
from aitor import Aitor
async def text_processor_handler(message: str, aitor: Aitor[List[str]]):
# Store message in memory
current_memory = aitor.get_memory()
current_memory.append(message)
aitor.set_memory(current_memory)
# Process the message
processed_msg = f"Processed: {message.upper()}"
print(f"[{aitor.name}] {processed_msg}")
# If workflow is attached, run it with the message
if aitor.workflow:
return await asyncio.to_thread(aitor.workflow.execute, message)
return processed_msg
async def main():
# Create an aitor directly
aitor = Aitor(
initial_memory=[], # Start with empty list
name="TextAitor",
on_receive_handler=text_processor_handler
)
# Use the blocking 'ask' method
result1 = await aitor.ask("Hello, world!")
print(f"Ask result: {result1}")
# Use the non-blocking 'tell' method
aitor.tell("This is a non-blocking call")
# Always shutdown when done
Aitor.shutdown()
if __name__ == "__main__":
asyncio.run(main())
Building Workflows
from aitor.aitorflows import Aitorflow
from aitor.task import task
# Define some tasks for a workflow
@task
def clean_text(text: str) -> str:
return text.strip()
@task
def count_words(text: str) -> dict:
return {"word_count": len(text.split())}
@task
def analyze_sentiment(text: str) -> dict:
# Simple sentiment analysis
positive_words = ["good", "great", "excellent", "happy"]
negative_words = ["bad", "terrible", "sad", "unhappy"]
score = 0
for word in text.lower().split():
if word in positive_words:
score += 1
elif word in negative_words:
score -= 1
return {"sentiment_score": score}
# Create and define workflow
workflow = Aitorflow(name="Text Analysis")
clean = clean_text
word_counter = count_words
sentiment = analyze_sentiment
# Define workflow dependencies
clean >> [word_counter, sentiment]
# Add tasks to workflow
workflow.add_task(clean)
workflow.add_task(word_counter)
workflow.add_task(sentiment)
Attaching Workflows to Aitors
async def main():
aitor = Aitor(
initial_memory=[],
name="TextAitor",
on_receive_handler=text_processor_handler
)
# Attach workflow
aitor.attach_workflow(workflow)
# Use 'ask' with the workflow
result2 = await aitor.ask("This is a great example!")
print(f"Workflow result: {result2}")
# Check aitor's memory
print(f"Aitor memory: {aitor.get_memory()}")
Aitor.shutdown()
if __name__ == "__main__":
asyncio.run(main())
Core Concepts
Aitors
Aitors are memory-enabled agents that can process messages either synchronously or asynchronously. They are defined as generic classes typed by their memory structure.
Key Features:
- Typed memory management
- Thread-safe operations
- Workflow integration
- Async processing
Workflows (Aitorflows)
Workflows define processing pipelines as directed acyclic graphs of tasks.
Key Features:
- Task dependency management
- Parallel task execution
- Input/output validation
- Visualization tools
Tasks
Tasks are the building blocks of workflows, encapsulating individual operations.
Key Features:
- Simple
>>operator for defining dependencies - Flexible input/output handling
- Decorator support for clean syntax
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for 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
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 aitor-0.1.0.tar.gz.
File metadata
- Download URL: aitor-0.1.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d7249992292f42fd002994108132d63787748da9aa385c16331dabecf6f329a
|
|
| MD5 |
bdd32a439dcb078147daf72581f3ed98
|
|
| BLAKE2b-256 |
a598f667c6bb39d67e44c026c8591a743558a431834af50ad7a015c9dc36d760
|
File details
Details for the file aitor-0.1.0-py3-none-any.whl.
File metadata
- Download URL: aitor-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f6eb542127fec396b24f76b727b4b00ac0282296483c399e25e1915939e2761
|
|
| MD5 |
ccb70d7a1a174117cfc4f0071d0be9bf
|
|
| BLAKE2b-256 |
a4870efedb81669c77d936c3fca62a9005275f4a15e348c6eb98eeb0798e1c5f
|