Skip to main content

Modular composable chatbot development

Project description

Gitter chat

Agent (agt)

Agent is a high-level toolkit for building chatbots using conversational components. Try Agent if you want to make your chatbot modular using composable components.

Installation

# optional: create a virtual environment
python3 -m venv myvenv
source myvenv/bin/activate

# install agt
pip3 install agt

Additional dependecies

You may want to install dependencies to connect to channels such as telegram and discord or share components on cocohub.

Available dependecies

  • discord - to connect your bot/component to discord
  • telegram - to connect your bot/component to telegram
  • msbf - to connect your bot/component to microsoft bot framework
  • vendor - publish component on cocohub
  • dsl - Hy DSL for nicer syntax when building components/nlu

Examples:

pip install agt[telegram]
# or for multiple dependecies
pip install agt[telegram,dsl]

Getting Started

Create your first bot

Agent components are python coroutines (note the async def)

We take state as the first parameter - which is an object that allow us to interact with the environment the component/bot is running on

async def mybot(state):
    # state.user_input() waits for the next user input
    user_input = await state.user_input()

    # state.say sends a response
    await state.say(user_input)

Paste this code in a file called example.py

Try it in the terminal

python3 -m agt example.mybot

Channels

Connecting to channels is easy and just requires using regular Agent components

Telegram

Make sure to install agt with telegram support - pip install agt[telegram]

Create a new bot and get telegram token from Telegram botfather using this guide: https://core.telegram.org/bots#6-botfather

export TELEGRAM_TOKEN=<Your telegram bot token>
python3 -m agt.channels.telegram example.mybot

Discord

Make sure to install agt with discord support - pip install agt[discord]

Create a new bot account and get a token using this guide: https://discordpy.readthedocs.io/en/latest/discord.html

export DISCORD_KEY=<Your discord bot token>
python3 -m agt.channels.discord example.mybot

Microsoft bot framework

Make sure to install agt with microsoft bot framework support - pip install agt[msbf]

export MicrosoftAppId=<Your bot Microsft App Id>
export MicrosoftAppPassword=<Your bot Microsoft App Password>
python3 -m agt.channels.msbf example.mybot

Basic Language Understanding

Inside agt.nlu we have simple patterns to regex compiler to perform basic understanding tasks

Compile simple word patterns to regex

Some Examples:

intent = Intent(
    Pattern("the", "boy", "ate", "an", "apple")
)
assert intent("the boy ate an apple") == True
assert intent("the boy ate an orange") == False

intent = Intent(
    Pattern("the", "boy", "ate", "an", AnyWords(min=1, max=1))
)
assert intent("the boy ate an apple") == True
assert intent("the boy ate an orange") == True

intent = Intent(
    Pattern("the", Words("boy", "girl"), "ate", "an", AnyWords(min=1, max=1))
)
assert intent("the boy ate an apple") == True
assert intent("the boy ate an orange") == True
assert intent("the girl ate an orange") == True
assert intent("the girl ate a banana") == False

intent = Intent(
    Pattern("the", ("boy", "girl"), "ate", WordsRegex(r"an?"), AnyWords(min=1, max=1))
)
assert intent("the boy ate an apple") == True
assert intent("the boy ate an orange") == True
assert intent("the girl ate an orange") == True
assert intent("the girl ate a banana") == True
assert intent("a nice boy ate an apple") == False

intent = Intent(
    Pattern(WILDCARD, Words("boy", "girl"), "ate", WordsRegex(r"an?"), AnyWords(min=1, max=1))
)
assert intent("a nice boy ate an apple") == True

Pattern takes sentence elements and translate each one to optmized regular expression.

Intent groups multiple patterns so if any of the patterns match the intent evals to True

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

agt-0.5.1.tar.gz (30.1 kB view details)

Uploaded Source

Built Distribution

agt-0.5.1-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file agt-0.5.1.tar.gz.

File metadata

  • Download URL: agt-0.5.1.tar.gz
  • Upload date:
  • Size: 30.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for agt-0.5.1.tar.gz
Algorithm Hash digest
SHA256 792009207e80e0c3609e3e260c625c5f12b9a5934c7c5d67328c0074531075a6
MD5 137e1870e0d03af0a8b5b1dd1335e2c7
BLAKE2b-256 bf88704c92a558f0d5e4885e5237a82c24cd7395c198b85f8ba7e8b5a577940f

See more details on using hashes here.

File details

Details for the file agt-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: agt-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 32.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for agt-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1a860bf3b7080bab7d68ca915bd07c38d6e21880fb4b0a70011bd0c33172c99
MD5 16934fadfcd1a446515f693d2d98cfe7
BLAKE2b-256 37b66b969275e7242c91ce5a49a6a4b4d19eb7b03288b9e8e80b8db9f02c2ee6

See more details on using hashes here.

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