Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Agent conversation: short first line, named jobs, phase timing on cards

Bowen Xue5ea9991a9950
diff --git a/freevideo_engine/agent/comfy.py b/freevideo_engine/agent/comfy.py
index 3b2ff7d..2fe945f 100644
--- a/freevideo_engine/agent/comfy.py
+++ b/freevideo_engine/agent/comfy.py
@@ -188,7 +188,10 @@ class ComfyPort:
from ..comfy_progress import STATE
with STATE.lock:
row = STATE.rows.get(str(node))
- return json.loads(json.dumps(row['message'])) if row else None
+ if not row:
+ return None
+ # How old the message is, as a reopened page gets it, so a bar can go on from where the engine is now.
+ return dict(json.loads(json.dumps(row['message'])), age_seconds=max(0., STATE.clock() - row['measured']))
async def submit(self, graph, extra):
if self.handler is None:
diff --git a/freevideo_engine/agent/guide.py b/freevideo_engine/agent/guide.py
index c727736..49f35a9 100644
--- a/freevideo_engine/agent/guide.py
+++ b/freevideo_engine/agent/guide.py
@@ -149,7 +149,8 @@ GUIDE = {
RULES = [
'Finish the job. When the user asks for a video, keep going until the finished video exists. Decide ordinary '
'things yourself: how to split shots, how many takes, which take to keep. Tell the user what you decided in '
- 'one or two sentences at the end, not along the way.',
+ 'one or two sentences at the end, not along the way. Name every video you submit: label is a short name of what '
+ 'it shows, in the user\'s language (2 to 8 Chinese characters, or 1 to 4 words), for example "Seaside at dawn".',
'Solve problems yourself first. Every error has a next field, and often details with alternatives; these are '
'steps that work on this computer. Not enough graphics memory: use a listed alternative (a lower resolution '
'or a shorter video) and try again. A take is not good: make another; if it is still not good after two more, '
@@ -182,7 +183,8 @@ RULES = [
RULES_ZH = [
'把任务做完。用户要求生成视频时,持续推进,直到成片生成。如何拆分镜头、拍几条、选哪一条等普通决定,'
- '由你自己做。最后用一两句话告诉用户你做了哪些决定,不要每做一步都请用户决定。',
+ '由你自己做。最后用一两句话告诉用户你做了哪些决定,不要每做一步都请用户决定。'
+ '提交的每条视频都起个名字:label 写拍的是什么,用用户的语言,2 到 8 个字,例如“清晨海边”。',
'先自己解决问题。每个错误都有 next 字段,details 里也常有可选方案;这些是在本机可行的处理步骤。'
'显存不足时,从列出的方案中选择较低分辨率或较短时长重试。一条拍得不好就再拍;再拍两条仍不满意,'
'换一种描述,不要反复提交同一个要求。队列繁忙时,用 wait=25 等待该任务,不要不停查询。'
@@ -353,7 +355,8 @@ def connection_guide(root, base, lang=None, offers=None):
'call("POST", "/connect/hello", {"client": "Local Agent", "via": "http"})',
'print(call("GET", ""))',
'# Only after the user asks for a video:',
- '# job = call("POST", "/jobs", {"prompt": "USER_REQUEST", "ref": "shot-1"})["job"]',
+ '# label is the short name the user sees on the job, in their language: what the video shows, 2 to 8 characters.',
+ '# job = call("POST", "/jobs", {"prompt": "USER_REQUEST", "label": "SHORT NAME", "ref": "shot-1"})["job"]',
'# job = call("GET", "/jobs/" + job["id"] + "?wait=25")',
'# Poll the same ID until succeeded. Retry a lost submission using the same ref.',
'# Download base origin + job["result"]["video"]["url"] with the same Authorization header.',
@@ -386,26 +389,32 @@ def connection_guide(root, base, lang=None, offers=None):
conversation='用户会在 FreeVideo 的“AI 全自动”页里直接和你说话,你的话也显示在那里。'
'连接后先调一次等待接口 GET ' + base + PREFIX + '/inbox?wait=50(MCP 用不带 id 的 freevideo_wait),'
'回应里的 session 就是这段对话;往 POST ' + base + PREFIX + '/sessions/{session}/events 发 '
- '{"type":"message","text":"…"}(MCP 用 freevideo_session_post),把上面那段自我介绍发到这里。'
+ '{"type":"message","text":"…"}(MCP 用 freevideo_session_post)。在这里先只说一句话,不超过 20 个字,'
+ '不列条目、不举例(页面上已经有例句),例如“连上了。告诉我想做什么视频。”'
'然后守在这段对话里:再调等待接口,它最多约 50 秒返回;"again": true 表示用户还没说话,'
'马上再调下一次,一次接一次,不限次数。没有消息不是结束的理由:不要结束这一轮回复,'
'不要停下来问用户——你一停,用户在 FreeVideo 里说的话就没人听了。'
'用命令行调接口时,每次等待单独发一条命令(一条命令里不写循环,超时设到 60 秒以上),'
'返回后接着发下一条。'
- '收到话(inbox 里每条的 text)就去做;做完把结果用一两句话发回同一个 session,再接着等。'
+ '收到话(inbox 里每条的 text)先回一句再动手,例如“好的,开始生成。”:只一句,不复述尺寸、'
+ '时长这些参数,也不说预计时间(任务卡上都有)。做完再说一句短的,例如“好了。”,'
+ '或者一句用户需要知道的话,发回同一个 session,再接着等。'
'这段对话里不要新建会话。只有用户明确让你停,才停。' if zh else
'The user talks to you inside FreeVideo, in the Autopilot view, and your words are shown there. '
'After connecting, call the wait once: GET ' + base + PREFIX + '/inbox?wait=50 (MCP: freevideo_wait '
'without id). Its "session" is this conversation; POST ' + base + PREFIX + '/sessions/{session}/events '
- 'with {"type":"message","text":"..."} (MCP: freevideo_session_post) and say the introduction above '
- 'there. Then stay in this conversation: call the wait again; it answers within about 50 seconds, and '
+ 'with {"type":"message","text":"..."} (MCP: freevideo_session_post). Say only one short sentence '
+ 'there first, at most 12 words, no list and no examples (the page already shows examples), for example '
+ '"Connected. Tell me what video you want." Then stay in this conversation: call the wait again; it answers within about 50 seconds, and '
'"again": true means the user has not spoken yet, so call it again at once, time after time, with no '
'limit. Nothing new is not a reason to finish: do not end your reply and do not stop to ask the '
'user, because once you stop nobody hears what the user says in FreeVideo. From a command line, '
'each wait is its own command (no loop inside one command, timeout above 60 seconds); when it '
'returns, run the next one. '
- 'When words arrive (text of each inbox row), do what they ask, post the result in one or two '
- 'sentences to the same session, and wait again. Do not create another session for this conversation. '
+ 'When words arrive (text of each inbox row), answer with one sentence before you start, for example '
+ '"OK, starting.": one sentence only, without repeating size or length and without an estimate (the '
+ 'job card shows them). When it is done say one short sentence, for example "Done.", or one thing the '
+ 'user needs to know, to the same session, and wait again. Do not create another session for this conversation. '
'Stop only when the user clearly tells you to.',
rules=RULES_ZH if zh else RULES,
fallback='如果你无法执行命令、读取本地文件或连接到这台电脑,请如实告诉用户:'
diff --git a/freevideo_engine/agent/jobs.py b/freevideo_engine/agent/jobs.py
index 4681945..d507f7e 100644
--- a/freevideo_engine/agent/jobs.py
+++ b/freevideo_engine/agent/jobs.py
@@ -967,6 +967,32 @@ class Jobs:
return dict(phase=row.get('_phase') or ('running' if row['status'] == 'running' else 'queued'),
**({'detail': row['_detail']} if row.get('_detail') else {}))
+ def estimate(self, row):
+ """The engine's own timing of the current phase, for a page that moves its bar between two messages
+ the way the creation panel does. Only keys the engine sent."""
+ if row['status'] not in ('queued', 'running', 'cancelling'):
+ return None
+ try:
+ if row.get('chain_id'):
+ # A video in several parts has one bar over all of them; the engine times each part by itself.
+ chain = self.chain(row['chain_id'])
+ message = self.port.progress(chain['node']) or {} if chain['count'] == 1 and chain.get('node') else {}
+ elif row['kind'] == 'generate' and row.get('comfy'):
+ message = self.port.progress(row['comfy']['node']) or {}
+ else:
+ return None
+ except Exception:
+ return None
+ value = {key: message[key] for key in ('age_seconds', 'phase', 'done', 'total', 'display_fraction',
+ 'step_elapsed_seconds', 'estimated_step_seconds') if message.get(key) is not None}
+ overall = message.get('overall') if isinstance(message.get('overall'), dict) else {}
+ overall = {key: overall[key] for key in ('fraction', 'estimated', 'status', 'phase_start_fraction', 'phase_weight',
+ 'phase_seconds', 'phase_elapsed_seconds', 'sampling_time_weighted')
+ if overall.get(key) is not None}
+ if overall:
+ value['overall'] = overall
+ return value or None
+
# Scheduling ----------------------------------------------------------------------------------------
def active(self):
return [r for r in self.rows() if r['status'] in ACTIVE]
diff --git a/freevideo_engine/agent/routes.py b/freevideo_engine/agent/routes.py
index a2b2982..22d48cd 100644
--- a/freevideo_engine/agent/routes.py
+++ b/freevideo_engine/agent/routes.py
@@ -13,6 +13,7 @@ from inspect import isawaitable
import logging
import math
import os
+import re
from pathlib import Path
import secrets
import stat
@@ -710,13 +711,32 @@ def register():
# Every answer to the agent carries the user's unread words, so a recent call will hear them too.
return dict(connected=connected, name=shown, listening=connected and (chat['waiting'] > 0 or now - seen < 90))
+ def chat_name(said):
+ """A job the agent left unnamed is called by what the user asked for: the first words after a colon."""
+ text = re.split(r'[::]', said or '', maxsplit=1)[-1].strip()
+ text = re.split(r'[,。!?;、,.!?;\n]', text, maxsplit=1)[0].strip() or text
+ if not text:
+ return None
+ if text.isascii():
+ return text if len(text) <= 24 else text[:25].rsplit(' ', 1)[0][:24]
+ return text[:8]
+
+ def chat_card(row, fold):
+ card = activity_item(row, card=True)
+ if not card.get('label') and fold is not None:
+ card['label'] = fold['names'].get(row['id'])
+ estimate = jobs.estimate(row)
+ if estimate:
+ card['progress']['estimate'] = estimate
+ return card
+
def chat_fold(store, sid):
"""The session as the page shows it: sentences, the jobs made along the way, and questions."""
fold = chat['folds'].get(sid)
if fold is None:
while len(chat['folds']) >= 8:
chat['folds'].pop(next(iter(chat['folds'])))
- fold = chat['folds'][sid] = dict(seq=0, items=[], jobs={}, asked={}, sent={}, ids={})
+ fold = chat['folds'][sid] = dict(seq=0, items=[], jobs={}, asked={}, sent={}, ids={}, names={}, said=None)
while store.get(sid)['last_seq'] > fold['seq']:
rows = store.events(sid, after=fold['seq'], limit=500)
if not rows:
@@ -726,10 +746,13 @@ def register():
base = dict(seq=row['seq'], at=row['at'], type=row['type'])
if row['type'] == 'message':
fold['items'].append(dict(base, role='user' if row['by'] == 'user' else 'agent', text=row['text']))
+ if row['by'] == 'user':
+ fold['said'] = row['text']
elif row['type'] == 'step' and row['state'] == 'done':
job = (row.get('refs') or {}).get('job')
if job and job not in fold['jobs']:
fold['jobs'][job] = row['seq']
+ fold['names'][job] = chat_name(fold['said'])
fold['items'].append(dict(base, type='job', job=job))
elif row['type'] == 'confirm':
if row['state'] == 'asked':
@@ -786,10 +809,10 @@ def register():
now = time.time()
shown = {r['id']: r for r in mine if r['status'] in ACTIVE or (r.get('finished_at') or 0) > now - 1800}
shown.update((i['job'], known[i['job']]) for i in items if i['type'] == 'job')
- value['jobs'] = {identity: activity_item(row, card=True) for identity, row in shown.items()}
+ value['jobs'] = {identity: chat_card(row, fold) for identity, row in shown.items()}
value['current'] = current['id'] if current else None
if current and current['id'] not in value['jobs']:
- value['jobs'][current['id']] = activity_item(current, card=True)
+ value['jobs'][current['id']] = chat_card(current, fold)
return value
return reply(await asyncio.to_thread(read))
@@ -800,8 +823,9 @@ def register():
store = work_sessions()
sid = chat_session(store)
rows = jobs.rows()
- current = chat_current(rows, sid, chat['folds'].get(sid))[1] if sid else None
- return dict(agent=agent_state(), current=activity_item(current, card=True) if current else None,
+ fold = chat_fold(store, sid) if sid else None
+ current = chat_current(rows, sid, fold)[1] if sid else None
+ return dict(agent=agent_state(), current=chat_card(current, fold) if current else None,
active=sum(1 for r in rows if r['status'] in ACTIVE))
return reply(await asyncio.to_thread(read))