Skip to main content

StringDALE

String Diagram Agent Language Express (StringDale) is a library for building complex LLM agentic workflows easily using string diagrams.

Motivation

We found current agentic frameworks unnecessarily complex:

  • Too many levels of abstractions and boilerplate code.
  • Too many interfaces to learn
  • To many wrappers to build for our code to fit these frameworks

As a response, we create stringdale which aims to:

  • Have a small interface - making it easier to learn.
  • Non-intrusive - You can use your own functions in stringdale, without fitting them to a complex interface.
  • Have few levels of abstraction - we don’t create tons of wrappers you have to navigate, you bring your own functions and understand exactly what is happening at all times.
  • Make tracing and debugging simple.

Installation

# in an environment with python>=3.10
pip install stringdale

stringdale uses graphviz to draw your diagrams in jupyter notebooks.

Make sure you download and install graphviz on your system if you want diagrams to be rendered.

Usage

Lets look at how to build a RAG workflow

# bring your own LLM based functions
# These can be any function or callable
# for now lets use example ones
from stringdale.chat import Chat
from stringdale.db import ChromaClient

Lets make an example vector db:

chroma_client = ChromaClient()

dog_docs = [
    {
        'id': 'dog1',
        'text': 'The Golden Retriever is a friendly, intelligent breed known for its golden coat. They make excellent family pets and are great with children.',
        'metadata': {'breed': 'Golden Retriever'}
    },
    {
        'id': 'dog2', 
        'text': 'German Shepherds are loyal, protective dogs often used in police work. They are highly trainable and good at various tasks.',
        'metadata': {'breed': 'German Shepherd'}
    },
    {
        'id': 'dog3',
        'text': 'The Golden Retriever is a friendly, intelligent breed with a beautiful golden coat. They are wonderful family pets that get along well with kids.',
        'metadata': {'breed': 'Golden Retriever'}  
    },
    {
        'id': 'dog4',
        'text': 'Huskies are energetic working dogs bred for cold climates. They have thick fur and often blue eyes.',
        'metadata': {'breed': 'Husky'}
    },
    {
        'id': 'dog5',
        'text': 'Siberian Huskies are active working dogs that thrive in cold weather. They are known for their thick coats and striking blue eyes.',
        'metadata': {'breed': 'Husky'} 
    }
]

chroma_client.add_collection("dog_docs",exists_ok=True)
chroma_client.upsert(collection_name="dog_docs",docs=dog_docs)
chroma_client.list(collection_name='dog_docs')
[{'id': 'dog1',
  'text': 'The Golden Retriever is a friendly, intelligent breed known for its golden coat. They make excellent family pets and are great with children.',
  'metadata': {'breed': 'Golden Retriever'},
  'embedding': array([0.05813659, 0.02785078, 0.00372152, ..., 0.0241031 , 0.04067278,
         0.00027733])},
 {'id': 'dog2',
  'text': 'German Shepherds are loyal, protective dogs often used in police work. They are highly trainable and good at various tasks.',
  'metadata': {'breed': 'German Shepherd'},
  'embedding': array([ 0.03066194,  0.00074497,  0.01366658, ..., -0.0081617 ,
         -0.02541033, -0.01031713])},
 {'id': 'dog3',
  'text': 'The Golden Retriever is a friendly, intelligent breed with a beautiful golden coat. They are wonderful family pets that get along well with kids.',
  'metadata': {'breed': 'Golden Retriever'},
  'embedding': array([0.04065013, 0.02587523, 0.01385626, ..., 0.02761683, 0.03554016,
         0.00553581])},
 {'id': 'dog4',
  'text': 'Huskies are energetic working dogs bred for cold climates. They have thick fur and often blue eyes.',
  'metadata': {'breed': 'Husky'},
  'embedding': array([-0.02400597, -0.00190817, -0.02052087, ..., -0.02349378,
         -0.04244469, -0.02794758])},
 {'id': 'dog5',
  'text': 'Siberian Huskies are active working dogs that thrive in cold weather. They are known for their thick coats and striking blue eyes.',
  'metadata': {'breed': 'Husky'},
  'embedding': array([-0.01651848,  0.00581224, -0.02498457, ..., -0.00659932,
         -0.03063537, -0.02282516])}]
rag_chat = Chat(
    model='gpt-4o-mini',
    messages=[
        {'role':'system','content':'''
            You are a helpful assistant that answers questions about dogs.
            I found the following documents that may be relevant to the user's question:
            {% for doc in docs %}
            {{doc['text']}}
            {% endfor %}
            '''},
        {'role':'user','content':'{{question}}'},
    ]
)
# import the basic building blocks
from stringdale import V,E,Define
# define your diagram schema
with Define('hello world') as RAG:
    V('get_docs',chroma_client.query)
    E('Start->get_docs(**)')
        
    V('chat',rag_chat)
    E('get_docs->chat(docs=.)')
    E('Start->chat(question=query)')
    E('chat->End')

RAG.draw()

# run the diagram
diagram = RAG()

diagram_input = {
    'query':'tell me some stuff about golden retrievers',
    'collection_name':'dog_docs',
    'k':2
}

for trace in diagram.run(diagram_input):
    # you can write any logging,tracing logic here
    trace.pprint(file='log_file.txt')
    pass

# after running, access the output 
diagram.output
{'role': 'assistant',
 'content': 'The Golden Retriever is a friendly and intelligent breed known for its beautiful golden coat. They make excellent family pets and are particularly good with children, making them wonderful companions for families.',
 'meta': {'input_tokens': 198, 'output_tokens': 42}}
! cat log_file.txt
! rm log_file.txt
Node Start:
{ 'input': { 'collection_name': 'dog_docs',
             'k': 2,
             'q': 'tell me some stuff about golden retrievers'},
  'output': { 'collection_name': 'dog_docs',
              'k': 2,
              'q': 'tell me some stuff about golden retrievers'}}
================================================================================
Node Start:
{ 'input': { 'collection_name': 'dog_docs',
             'k': 2,
             'query': 'tell me some stuff about golden retrievers'},
  'output': { 'collection_name': 'dog_docs',
              'k': 2,
              'query': 'tell me some stuff about golden retrievers'}}
================================================================================
Node get_docs:
{ 'input': { 'collection_name': 'dog_docs',
             'k': 2,
             'query': 'tell me some stuff about golden retrievers'},
  'output': [ { 'distance': 0.6993070840835571,
                'id': 'dog3',
                'metadata': {'breed': 'Golden Retriever'},
                'text': 'The Golden Retriever is a friendly, intelligent breed '
                        'with a beautiful golden coat. They are wonderful '
                        'family pets that get along well with kids.'},
              { 'distance': 0.7122190594673157,
                'id': 'dog1',
                'metadata': {'breed': 'Golden Retriever'},
                'text': 'The Golden Retriever is a friendly, intelligent breed '
                        'known for its golden coat. They make excellent family '
                        'pets and are great with children.'}]}
================================================================================
Node chat:
{ 'input': { 'docs': [ { 'distance': 0.6993070840835571,
                         'id': 'dog3',
                         'metadata': {'breed': 'Golden Retriever'},
                         'text': 'The Golden Retriever is a friendly, '
                                 'intelligent breed with a beautiful golden '
                                 'coat. They are wonderful family pets that '
                                 'get along well with kids.'},
                       { 'distance': 0.7122190594673157,
                         'id': 'dog1',
                         'metadata': {'breed': 'Golden Retriever'},
                         'text': 'The Golden Retriever is a friendly, '
                                 'intelligent breed known for its golden coat. '
                                 'They make excellent family pets and are '
                                 'great with children.'}],
             'question': 'tell me some stuff about golden retrievers'},
  'output': { 'content': 'The Golden Retriever is a friendly and intelligent '
                         'breed known for its beautiful golden coat. They make '
                         'excellent family pets and are particularly good with '
                         'children, making them wonderful companions for '
                         'families.',
              'meta': {'input_tokens': 198, 'output_tokens': 42},
              'role': 'assistant'}}
================================================================================
Node End:
{ 'input': { 0: { 'content': 'The Golden Retriever is a friendly and '
                             'intelligent breed known for its beautiful golden '
                             'coat. They make excellent family pets and are '
                             'particularly good with children, making them '
                             'wonderful companions for families.',
                  'meta': {'input_tokens': 198, 'output_tokens': 42},
                  'role': 'assistant'}},
  'output': { 'content': 'The Golden Retriever is a friendly and intelligent '
                         'breed known for its beautiful golden coat. They make '
                         'excellent family pets and are particularly good with '
                         'children, making them wonderful companions for '
                         'families.',
              'meta': {'input_tokens': 198, 'output_tokens': 42},
              'role': 'assistant'}}
================================================================================

Reporting Bugs

Found bugs? Missing features? Feel free to open an issue

Contributing

Want to contribute to stringdale? Great! Feel free to submit a PR or discuss a feature you would like to add in the Issues.

To get a working development environment:

# clone the repo
git clone https://github.com/DeanLight/stringdale.git    
cd stringdale

# install stringdale in editable dev mode
pip install -e ".[dev]"

# run pre-commit to install commit hooks
pre-commit install

stringdale is developed using nbdev

# Make changes under nbs/ directory
# ...

# clean and export notebooks into a python library
nbdev_clean && nbdev_export

# make sure tests pass
nbdev_test

# Changing the docs? make sure that they are rendering correctly
nbdev_docs

Metadata

Release files for StringDALE 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for StringDALE 0.5.0
File Size Uploaded
stringdale-0.5.0.tar.gz 2.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for StringDALE 0.5.0
File Interpreter ABI Platform
stringdale-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 2.4 MB

Release files / stringdale-0.5.0.tar.gz

Download URL stringdale-0.5.0.tar.gz
Size 2.3 MB
Tags Source
SHA-256 checksum
How to use checksums
be3ccaf00ebd1e114ab028ab69a4ad84329d2b2a66fcd6c26a03be7f53597f23
BLAKE2b-256 checksum
How to use checksums
8b08d20b36498c941c47bbb704f3556107bb4df1a1543094b4ea8c7f3690195c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.2

Release files / stringdale-0.5.0-py3-none-any.whl

Download URL stringdale-0.5.0-py3-none-any.whl
Size 109.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68276632aa7865e6e40ea6d26cd955a262419b3ee60e880eeb7f0af4b6e02e6e
BLAKE2b-256 checksum
How to use checksums
8625eb50ee2b5df264603da3f4e42622d246de403724a08e63fb758fc1fbaa66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.2

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page