Skip to main content

No project description provided

Project description

Large Language Model State Machine

WIP

NOTE! This project is at this point a draft and a technical concept exploring state machine use for driving LLM Agents to success.

Introduction

The Large Language Model State Machine is a sophisticated framework for building state-driven workflow agents using large language models, like GPT-4. It's designed to streamline the process of handling complex workflows and decision-making processes in automated systems.

Installation

# Clone the repository
git clone https://github.com/robocorp/llm_state_machine

# Install dependencies (if any)
pip install [dependencies]

Usage

To use the Large Language Model State Machine, follow these steps:

  1. Initialize a WorkflowAgentBuilder.
  2. Define states and their respective transitions.
  3. Build the workflow agent and add messages to it.
  4. Run model step by step until DONE.

Example

def focus(argument: str):
    """when searching for texts in the html,

    Parameters
    ----------
    argument : str
        The focused text to find from html.
    """
    output = html_explorer(html_content, focus_text=argument, max_total_length=3000)
    return f"""focus "{argument}":\n```\n{output}\n```""", "INIT"

...

builder = WorkflowAgentBuilder()
builder.add_state_and_transitions("INIT", {focus, select})
builder.add_state_and_transitions("SELECTED_NON_EMPTY", {focus, select, validate})
builder.add_state_and_transitions("VALIDATED", {focus, select, validate, result})
builder.add_end_state("DONE")
workflow_agent = builder.build()
workflow_agent.add_message(
    {
        "role": "system",
        "content": "You are a helpful HTML css selector finding assistant.",
    }
)
workflow_agent.add_message(
    {
        "role": "user",
        "content": (
            "Assignment: Create CSS Selectors Based on Text Content\n"
            "Your task is to develop CSS selectors that can target HTML elements containing specific text contents. "
            "You are provided with a list of example texts. Use these examples to create selectors that can identify "
            "elements containing these texts in a given HTML structure.\n\n"
            "Instructions:\n"
            f"- Use the provided list of examples: {examples_str}.\n"
            "Your goal is to create selectors that are both precise and efficient, tailored to the specific"
            " content and structure of the HTML elements."
        ),
    }
)
for message in workflow_agent.messages:
    print(str(message)[:160])
print(">" * 80)
res = "NO RESULT"
while workflow_agent.current_state != "DONE":
    res = workflow_agent.step()
print(res)

API Reference

WorkflowAgentBuilder

  • add_state_and_transitions(state_name, transition_functions): Define a state and its transitions.
  • add_end_state(state_name): Define an end state for the workflow.
  • build(): Builds and returns a WorkflowAgent.

WorkflowAgent

  • trigger(function_call, args): Triggers a transition in the workflow.
  • add_message(message): Adds a message to the workflow.
  • step(): Executes a step in the workflow.

License

Apache 2.0

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

llmstatemachine-0.2.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

llmstatemachine-0.2.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file llmstatemachine-0.2.0.tar.gz.

File metadata

  • Download URL: llmstatemachine-0.2.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Darwin/23.0.0

File hashes

Hashes for llmstatemachine-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8b418ae21e11297f98bd434a1b8214e13d4a54eefaf41a3cff9662df8fc44880
MD5 ee14de128d7583bfa6892e790fa8e78e
BLAKE2b-256 4ce9a37470e906b92be3bdf93bc33454125dab1ec322fc69f72a986ab5a6d7c1

See more details on using hashes here.

Provenance

File details

Details for the file llmstatemachine-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: llmstatemachine-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Darwin/23.0.0

File hashes

Hashes for llmstatemachine-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c11a8d263872e1ad03f8a38bb631bd09369c5b0bcc7cc352e292e8f5de79cbb
MD5 3f28141abb19757c4dc3a7f7320a9c94
BLAKE2b-256 2538f341213938fd6dd70a0c4dbb55fbd6284581f47150ca9b525f342743285b

See more details on using hashes here.

Provenance

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