Skip to main content

Enables creation of workflows for Dria Agents

Project description

Dria Workflows

Dria Workflows enables the creation of workflows for Dria Agents.

Installation

You can install Dria Workflows using pip:

pip install dria_workflows

Usage Example

Here's a simple example of how to use Dria Workflows:

import logging
from dria_workflows import WorkflowBuilder, Operator, Write, Edge, validate_workflow_json


def main():
    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

    builder = WorkflowBuilder()

    # Add a step to your workflow
    builder.generative_step(id="write_poem", prompt="Write a poem as if you are Kahlil Gibran", operator=Operator.GENERATION, outputs=[Write.new("poem")])
    
    # Define the flow of your workflow
    flow = [Edge(source="write_poem", target="_end")]
    builder.flow(flow)
    
    # Set the return value of your workflow
    builder.set_return_value("poem")
    
    # Build your workflow
    workflow = builder.build()

    # Validate your workflow
    validate_workflow_json(workflow.model_dump_json(indent=2, exclude_unset=True, exclude_none=True))

    # Save workflow
    workflow.save("poem_workflow.json")


if __name__ == "__main__":
    main()

Here is a more complex workflow

import logging
from dria_workflows import WorkflowBuilder, ConditionBuilder, Operator, Write, GetAll, Read, Push, Edge, Expression, validate_workflow_json


def main():
    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

    # Give a starting memory as input
    builder = WorkflowBuilder(memory={"topic_1":"Linear Algebra", "topic_2":"CUDA"})

    # Add steps to your workflow
    builder.generative_step(id="create_query", prompt="Write down a search query related to following topics: {{topic_1}} and {{topic_2}}. If any, avoid asking questions asked before: {{history}}", operator=Operator.GENERATION, inputs=[GetAll.new("history", False)], outputs=[Write.new("search_query")])
    builder.generative_step(id="search", prompt="{{search_query}}", operator=Operator.FUNCTION_CALLING, outputs=[Write.new("result"), Push.new("history")])
    builder.generative_step(id="evaluate", prompt="Evaluate if search result is related and high quality to given question by saying Yes or No. Question: {{search_query}} , Search Result: {{result}}. Only output Yes or No and nothing else.", operator=Operator.GENERATION, outputs=[Write.new("is_valid")])

    # Define the flow of your workflow
    flow = [
        Edge(source="create_query", target="search"),
        Edge(source="search", target="evaluate"),
        Edge(source="evaluate", target="_end", condition=ConditionBuilder.build(expected="Yes", target_if_not="create_query", expression=Expression.CONTAINS, input=Read.new("is_valid", True))),
    ]
    builder.flow(flow)

    # Set the return value of your workflow
    builder.set_return_value("result")

    # Build your workflow
    workflow = builder.build()
    validate_workflow_json(workflow.model_dump_json(indent=2, exclude_unset=True, exclude_none=True))

    workflow.save("search_workflow.json")


if __name__ == "__main__":
    main()

Detailed docs soon. andthattoo

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

dria_workflows-0.2.2.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

dria_workflows-0.2.2-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file dria_workflows-0.2.2.tar.gz.

File metadata

  • Download URL: dria_workflows-0.2.2.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/23.6.0

File hashes

Hashes for dria_workflows-0.2.2.tar.gz
Algorithm Hash digest
SHA256 33c1eff24e0fa5f89932f0fa168a7d27c2188c869eaccc3ce9312f71db37769a
MD5 a68f3894324cd149cc88b74b4f975ca7
BLAKE2b-256 c3e45c4098341289f7d100e4fd2134ffc6235b73f452929083093ffdcd4ee7ca

See more details on using hashes here.

File details

Details for the file dria_workflows-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: dria_workflows-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/23.6.0

File hashes

Hashes for dria_workflows-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c9f246694414b8eeb48798a69892e0e15a1479f1dd16158001006d387946abe9
MD5 312ea994f26e035237f30677ddcc23ab
BLAKE2b-256 79686efd5c18ddeaef987624f30e077ddd548dec89a563287e2a5bda256bcfb0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page