A LangGraph-based extension framework for complex workflow applications, enabling the integration of various AI models and tools into a cohesive system.
Project description
Black LangCube
A LangGraph-based extension framework designed to facilitate the development of complex applications by providing a structured way to define and manage workflows.
🚀 Features
- BaseGraph Framework: Foundational interface for constructing, compiling, and executing stateful workflow graphs
- Data Structures: Pydantic models for scientific article metadata, search strategies, outlines, and more
- LLM Nodes: Pre-built nodes for common language model operations
- Helper Utilities: Token counting, result processing, file management, and workflow utilities
- Subgraph System: Modular subworkflows for translation, output generation, and specialized tasks
- Extensible Architecture: Easy to extend with custom nodes and workflows
📦 Installation
From PyPI (when published):
pip install black_langcube
Development Installation:
git clone https://github.com/cerna-kostka/black-langcube.git
cd black-langcube
pip install -e .
With optional dependencies:
pip install black_langcube[dev,examples]
🏗️ Core Components
BaseGraph
The foundation for building stateful workflow graphs using LangGraph:
from black_langcube.graf.graph_base import BaseGraph, GraphState
class MyCustomGraph(BaseGraph):
def __init__(self, user_message, folder_name, language):
super().__init__(MyGraphState, user_message, folder_name, language)
self.build_graph()
def build_graph(self):
# Add nodes and edges to your workflow
self.add_node("my_node", my_node_function)
self.add_edge(START, "my_node")
self.add_edge("my_node", END)
@property
def workflow_name(self):
return "my_custom_graph"
LLMNode
A base class for defining nodes that interact with language models:
from black_langcube.llm_modules.LLMNodes.LLMNode import LLMNode
class MyCustomNode(LLMNode):
def generate_messages(self):
return [
("system", "You are a helpful assistant"),
("human", self.state.get("user_input", ""))
]
def execute(self, extra_input=None):
result, tokens = self.run_chain(extra_input)
return {"output": result, "tokens": tokens}
Data Structures
Pydantic models for structured data handling:
from black_langcube.data_structures.data_structures import Article, Strategies, Outline
# Use pre-defined data structures
article = Article(topic="AI Research", language="English")
strategies = Strategies(strategy1="Search academic papers", strategy2="Analyze trends")
LLM Nodes
Pre-built nodes for language model operations:
from black_langcube.llm_modules.LLMNodes.LLMNode import LLMNode
class MyCustomNode(LLMNode):
def generate_messages(self):
return [
("system", "You are a helpful assistant"),
("human", self.state.get("user_input", ""))
]
def execute(self, extra_input=None):
result, tokens = self.run_chain(extra_input)
return {"output": result, "tokens": tokens}
📚 Architecture
The library is organized into several key modules:
graf/: Core graph classes and workflow definitionsdata_structures/: Pydantic models for data validationllm_modules/: Language model integration and node definitionshelper_modules/: Utility functions and helper classesmessages/: Message formatting and composition utilitiesprompts/: Prompt templates and configurationsformat_instructions/: Output formatting utilities
🛠️ Usage Examples
Basic Workflow
from black_langcube.graf.graph_base import BaseGraph, GraphState
from langgraph.graph import START, END
class SimpleWorkflow(BaseGraph):
def __init__(self, message, folder, language):
super().__init__(GraphState, message, folder, language)
self.build_graph()
def build_graph(self):
def process_message(state):
return {"result": f"Processed: {state['messages'][-1].content}"}
self.add_node("process", process_message)
self.add_edge(START, "process")
self.add_edge("process", END)
@property
def workflow_name(self):
return "simple_workflow"
# Usage
workflow = SimpleWorkflow("Hello, world!", "output", "English")
result = workflow.run()
Using Subgraphs
from black_langcube.graf.subgrafs.translator_en_subgraf import TranslatorEnSubgraf
# Translation subgraph
translator = TranslatorEnSubgraf(config, subfolder="translations")
result = translator.run(extra_input={
"translation_input": "Bonjour le monde",
"language": "French"
})
🔧 Configuration
The library uses environment variables for configuration. Create a .env file:
OPENAI_API_KEY=your_openai_api_key_here
# optional: LangChain configuration
LANGCHAIN_API_KEY=your_langchain_api_key_here
LANGCHAIN_TRACING_V2=true
📖 Examples
See the examples/ directory for complete working examples:
- Basic Graph: Simple workflow with custom nodes
- Translation Pipeline: Multi-language processing workflow
- Scientific Article Processing: Complex multi-step analysis pipeline
- Custom Data Structures: Extending the framework with your own models
🧪 Development
Setting up development environment:
git clone https://github.com/cerna-kostka/black-langcube.git
cd black-langcube
pip install -e .[dev]
Running tests:
pytest
Code formatting:
black .
isort .
📋 Requirements
- Python 3.9+
- LangChain >= 0.3.24
- LangGraph >= 0.3.7
- Pydantic >= 2.0.0
- OpenAI API access
🤝 Contributing
This is a work in progress and contributions are welcome! Please feel free to:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
📄 License
MIT License (MIT)
⚠️ Note
This library is intended to be used within a larger application context. The code is provided as-is and is actively being improved. Take it with a grain of salt and feel free to contribute improvements!
🔗 Links
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 black_langcube-0.2.1.tar.gz.
File metadata
- Download URL: black_langcube-0.2.1.tar.gz
- Upload date:
- Size: 47.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e22f250c75d7cecb7311994622f2f77f4eb42a6931437a0f45bf565a25a02f0
|
|
| MD5 |
ad24b8d36b49f320ccb366312c97aa0d
|
|
| BLAKE2b-256 |
11658c7b1de456c4c25535d0e51ed3c012526cbf4c3404e8e6c1e2f41607652e
|
Provenance
The following attestation bundles were made for black_langcube-0.2.1.tar.gz:
Publisher:
python-publish.yml on cerna-kostka/black-langcube
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
black_langcube-0.2.1.tar.gz -
Subject digest:
0e22f250c75d7cecb7311994622f2f77f4eb42a6931437a0f45bf565a25a02f0 - Sigstore transparency entry: 1115277028
- Sigstore integration time:
-
Permalink:
cerna-kostka/black-langcube@5a98a919ebf7d359ee7d19bb5610c939c7b00969 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/cerna-kostka
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@5a98a919ebf7d359ee7d19bb5610c939c7b00969 -
Trigger Event:
release
-
Statement type:
File details
Details for the file black_langcube-0.2.1-py3-none-any.whl.
File metadata
- Download URL: black_langcube-0.2.1-py3-none-any.whl
- Upload date:
- Size: 67.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6cf18c5f288eb454db35a85ed85a8e74a44b35a0db0201f7a193331c18a7c4b
|
|
| MD5 |
247ec6d778ef0f89d6ef479101a4f771
|
|
| BLAKE2b-256 |
36a29b882b38895746419ae078d2ea0c5ce9ee426550c99404a2f79e3d659d5e
|
Provenance
The following attestation bundles were made for black_langcube-0.2.1-py3-none-any.whl:
Publisher:
python-publish.yml on cerna-kostka/black-langcube
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
black_langcube-0.2.1-py3-none-any.whl -
Subject digest:
d6cf18c5f288eb454db35a85ed85a8e74a44b35a0db0201f7a193331c18a7c4b - Sigstore transparency entry: 1115277044
- Sigstore integration time:
-
Permalink:
cerna-kostka/black-langcube@5a98a919ebf7d359ee7d19bb5610c939c7b00969 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/cerna-kostka
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@5a98a919ebf7d359ee7d19bb5610c939c7b00969 -
Trigger Event:
release
-
Statement type: