Marvin allows agents to interact with users through the command line interface (CLI). This is useful for:
- Gathering user input during task execution
- Creating interactive chatbots
- Building conversational interfaces
- Getting user confirmation or choices
- Providing real-time feedback
Note that this is not a replacement for a proper user interface, and is intended primarily for local prototyping and development.
Enabling CLI Interaction
To enable CLI interaction for a task, set the cli
parameter to True
:
import marvin
# Get user input
name = marvin.run(
"Ask for the user's name",
cli=True
)
print(f"The user's name is: {name}")
Interactive Conversations
Use threads to maintain context in interactive conversations:
import marvin
with marvin.Thread() as thread:
# Get user preferences
preferences = marvin.run(
"Ask about the user's movie preferences",
cli=True
)
# Make a recommendation
recommendation = marvin.run(
"Recommend a movie based on their preferences"
)
# Ask for feedback
feedback = marvin.run(
"Ask if they'd like another recommendation",
cli=True
)
Example: Interactive Survey
Here’s a complete example of an interactive survey:
import marvin
from typing import Literal
from dataclasses import dataclass
@dataclass
class Survey:
name: str
age: int
interests: list[str]
experience_level: Literal["beginner", "intermediate", "advanced"]
with marvin.Thread() as thread:
# Create an interactive agent
agent = marvin.Agent(
name="Surveyor",
cli=True,
instructions="Conduct a friendly survey about programming experience."
)
# Run the survey
result = marvin.run(
"Conduct a programming survey",
agents=[agent],
result_type=Survey
)
print(result)