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.2.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.2-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file fsm_llm-0.1.2.tar.gz.

File metadata

  • Download URL: fsm_llm-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 6885bb52f2610afaf534439762bf07ca9c41f98f39458569746310108cfec93f
MD5 cfad91980d31080a6ed33b9015b7e72f
BLAKE2b-256 b42b1bba4915fe2a7ac58a9957235d023ad0a75e8bf9a2707d567ddea7ee8d44

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fsm_llm-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bb0732233b77a59a1f565a80da124193103b9e40dfb7692f7dc189bdfbcc2c3b
MD5 1d41b331827bd562d669eee5c6ad07b2
BLAKE2b-256 37e9b881ad8f7d07b420299a18e7f33b37bfa017318f4fcc009bcaf3fb34b8a2

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