Skip to main content

A Python framework for FSM-based LLM agents

Project description

FSM-based LLM Conversational Agents

This project provides a package framework for creating conversational agents using a Finite State Machine (FSM) powered by Large Language Models (LLMs). It integrates with OpenAI's API and provides an easy way to define states, transitions, and interactions.

This is currently an experimental setup, and also part of a research project I am doing for university. For now it is meant for developers and experimenters mainly. Requires an OpenAI API key (currently tested on gpt-4o-mini).

Features

  • Define states and transitions for your agent using a simple decorator.
  • Handle dynamic conversation flow with flexible state management.
  • Integrates with GPT models to generate responses based on state context.

Installation

  1. Install the package directly from PyPI:

    pip install fsm-llm
    
  2. Set up environment variables: Create a .env file and add your OpenAI API key:

    OPENAI_API_KEY=your-api-key
    OPENAI_ORGANIZATION=your-organization-id
    

Ensure that your .env file is properly loaded. You can use the python-dotenv library to load these variables if they're not automatically loaded.

Usage Example (On/Off Switch)

  1. The LLMStateMachine class is the core of the framework. It handles state transitions based on user input.
from core.fsm import LLMStateMachine

# Create the FSM
fsm = LLMStateMachine(initial_state="START", end_state="END")

Examples

  • Light Switch Agent: A simple agent that asks the user whether they want to turn a light on or off. switch_agent.py
  • Customer Support Agent: A bot that collects user details and assists with customer queries. support_agent.py
  • Medical Triage Agent: A complex agent that helps assess if a medical situation is an emergency and collects patient data. medical_agent.py

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

fsm-llm-0.1.1.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

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

fsm_llm-0.1.1-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file fsm-llm-0.1.1.tar.gz.

File metadata

  • Download URL: fsm-llm-0.1.1.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.4

File hashes

Hashes for fsm-llm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f6b83e76bc01ef7aa71297bb081c8f941d0acd9566bf3454ae276f0b7b12e507
MD5 91be9675a58ca8ec544967669678cba9
BLAKE2b-256 6c4aa38d4748b4f6c315c2bfdd8bf15bb7ebb83d8ecce6e9de1187e958fc3a9e

See more details on using hashes here.

File details

Details for the file fsm_llm-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fsm_llm-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.4

File hashes

Hashes for fsm_llm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3e9b5e4987110e211d1e62c5a6ba2dff1c4ec5ea77525e558ff2ad03eeb33093
MD5 0ceac716a61b5189aca1c50e01c73330
BLAKE2b-256 25b1a0cc63d7b892935e7cc18be56b5d277209b631cd41d8963a0243ad998db0

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