-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgreetings_agent.py
80 lines (51 loc) · 1.79 KB
/
greetings_agent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# You may need to add your working directory to the Python path. To do so, uncomment the following lines of code
# import sys
# sys.path.append("/Path/to/directory/agentic-framework") # Replace with your directory path
import logging
from besser.agent.core.agent import Agent
from besser.agent.core.session import Session
from besser.agent.exceptions.logger import logger
# Configure the logging module (optional)
logger.setLevel(logging.INFO)
# Create the agent
agent = Agent('greetings_agent')
# Load agent properties stored in a dedicated file
agent.load_properties('config.ini')
# Define the platform your agent will use
websocket_platform = agent.use_websocket_platform(use_ui=True)
# STATES
initial_state = agent.new_state('initial_state', initial=True)
hello_state = agent.new_state('hello_state')
good_state = agent.new_state('good_state')
bad_state = agent.new_state('bad_state')
# INTENTS
hello_intent = agent.new_intent('hello_intent', [
'hello',
'hi',
])
good_intent = agent.new_intent('good_intent', [
'good',
'fine',
])
bad_intent = agent.new_intent('bad_intent', [
'bad',
'awful',
])
# STATES BODIES' DEFINITION + TRANSITIONS
initial_state.when_intent_matched(hello_intent).go_to(hello_state)
def hello_body(session: Session):
session.reply('Hi! How are you?')
hello_state.set_body(hello_body)
hello_state.when_intent_matched(good_intent).go_to(good_state)
hello_state.when_intent_matched(bad_intent).go_to(bad_state)
def good_body(session: Session):
session.reply('I am glad to hear that!')
good_state.set_body(good_body)
good_state.go_to(initial_state)
def bad_body(session: Session):
session.reply('I am sorry to hear that...')
bad_state.set_body(bad_body)
bad_state.go_to(initial_state)
# RUN APPLICATION
if __name__ == '__main__':
agent.run()