Package: agt
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.InstallationGetting StartedChannelsNLUInstallation# optional: create a virtual environmentpython3-mvenvmyvenvsourcemyvenv/bin/activate# install agtpip3installagtAdditional dependeciesYou may want to install dependencies to connect to channels such as telegram and discord or share components on cocohub.Available dependeciesdiscord - to connect your bot/component to discordtelegram - to connect your bot/component to telegrammsbf - to connect your bot/component to microsoft bot frameworkvendor - publish component on cocohubdsl - Hy DSL for nicer syntax when building components/nluExamples:pipinstallagt[telegram]# or for multiple dependeciespipinstallagt[telegram,dsl]Getting StartedCreate your first botAgent components are python coroutines (note theasync def)We takestateas the first parameter - which is an object that allow us to interact with the environment the component/bot is running onasyncdefmybot(state):# state.user_input() waits for the next user inputuser_input=awaitstate.user_input()# state.say sends a responseawaitstate.say(user_input)Paste this code in a file called example.pyTry it in the terminalpython3-magtexample.mybotChannelsConnecting to channels is easy and just requires using regular Agent componentsTelegramMake 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-botfatherexportTELEGRAM_TOKEN=<Yourtelegrambottoken>
python3-magt.channels.telegramexample.mybotDiscordMake 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.htmlexportDISCORD_KEY=<Yourdiscordbottoken>
python3-magt.channels.discordexample.mybotMicrosoft bot frameworkMake sure to install agt with microsoft bot framework support -pip install agt[msbf]exportMicrosoftAppId=<YourbotMicrosftAppId>exportMicrosoftAppPassword=<YourbotMicrosoftAppPassword>
python3-magt.channels.msbfexample.mybotBasic Language UnderstandingInside agt.nlu we have simple patterns to regex compiler to perform basic understanding tasksCompile simple word patterns to regexSome Examples:intent=Intent(Pattern("the","boy","ate","an","apple"))assertintent("the boy ate an apple")==Trueassertintent("the boy ate an orange")==Falseintent=Intent(Pattern("the","boy","ate","an",AnyWords(min=1,max=1)))assertintent("the boy ate an apple")==Trueassertintent("the boy ate an orange")==Trueintent=Intent(Pattern("the",Words("boy","girl"),"ate","an",AnyWords(min=1,max=1)))assertintent("the boy ate an apple")==Trueassertintent("the boy ate an orange")==Trueassertintent("the girl ate an orange")==Trueassertintent("the girl ate a banana")==Falseintent=Intent(Pattern("the",("boy","girl"),"ate",WordsRegex(r"an?"),AnyWords(min=1,max=1)))assertintent("the boy ate an apple")==Trueassertintent("the boy ate an orange")==Trueassertintent("the girl ate an orange")==Trueassertintent("the girl ate a banana")==Trueassertintent("a nice boy ate an apple")==Falseintent=Intent(Pattern(WILDCARD,Words("boy","girl"),"ate",WordsRegex(r"an?"),AnyWords(min=1,max=1)))assertintent("a nice boy ate an apple")==TruePatterntakes sentence elements and translate each one to optmized regular expression.Intentgroups multiple patterns so if any of the patterns match the intent evals toTrue