First_agent_template / tools /interactive_cli.py
kumar4372's picture
openai key
3696fe2
#!/usr/bin/env python3
import os
import sys
from tools.dialog_handler import handle_message
from tools import nlu_tool
def prompt_loop():
print("Interactive CLI for collection assistant. Type 'exit' to quit.")
context = {}
while True:
msg = input('You: ').strip()
if msg.lower() in ('exit','quit'):
print('Goodbye')
break
# run NLU first to see what is missing
nlu = nlu_tool.extract_intent_and_slots(msg)
intent = nlu.get('intent')
print(f"(NLU -> intent={intent}, slots={nlu.get('slots')})")
# call handler - it will return either a prompt for missing slot or a confirmation
out = handle_message(msg, context=context)
print('Assistant:', out['response'])
# If handler requested a missing slot (no request created), accept next input as value and append to message
if out.get('request') is None and 'Please provide' in out['response'] or out['response'].endswith('?'):
# ask user to provide the requested info and re-run
follow = input('You (reply): ').strip()
# naive: append to previous message for NLU re-processing
combined = follow
out2 = handle_message(combined, context=context)
print('Assistant:', out2['response'])
if out2.get('request'):
print('Created request:', out2['request'])
if __name__ == '__main__':
prompt_loop()