datamongus
11/04/2025, 12:13 AMMarvin
11/04/2025, 12:13 AMMarvin
11/04/2025, 12:17 AMmarvin.run(..., cli=True) call stay open forever. The CLI “prompt” is a tool, not a session manager. To keep an interactive session going, the supported pattern is to run a loop yourself and persist state across turns with a Thread (for chat history) and optional Memory (for long‑term facts).
A few specifics:
- In current Marvin, marvin.run does not take a cli flag. The “CLI” is available as a tool at marvin.tools.interactive.cli.cli. You can add that tool to an agent so it can ask the user questions during a single run, but it won’t keep the run open indefinitely.
- For a REPL that survives multiple messages, keep a single Thread (optionally with a fixed id so it’s restorable) and loop on input/output. Attach a shared Memory if you want durable recall across sessions.
Example REPL pattern (supported/recommended):
from marvin import Agent, Thread, Memory, run
from marvin.tools.interactive.cli import cli as ask_user
# Optional long-term memory shared across runs
mem = Memory(key="my-long-term-mem", description="Long-term facts about the user/session")
assistant = Agent(
name="Assistant",
instructions="You are a helpful assistant.",
tools=[ask_user], # lets the agent ask the user for input mid-run
memories=[mem], # long-term memory (optional)
)
# Use a stable thread id to persist conversation history to the local DB
thread = Thread(id="my-cli-session")
print("Type 'quit' to exit.")
with thread:
while True:
user = input("You: ")
if user.strip().lower() in {"quit", "exit"}:
break
# Use marvin.run so we can explicitly pass thread and agent(s)
reply = run(user, agents=[assistant], thread=thread)
print(f"Assistant: {reply}")
Notes:
- Thread maintains short‑term message history; it’s persisted to a local SQLite DB by default. You can change the DB via MARVIN_DATABASE_URL.
- Memory stores long‑term facts retrievable across sessions; using the same Memory key lets you share it across runs/threads.
- The CLI tool (ask_user) is useful if the agent needs to ask follow‑up questions within a single run, but it won’t keep the run “open” on its own.
Docs for deeper reference:
- Interactivity pattern: Interactivity
- Threads: Threads concept
- Memory: Memory pattern
If you can share which Marvin version you’re on, I can tailor an example exactly to it. But in current Marvin, the “loop + persistent Thread (+ optional Memory)” pattern is the supported way to run indefinitely. Your current approach is on the right track—just swap to a single Thread to avoid “new interactive runs” and keep history clean.