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.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: llmstatemachine-0.1.0.tar.gz
  • Upload date:
  • Size: 8.2 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.1.0.tar.gz
Algorithm Hash digest
SHA256 89bfa3e652c5326b5da8be535e053aff90cf954e16e78ee286302e84b1b0face
MD5 e4cc7a63e1b4e384d188ac72654e758d
BLAKE2b-256 09372db43b78e6717c9e0a6919ca176e714f4a148f809a568a4809c2f8a2e454

See more details on using hashes here.

File details

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

File metadata

  • Download URL: llmstatemachine-0.1.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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5511a5cca42319d2fbaced056d072bbcaa36a14ffbad24d9cb3a14210f49428b
MD5 aa48354dddd987d82be61790e7334203
BLAKE2b-256 7a6a272bf6495dda13465ce523e1435b05af663cba9de64401a8eacf68bb47b1

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