Skip to main content

AI Agents as DAGs - Directed Acyclic Graphs

Project description

DAGent - Directed Acyclic Graphs (DAGs) as AI Agents

Dagent Logo

DAGent is an opinionated Python library to create AI Agents quickly without overhead

Quickstart

Installing

  • pip install dagent or rye add dagent
  • Make sure you have the API key of your choice available in system. The default is OPENAI_API_KEY

Get right into it

See dagent/examples/quickstart_simple_agent.py for a quickstart example

DAGent basics

The idea behind dagent is to structure AI agents in to a workflow. This is done through setting each function up as a node in a graph.

The agentic behavior is through the inferring of what function to run through the use of LLMs which is abstracted by a "Decision Node".

Tool

  • A tool is just a function which the LLM can use.
  • It is helpful to have docstrings and annotations to assist the llm infer what is happening. This is recommended for larger functions/tools.

FunctionNode

  • Runs a python function
  • Can be attached to a DecisionNode to be treated as a tool and allow an LLM to choose which function to run

DecisionNode

  • This is where the llm picks a function to run from given options
  • The .compile() method autogenerates and saves tool descriptions under Tool. Run with param force_load=True if there are errors or if an option of tool changes
  • These tool/function descriptions get generated under a Tool_JSON folder. Feel free to edit tool descriptions if the agent is unreliable.

prev_output param for functions:

  • If passing data from one function to another, make sure this param is in the function signature.
  • If extra params get passed in/weird stuff happens add a **kwargs to see if

DAGent Diagram

graph TD
    A[Function Node] --> B[Decision Node]
    B --> C[Function Node]
    B --> E[Function Node]
    D --> F[Function Node]
    E --> G[Decision Node]
    F --> H[Function Node]
    G --> K[Function Node]
    G -- "Pick Function to Run" --> I[Function Node]
    G --> J[Function Node]
    I --> L[Function Node]
    J --> M[Function Node]
    K --> N[Function Node]
    K -- "Run Both " --> S[Function Node]

    %% Additional annotations
    B -- "Use a Function as a tool" --> D[Function Node]

Using Different Models

DAGent supports using different LLM models for inference and tool description generation. You can specify the model when calling call_llm or call_llm_tool, or when compiling the DecisionNode.

For example, to use the groq/llama3-70b-8192 model:

# Using groq with decision node
decision_node1 = DecisionNode('groq/llama3-70b-8192')

# Using ollama with decision node
decision_node2 = DecisionNode('ollama_chat/mistral', api_base="http://localhost:11434")

# Call llm function
output = decision_node2.run(messages=[{'role': 'user', 'content': 'add the numbers 2 and 3'}])

Other things to know

  • prev_output is needed in the function signature if you want to use the value from the prior function's value. Obviously the prior function should have returned something for this to work
  • If there are errors with too many params being passed into a function node, add **kwargs to your function
  • Args can be overriden at any time using the following (this merges the kwargs in the background with priority to the user):
add_two_nums_node.user_params = {
    # param_name : value
    a : 10
}

Acknowledgements

Shoutout to:

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

dagent-0.0.8.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dagent-0.0.8-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file dagent-0.0.8.tar.gz.

File metadata

  • Download URL: dagent-0.0.8.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.2

File hashes

Hashes for dagent-0.0.8.tar.gz
Algorithm Hash digest
SHA256 8dc955484418fbe6459b9a6685fea7b877055eddd0de49f8d5d4556775424bdf
MD5 3e9a8ffd5abbb673d41918f158792d2a
BLAKE2b-256 7ba2fd5077966ba8e3f0f3fbee030320587b0741a0dde2f1273b88a4bdd4d88c

See more details on using hashes here.

File details

Details for the file dagent-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: dagent-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.2

File hashes

Hashes for dagent-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 326f017659ffb96eedaba8fd61a3503c7b83fed92796d61e2a4b66d24e941eb1
MD5 fe30fca11a5cf1dc9484a81e4f033978
BLAKE2b-256 41fbe8eb4cfe928646df8c6feedca485dcf5775965aa2b2de9288b51e76beb61

See more details on using hashes here.

Supported by

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