Interactive REPL-Style Agents
Input loops, history, and multi-turn conversation in terminal agents.
What Is a REPL-Style Agent?
A REPL (Read-Eval-Print Loop) is an interactive terminal session where you type input, get output, and continue. Chat agents in the terminal work exactly this way: the user types a message, the agent responds, and the conversation continues until the user exits.
The Basic REPL Loop
The simplest REPL is a while True loop that reads user input with input(), processes it, and prints the result. The loop runs forever until the user signals exit.
def run_agent_repl():
print('Agent started. Type /exit to quit.')
conversation_history = []
while True:
user_input = input('You: ').strip()
if not user_input:
continue # ignore empty lines
if user_input == '/exit':
print('Goodbye!')
break
# Add user message to history
conversation_history.append({'role': 'user', 'content': user_input})
# Get agent response (here we use a placeholder)
agent_reply = f'[Agent reply to: {user_input}]'
conversation_history.append({'role': 'assistant', 'content': agent_reply})
print(f'Agent: {agent_reply}')
run_agent_repl()All lessons in this course
- Building Command-Line Agent Interfaces
- Interactive REPL-Style Agents
- Argument Parsing and Help Text
- Streaming Output in CLI Agents