Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

feat(bots): Bot prompt sections, Bots roster, typed mentions, and Bot labels (#3120)

Call White3d04c1d4a46a
diff --git a/core/agent_input.py b/core/agent_input.py
index cde6b3fb5..f6f110d12 100644
--- a/core/agent_input.py
+++ b/core/agent_input.py
@@ -62,6 +62,8 @@ def _token(value: Any) -> str:
#: How an input no person typed begins (``AgentInputMetadata.render``).
HARNESS_MARKER = "[Harness:"
+#: A Bot's permanent Session id, ``ses_<handle>`` (``core.bots.BOT_HANDLE_PATTERN``).
+_BOT_SESSION = re.compile(r"ses_([a-z][a-z0-9-]{1,23})")
#: The dispatch provenance a ``[Harness: ...]`` label is built from: all a merged batch's
#: Message keeps of each later Delivery's provenance (``merged_harness_sources``).
@@ -92,9 +94,12 @@ def harness_source(spec: Mapping[str, Any]) -> str:
source_kind = _token(spec.get("source_kind"))
actor = str(spec.get("source_actor") or "").strip()
# The Agent Session that authored the input: a callback names the delegated run's
- # Session, an agent-authored run its caller (``source_actor``).
+ # Session, an agent-authored run its caller (``source_actor``). A Bot's Session is
+ # ``ses_<handle>``, a namespace generated ids never enter (``docs/plans/bots.md`` D2),
+ # so it is named as the Bot.
session = _token(spec.get("source_session_id")) or (_token(actor) if source_kind == "agent" else "")
- origin = f"from #{session}" if session else ""
+ bot = _BOT_SESSION.fullmatch(session)
+ origin = f"from @<bot:{bot.group(1)}>" if bot else f"from #{session}" if session else ""
if trigger == "watch":
parts = ["Watch", definition, name]
elif trigger == "scheduled":
diff --git a/core/bots.py b/core/bots.py
index 5ffaca854..31a15e7eb 100644
--- a/core/bots.py
+++ b/core/bots.py
@@ -34,6 +34,7 @@ from core.vibe_agents import (
VibeAgent,
VibeAgentStore,
agent_bot_record,
+ is_builtin_default_agent,
is_main_bot_agent,
normalize_agent_name,
)
@@ -556,6 +557,14 @@ class BotService:
raise BotError(
"bot_agent_backend", f"Only Vibey Agents can be Bots; '{agent.name}' runs on {agent.backend}"
)
+ if is_builtin_default_agent(agent):
+ # Vibey stays an ordinary worker: listed among Agents, mentionable, and the default (bots.md D9).
+ raise BotError("bot_agent_builtin", f"The built-in Agent '{agent.name}' cannot be a Bot", status=409)
+ if _is_default_agent(conn, agent):
+ raise BotError(
+ "bot_agent_default", f"Agent '{agent.name}' is the default Agent; choose another default first",
+ status=409,
+ )
if not agent.enabled:
raise BotError("bot_agent_disabled", f"Agent '{agent.name}' is disabled", status=409)
if agent_bot_record(agent) is not None:
@@ -710,6 +719,15 @@ class BotService:
)
+def _is_default_agent(conn: Connection, agent: VibeAgent) -> bool:
+ """Whether the instance's recorded default Agent is ``agent``: new chats start on it, so it cannot be a Bot."""
+ name = VibeAgentStore._default_agent_name(conn)
+ try:
+ return bool(name) and normalize_agent_name(name) == agent.normalized_name
+ except ValueError:
+ return False
+
+
class _HandleMoved(Exception):
"""The handle checked before the insert was taken by the time the insert held the lock."""
diff --git a/core/prompt_registry.py b/core/prompt_registry.py
index 779b53ede..cf98c99bd 100644
--- a/core/prompt_registry.py
+++ b/core/prompt_registry.py
@@ -76,6 +76,10 @@ PROMPT_MODULES: tuple[PromptModule, ...] = (
PromptModule("runtime-snapshot-open", "Codex Runtime Snapshot Start", "runtime-snapshot-open.md", trailing_newlines=2),
PromptModule("base-capabilities-intro", "Base Capabilities Intro", "base-capabilities-intro.md", trailing_newlines=2),
PromptModule("agent-working-principles", "Agent Working Principles", "agent-working-principles.md", trailing_newlines=2),
+ # A Bot's own sections (docs/plans/bots.md): byte-stable for every Turn of the Bot and for its forks.
+ PromptModule("bot-identity-prompt", "You Are a Bot", "bot-identity.md", trailing_newlines=2, placeholders=("display_name", "handle", "role_sentence", "session_id")),
+ PromptModule("bot-memory-prompt", "Bot Memory", "bot-memory.md", trailing_newlines=2, placeholders=("workdir", "session_id")),
+ PromptModule("bot-main-prompt", "The Main Bot", "bot-main.md", trailing_newlines=2),
PromptModule("session-start-prompt", "Session Start Prompt", "session-start.md", trailing_newlines=2, placeholders=("default_session_id",)),
PromptModule("forked-session-prompt", "Forked Session Prompt", "forked-session.md", trailing_newlines=2, placeholders=("source_session_id", "default_session_id")),
PromptModule("base-capabilities-body", "Base Capabilities Body", "base-capabilities.md", trailing_newlines=1),
@@ -86,7 +90,7 @@ PROMPT_MODULES: tuple[PromptModule, ...] = (
PromptModule("quick-replies-prompt", "Quick Replies Prompt", "quick-replies.md", leading_newlines=1, trailing_newlines=1),
PromptModule("vault-routing-prompt", "Vault Routing Prompt", "vault.md", leading_newlines=1, trailing_newlines=1),
PromptModule("harness-routing-prompt", "Harness Routing Prompt", "harness.md", leading_newlines=1, trailing_newlines=1),
- PromptModule("harness-agents-prompt", "Harness Agents Prompt", "harness-agents.md", placeholders=("enabled_agents_rows",)),
+ PromptModule("harness-agents-prompt", "Harness Agents Prompt", "harness-agents.md", placeholders=("bots_rows", "enabled_agents_rows")),
PromptModule("project-context-prompt", "Project Context and History Prompt", "project-context.md", leading_newlines=1, trailing_newlines=1),
PromptModule("mcp-capabilities-prompt", "MCP Capabilities", "mcp.md", leading_newlines=1, trailing_newlines=1),
PromptModule("mcp-pagination-prompt", "MCP Discovery Pagination", "mcp-pagination.md", trailing_newlines=1),
diff --git a/core/prompts/bot-identity.md b/core/prompts/bot-identity.md
new file mode 100644
index 000000000..ae9f8909d
--- /dev/null
+++ b/core/prompts/bot-identity.md
@@ -0,0 +1,4 @@
+## You are a Bot
+You are {display_name}, the Bot `@<bot:{handle}>`.{role_sentence} Your one permanent conversation is Session `{session_id}`: it never ends, older context is condensed as it grows, and its full record stays readable with `vibe data query` on `session_id = '{session_id}'`.
+
+Other Bots and Agents also message you there. Their inputs begin with a `[Harness: ...]` line naming the sender; they are not the user's words. Your reply returns to the sender automatically, so answer in your reply and do not send it back with `--bot`.
diff --git a/core/prompts/bot-main.md b/core/prompts/bot-main.md
new file mode 100644
index 000000000..06be565b8
--- /dev/null
+++ b/core/prompts/bot-main.md
@@ -0,0 +1,4 @@
+## You are the user's main Bot
+You are the user's first point of contact, and you can see everything on this machine: every project, Session, Agent, and Bot. Talk things through with the user and decide with them. Work that takes doing goes to a Session that does it, which you start and follow through to the end.
+
+Your memory holds what the user entrusts to you: what they ask you to remember, the matters you are following, and the Sessions handling them.
diff --git a/core/prompts/bot-memory.md b/core/prompts/bot-memory.md
new file mode 100644
index 000000000..4b907087a
--- /dev/null
+++ b/core/prompts/bot-memory.md
@@ -0,0 +1,11 @@
+## Your memory
+Your working directory, `{workdir}`, is your home and your long-term memory. Keep it as an engineer keeps a project: maintaining it is part of your job alongside whatever the user asks.
+
+- Its `AGENTS.md` is in your system prompt; nothing else there is. Keep in it what you need on every Turn, and an index to the rest. Edits reach your system prompt after a pause or when this conversation is condensed; until then, what you wrote is already in the conversation above.
+- Organize everything else as you see fit, and reach it through that index.
+- Your conversation is condensed as it grows. What you will need again lasts only if you write it here.
+- Keep what you cannot look up. For live facts such as projects, Sessions, runs, and files, keep pointers, not copies.
+- Keep it true: correct what changed in place, and remove what no longer holds.
+- Avibe records every change here in the directory's Git history, before and after each Turn, including changes by the user and by the memory Bot. Use that history when you need to trace or undo something.
+- Only your permanent Session `{session_id}` writes here. A fork reads it and puts what is worth keeping in its result.
+- Who you are comes from your definition above, which the user owns. Never store secrets here.
diff --git a/core/prompts/harness-agents.md b/core/prompts/harness-agents.md
index 2e55d0c6b..8ff59b2c8 100644
--- a/core/prompts/harness-agents.md
+++ b/core/prompts/harness-agents.md
@@ -1,11 +1,24 @@
-### Agents
-The table below is generated from currently enabled Agents at prompt-injection time. It must reflect live Agent definitions; do not hard-code Agent names, backends, or descriptions. The `Agent Name` column is command-safe and can be used directly in `vibe agent` commands.
+### Bots and Agents
+You can address two kinds of workers. Both tables are generated from live definitions; use the first column exactly as listed in commands, and the display name when talking to the user.
+
+- A **Bot** is a standing member with one permanent Session and its own memory. A message to a Bot joins that conversation, and the Bot handles its messages in order.
+- An **Agent** is a reusable role: backend, model, and instructions. Each run starts a fresh Session with no memory of earlier runs, so several runs can work in parallel.
+
+Ask a Bot when the work needs its memory, ongoing responsibility, or judgment. Run an Agent for a self-contained task or for parallel work. In Chinese, the product calls Bots 伙伴; use that word when you write to the user in Chinese.
+
+| Bot | Display Name | Role |
+| --- | --- | --- |
+{bots_rows}
| Agent Name | Backend | Agent Description |
| --- | --- | --- |
{enabled_agents_rows}
-Rules:
+Bot rules:
+- Message a Bot with `vibe agent run --bot <bot> --message ...`. Like any async run, its reply returns to this conversation as a callback.
+- Reach a Bot only through `--bot`, never through `--agent` or `--session-id`. `--model` and `--reasoning-effort` do not apply.
+
+Agent rules:
- All Agents listed in the generated table are enabled. Use the `Agent Name` value exactly as listed in shell commands such as `vibe agent show <agent-name>` and `vibe agent run --agent <agent-name> ...`.
- `--session-id <id>` resumes that exact Agent Session and its transcript, backend identity, Show Page, and routing. Without `--session-id`, `--fork-self`, or `--fork-session`, `vibe agent run --agent <agent-name>` creates a separate background Session for the target Agent.
- `--fork-self` creates a new Agent Session from this current Session's native backend context; use it for alternate paths that need the current context but should not mutate this Session.
@@ -17,8 +30,10 @@ Rules:
- Create or update Agents only when it captures a reusable role, reduces repeated prompting, or makes a long-running Harness more reliable.
### Mentions in user messages
-On the Web chat the user composes with `@` / `#` autocomplete, which inserts stable references into their message text:
-- `@<agent-name>` points at that enabled Agent (see the table above). Act on it with `vibe agent run --agent <agent-name> ...`.
-- `#<session-id>` points at that Session. Resume it with `vibe agent run --session-id <session-id> ...`, or read its history with `vibe data query`.
+The Web composer inserts typed references into the message text:
+- `@<bot:name>` points at a Bot. Message it with `vibe agent run --bot <name> ...`.
+- `@<agent:name>` points at an Agent. Run it with `vibe agent run --agent <name> ...`.
+- `#<session-id>` points at a Session. Resume it with `vibe agent run --session-id <session-id> ...`, or read it with `vibe data query`.
+- `@<name>` without a type, found in older messages, points at an Agent.
-Treat these as the user pointing at that Agent or Session, and decide the action from context. Only the bracketed `@<...>` / `#<...>` forms are references; a bare `@` or `#` in prose is ordinary text.
+A mention says whom the user pointed at, not what to do; decide the action from the message. A mention of yourself needs no command. Only these bracketed forms are references; a bare `@` or `#` in prose is ordinary text.
diff --git a/core/system_prompt_injection.py b/core/system_prompt_injection.py
index d3fe55f08..288b85b20 100644
--- a/core/system_prompt_injection.py
+++ b/core/system_prompt_injection.py
@@ -36,11 +36,36 @@ logger = logging.getLogger(__name__)
# guidance and catalogs; backends must not prepend or append their own copy.
+#: The main Bot's name in prompts while the user has not named it (``docs/plans/bots.md`` D5).
+MAIN_BOT_DEFAULT_DISPLAY_NAME = "Vibey"
+
+
@dataclass(frozen=True)
class AgentPromptInfo:
name: str
description: str
backend: str = "unknown"
+ #: Set when the Agent is a Bot: the Bots table lists it, and the Agents table leaves it out.
+ bot_handle: str = ""
+ bot_display_name: str = ""
+ bot_position: int = 0
+ bot_builtin: bool = False
+
+
+@dataclass(frozen=True)
+class BotPromptInfo:
+ """The Bot a Vibey Turn runs as, for its own sections (``docs/plans/bots.md`` "Prompt drafts").
+
+ Every field is a fact of the Bot, never of the Session or Turn, so a Bot's sections are byte-stable across its
+ Turns and identical in its forks, which keep its directory (D7).
+ """
+
+ handle: str
+ display_name: str
+ role: str
+ session_id: str
+ workdir: str
+ builtin: bool = False
def _codex_generated_images_block() -> RenderedPromptBlock:
@@ -94,6 +119,40 @@ def _is_web_platform(platform: str) -> bool:
return platform.strip().lower() in {"avibe", "web"}
+def _agent_bot_fields(agent: Any) -> dict[str, Any]:
+ """The Bot an Agent is, from an Agent record, its list payload (``bot``), or an already coerced row."""
+ if isinstance(agent, AgentPromptInfo):
+ return {
+ "bot_handle": agent.bot_handle,
+ "bot_display_name": agent.bot_display_name,
+ "bot_position": agent.bot_position,
+ "bot_builtin": agent.bot_builtin,
+ }
+ if isinstance(agent, dict):
+ bot = agent.get("bot")
+ builtin = bool(bot.get("builtin")) if isinstance(bot, dict) else False
+ else:
+ from core.vibe_agents import agent_bot_record, is_main_bot_agent
+
+ try:
+ bot = agent_bot_record(agent) if getattr(agent, "archived_at", None) is None else None
+ builtin = bool(bot) and is_main_bot_agent(agent)
+ except (AttributeError, TypeError):
+ bot, builtin = None, False
+ if not isinstance(bot, dict) or not str(bot.get("handle") or "").strip():
+ return {}
+ try:
+ position = int(bot.get("position") or 0)
+ except (TypeError, ValueError):
+ position = 0
+ return {
+ "bot_handle": str(bot["handle"]).strip(),
+ "bot_display_name": str(bot.get("display_name") or "").strip(),
+ "bot_position": position,
+ "bot_builtin": builtin,
+ }
+
+
def _coerce_agent_prompt_info(agent: Any) -> AgentPromptInfo:
if isinstance(agent, dict):
raw_name = str(agent.get("name") or "").strip()
@@ -112,6 +171,7 @@ def _coerce_agent_prompt_info(agent: Any) -> AgentPromptInfo:
name=name,
description=description or "(no description)",
backend=backend or "unknown",
+ **_agent_bot_fields(agent),
)
@@ -123,17 +183,37 @@ def _escape_markdown_table_cell(value: str) -> str:
return str(value).replace("\\", "\\\\").replace("|", "\\|").replace("\n", " ").strip()
-def _format_enabled_agents_rows(enabled_agents: Optional[Iterable[Any]]) -> str:
- if enabled_agents is None:
- return ""
-
+def _coerce_enabled_agents(enabled_agents: Optional[Iterable[Any]]) -> list[AgentPromptInfo]:
rows: list[AgentPromptInfo] = []
- for agent in enabled_agents:
+ for agent in enabled_agents or ():
try:
rows.append(_coerce_agent_prompt_info(agent))
except ValueError:
logger.debug("Skipping enabled Agent prompt row with no name: %r", agent)
+ return rows
+
+
+def _bot_display_name(name: str, *, builtin: bool) -> str:
+ return name or (MAIN_BOT_DEFAULT_DISPLAY_NAME if builtin else "")
+
+def _format_bots_rows(rows: list[AgentPromptInfo]) -> str:
+ """The Bots table: the main Bot first, then by position, as the Web strip orders them."""
+ bots = sorted(
+ (row for row in rows if row.bot_handle),
+ key=lambda row: (0 if row.bot_builtin else 1, row.bot_position, row.bot_handle),
+ )
+ return "\n".join(
+ f"| {_escape_markdown_table_cell(bot.bot_handle)} | "
+ f"{_escape_markdown_table_cell(_bot_display_name(bot.bot_display_name, builtin=bot.bot_builtin))} | "
+ f"{_escape_markdown_table_cell(bot.description)} |"
+ for bot in bots
+ )
+
+
+def _format_enabled_agents_rows(rows: list[AgentPromptInfo]) -> str:
+ """The Agents table. An Agent that is a Bot is listed once, as the Bot (``bots.md`` D4)."""
+ rows = [row for row in rows if not row.bot_handle]
if not rows:
return ""
@@ -156,6 +236,55 @@ def _format_enabled_agents_rows(enabled_agents: Optional[Iterable[Any]]) -> str:
return "\n".join(lines)
+def _role_sentence(role: str) -> str:
+ text = " ".join(str(role or "").split())
+ if not text:
+ return ""
+ return f" Your role: {text}" + ("" if text[-1] in ".!?。!?" else ".")
+
+
+def _bot_blocks(bot: BotPromptInfo) -> list[RenderedPromptBlock]:
+ blocks = [
+ render_prompt_block(
+ "bot-identity-prompt",
+ display_name=_bot_display_name(" ".join(bot.display_name.split()), builtin=bot.builtin) or bot.handle,
+ handle=bot.handle,
+ role_sentence=_role_sentence(bot.role),
+ session_id=bot.session_id,
+ ),
+ render_prompt_block("bot-memory-prompt", workdir=bot.workdir, session_id=bot.session_id),
+ ]
+ if bot.builtin:
+ blocks.append(render_prompt_block("bot-main-prompt"))
+ return blocks
+
+
+def bot_for_turn(store: Any, *, agent_id: Optional[str], cwd: str) -> Optional[BotPromptInfo]:
+ """The Bot a Turn runs as: its Agent is the Bot's, and it runs in the Bot's directory.
+
+ This is the one rule for the Bot sections, and it needs no Session id: the Bot's own Session runs there, and so
+ does every fork of it, since forks keep the source's directory (``bots.md`` D7). A fork therefore shares its
+ source's sections and its cached prefix; a fresh ``--agent`` Session of the same Agent runs elsewhere and is an
+ ordinary worker. Reads the catalog: call it off the event loop.
+ """
+ if store is None or not agent_id or not cwd:
+ return None
+ from core.bots import bot_from_agent
+
+ agent = store.get_by_id(agent_id)
+ bot = bot_from_agent(agent) if agent is not None else None
+ if bot is None or os.path.realpath(cwd) != os.path.realpath(bot.directory):
+ return None
+ return BotPromptInfo(
+ handle=bot.handle,
+ display_name=bot.display_name,
+ role=bot.role,
+ session_id=bot.session_id,
+ workdir=str(bot.directory),
+ builtin=bot.builtin,
+ )
+
+
def get_enabled_agents_for_prompt(controller: Any) -> Optional[list[AgentPromptInfo]]:
store = getattr(controller, "vibe_agent_store", None)
if store is None:
@@ -187,8 +316,12 @@ def build_system_prompt_blocks(
skills_cwd: str | Path | None = None,
skills_project_base: str | Path | None = None,
skill_catalog_sink: list[dict[str, Any]] | None = None,
+ bot: BotPromptInfo | None = None,
) -> list[RenderedPromptBlock]:
- """The production composition, also exported by the debug command."""
+ """The production composition, also exported by the debug command.
+
+ ``bot`` is the Bot a Vibey Turn runs as (``bot_for_turn``); only then are the Bot sections rendered.
+ """
skills = None
if skills_cwd is not None:
@@ -208,6 +341,10 @@ def build_system_prompt_blocks(
render_prompt_block("base-capabilities-intro"),
render_prompt_block("agent-working-principles"),
]
+ if isinstance(bot, dict):
+ bot = BotPromptInfo(**bot)
+ if bot is not None:
+ blocks.extend(_bot_blocks(bot))
if context is not None and backend != "vibey":
blocks.append(render_prompt_block("session-start-prompt", default_session_id=_extract_default_session_id(context)))
correction = build_forked_session_correction_prompt(context)
@@ -225,9 +362,13 @@ def build_system_prompt_blocks(
blocks.append(render_prompt_block("vault-routing-prompt"))
if context is not None:
blocks.append(render_prompt_block("harness-routing-prompt"))
- agent_rows = _format_enabled_agents_rows(enabled_agents)
- if agent_rows:
- blocks.append(render_prompt_block("harness-agents-prompt", enabled_agents_rows=agent_rows))
+ roster = _coerce_enabled_agents(enabled_agents)
+ agent_rows = _format_enabled_agents_rows(roster)
+ bots_rows = _format_bots_rows(roster)
+ if agent_rows or bots_rows:
+ blocks.append(
+ render_prompt_block("harness-agents-prompt", bots_rows=bots_rows, enabled_agents_rows=agent_rows)
+ )
if include_context_guidance:
blocks.append(render_prompt_block("project-context-prompt"))
from core.mcp_hub.prompt import build_mcp_prompt_blocks
@@ -244,7 +385,8 @@ def build_system_prompt_blocks(
skill_catalog_sink.append(catalog_result(skills, entry_point="runtime_prompt"))
except Exception:
logger.info("Skill catalog observation unavailable during prompt preparation")
- if context is not None:
+ if context is not None and bot is None:
+ # A Bot's Session is titled by the Bot's display name, so it gets no title section (bots.md D5).
platform = resolve_context_platform(context, fallback_platform=fallback_platform, default="<platform>")
if _is_web_platform(platform):
blocks.append(render_prompt_block("session-title-prompt"))
diff --git a/core/vibe_agents.py b/core/vibe_agents.py
index c4c682459..ca70259ef 100644
--- a/core/vibe_agents.py
+++ b/core/vibe_agents.py
@@ -1994,6 +1994,9 @@ class VibeAgentStore:
agent_name=agent.name,
reason="disabled",
)
+ if is_bot_agent(agent):
+ # A Bot is a standing colleague with one conversation; new chats never start on its Agent.
+ raise AgentBotLockedError(agent_name=agent.name)
# No audience validation here: the default is advisory and the ACL
# is enforced per-principal at use time. Agent managers may point
# instance-wide routing without widening the target Agent's ACL.
diff --git a/docs/CLI.md b/docs/CLI.md
index be8363e55..f8fde8805 100644
--- a/docs/CLI.md
+++ b/docs/CLI.md
@@ -780,7 +780,8 @@ vibe bot remove cso
follows the main Bot's model and effort.
- `set` makes an existing enabled Vibey Agent a Bot. Its handle is its Agent
name; an Agent that was a Bot before gets its old handle, Session, and
- directory back.
+ directory back. The built-in `vibey` Agent and the default Agent cannot be
+ set; a Bot's Agent cannot become the default Agent either.
- `update` changes the display name, the emoji avatar (`--emoji` with `--hue`,
or `--clear-avatar`), or the position among the other Bots. Change the role,
model, or instructions with `vibe agent update`.
diff --git a/docs/CLI_ZH.md b/docs/CLI_ZH.md
index 216542ad0..cce21fa56 100644
--- a/docs/CLI_ZH.md
+++ b/docs/CLI_ZH.md
@@ -572,7 +572,7 @@ Session 空闲时立即启动;只有明确拒绝后才回退到 P3。它不会
`vibe session send-now` 是无内容 P1 操作,只提升现有的精确 FIFO 队头,不新增消息。
过期队头会被拒绝,而不会改为提升下一条;两个命令都不会调用 Stop。
-`--bot <handle>` 给伙伴(Bot)的永久 Session 发消息(见 `vibe bot`)。这次运行会像
+`--bot <handle>` 按代号给伙伴(Bot)的永久 Session 发消息(见 `vibe bot`)。这次运行会像
`--queue` 一样排在伙伴之前的消息之后,所以伙伴一次只处理一条消息。伙伴只有一个对话,
用自己的模型:`--agent`、`--session-id`、fork 参数、`--model`、`--reasoning-effort`、
位置参数、`--cwd` 和 `--close-after` 都不能与 `--bot` 一起使用。对同时是伙伴的
@@ -624,18 +624,19 @@ vibe bot update cso --position 1
vibe bot remove cso
```
-- `list` 列出所有伙伴,主伙伴在最前;`show` 按 handle 显示一个伙伴。
-- `create` 新建一个以 handle 命名的 Vibey Agent,并把它设为伙伴。`--handle` 是小写
+- `list` 列出所有伙伴,主伙伴在最前;`show` 按代号显示一个伙伴。
+- `create` 新建一个以代号(handle)命名的 Vibey Agent,并把它设为伙伴。`--handle` 是小写
ASCII,2 到 24 个字母、数字或连字符,以字母开头、不以连字符结尾;`main`、`memory`、`ops` 已保留。
- 不传 `--handle` 时,handle 由名字生成:ASCII 名字会被规范化,其他名字会被转写,
+ 不传 `--handle` 时,代号由名字生成:ASCII 名字会被规范化,其他名字会被转写,
被占用时加 `-2`。不传 `--model` 时,伙伴沿用主伙伴的模型和推理强度。
-- `set` 把一个已启用的现有 Vibey Agent 设为伙伴。它的 handle 就是 Agent 名称;
- 以前当过伙伴的 Agent 会拿回原来的 handle、Session 和目录。
+- `set` 把一个已启用的现有 Vibey Agent 设为伙伴。它的代号就是 Agent 名称;
+ 以前当过伙伴的 Agent 会拿回原来的代号、Session 和目录。内置的 `vibey` Agent
+ 和默认 Agent 不能设为伙伴;伙伴的 Agent 也不能设为默认 Agent。
- `update` 修改显示名称、emoji 头像(`--emoji` 配合 `--hue`,或 `--clear-avatar`),
或在其他伙伴中的位置。角色、模型或指令用 `vibe agent update` 修改。
- `remove` 移出伙伴,保留 Agent、Session 和目录。主伙伴不能移出。
-伙伴创建后 handle 不再改变:它的 Session 是 `ses_<handle>`,目录是
+伙伴创建后代号不再改变:它的 Session 是 `ses_<handle>`,目录是
`~/.avibe/bots/<handle>/`。主伙伴的 Session 是 `ses_main`。Agent 作为伙伴期间保持
启用,不能改名或删除。目录一开始是一个空的 Git 仓库;Avibe 在伙伴 Session 的每个
Turn 之前(他人的修改)和之后(伙伴自己的修改)自动提交,从不压缩历史。
diff --git a/modules/agents/vibey/agent.py b/modules/agents/vibey/agent.py
index 169950008..42729b6ea 100644
--- a/modules/agents/vibey/agent.py
+++ b/modules/agents/vibey/agent.py
@@ -1662,14 +1662,17 @@ class VibeyAgent(BaseAgent):
scans the ordinary static Skill directories.
"""
from core.managed_skills import managed_skill_project_base
- from core.system_prompt_injection import build_system_prompt_blocks, get_enabled_agents_for_prompt
+ from core.system_prompt_injection import bot_for_turn, build_system_prompt_blocks, get_enabled_agents_for_prompt
context = request.context
skill_catalog_sink: list[dict] = []
def build() -> list[RenderedPromptBlock]:
- # Every lookup runs here, off the loop: the enabled-Agent list reads SQLite.
+ # Every lookup runs here, off the loop: the enabled-Agent list and the Bot read SQLite.
return build_system_prompt_blocks(
+ bot=bot_for_turn(
+ getattr(self.controller, "vibe_agent_store", None), agent_id=request.vibe_agent_id, cwd=cwd
+ ),
agent_instructions=request.vibe_agent_system_prompt or "",
backend=BACKEND,
include_quick_replies=getattr(self.config, "reply_enhancements", True)
diff --git a/modules/agents/vibey/prompt_snapshot.py b/modules/agents/vibey/prompt_snapshot.py
index 850671f46..66112ce7d 100644
--- a/modules/agents/vibey/prompt_snapshot.py
+++ b/modules/agents/vibey/prompt_snapshot.py
@@ -50,6 +50,10 @@ COMPONENT_TIERS = {
"mcp-pagination-prompt": 1,
"session-title-prompt": 1,
"agent-instructions": 1,
+ # A Bot's sections are who it is (docs/plans/bots.md "Prompt drafts"); the roster is someone else's change.
+ "bot-identity-prompt": 1,
+ "bot-memory-prompt": 1,
+ "bot-main-prompt": 1,
"harness-agents-prompt": 2,
"skills-catalog": 2,
"skills-more-notice": 2,
@@ -160,10 +164,21 @@ class Decision:
applied: tuple[Pending, ...] = ()
+def _file_tier(path: str, *, global_file: bool) -> int:
+ """The user's global file is 1; a Bot's own memory file, ``~/.avibe/bots/<handle>/AGENTS.md``, is the Bot's own
+ writing, 3 (bots.md D11); every other file, the shared ``~/.avibe/bots/AGENTS.md`` included, is 2."""
+ if global_file:
+ return 1
+ from config import paths
+
+ bots = os.path.realpath(paths.get_bots_dir())
+ return 3 if os.path.dirname(os.path.dirname(os.path.realpath(path))) == bots else 2
+
+
def component_tier(before: Component | None, after: Component | None) -> int:
component = after or before
if component.path:
- return COMPONENT_TIERS.get(component.id, 1 if component.global_file else 2)
+ return COMPONENT_TIERS.get(component.id, _file_tier(component.path, global_file=component.global_file))
if (before is not None and after is not None and component.id in COMPONENT_TIERS
and before.contract_revision != after.contract_revision):
return 1
diff --git a/tests/test_agent_input.py b/tests/test_agent_input.py
index 84a5d5dee..1471c1d86 100644
--- a/tests/test_agent_input.py
+++ b/tests/test_agent_input.py
@@ -82,20 +82,29 @@ _HARNESS_SOURCES = [
pytest.param("hook", None, None, "hook send run-1", id="released-hook-send"),
pytest.param("webhook", "hook-9", None, "webhook hook-9", id="webhook"),
pytest.param(
- "agent_run", None, {"source_kind": "agent", "source_actor": "ses_caller"},
- "agent run run-1 from #ses_caller", id="agent-run",
+ "agent_run", None, {"source_kind": "agent", "source_actor": "sescaller01"},
+ "agent run run-1 from #sescaller01", id="agent-run",
+ ),
+ pytest.param(
+ "agent_run", None, {"source_kind": "agent", "source_actor": "ses_main"},
+ "agent run run-1 from @<bot:main>", id="agent-run-from-a-bot",
+ ),
+ pytest.param(
+ "agent_run", None,
+ {"source_kind": "callback", "source_actor": "run-0", "parent_run_id": "run-0", "source_session_id": "ses_cso"},
+ "callback of run run-0 from @<bot:cso>", id="callback-from-a-bot",
),
pytest.param("agent_run", None, {"source_kind": "cli"}, "agent run run-1 from the CLI", id="cli-run"),
pytest.param(
"agent_run", None,
- {"source_kind": "callback", "source_actor": "run-0", "parent_run_id": "run-0", "source_session_id": "ses_child"},
- "callback of run run-0 from #ses_child", id="callback",
+ {"source_kind": "callback", "source_actor": "run-0", "parent_run_id": "run-0", "source_session_id": "seschild01"},
+ "callback of run run-0 from #seschild01", id="callback",
),
pytest.param(
"agent_run", None,
{"source_kind": "callback", "source_actor": "run-0:terminal:failed", "parent_run_id": "run-0",
- "source_session_id": "ses_child"},
- "callback of run run-0 from #ses_child", id="terminal-callback",
+ "source_session_id": "seschild01"},
+ "callback of run run-0 from #seschild01", id="terminal-callback",
),
pytest.param(
"agent_run", None, {"source_kind": "callback", "source_actor": "vault:vrq_1"},
@@ -143,7 +152,7 @@ def test_a_persons_message_is_never_tagged(tmp_path, include_time):
# Even a context that carries Harness provenance: what decides is who typed the input.
context = _scheduler_context(
- tmp_path, trigger_kind="agent_run", metadata={"source_kind": "agent", "source_actor": "ses_caller"}
+ tmp_path, trigger_kind="agent_run", metadata={"source_kind": "agent", "source_actor": "sescaller01"}
)
context.user_id = "U1"
handler = SimpleNamespace(_input_user_name=AsyncMock(return_value="Alex"))
diff --git a/tests/test_bot_prompts.py b/tests/test_bot_prompts.py
new file mode 100644
index 000000000..169a7a73a
--- /dev/null
+++ b/tests/test_bot_prompts.py
@@ -0,0 +1,143 @@
+"""The Bot prompt sections and the Bots and Agents roster (``docs/plans/bots.md`` "Prompt drafts")."""
+
+from __future__ import annotations
+
+import re
+import shlex
+
+import pytest
+
+from core.system_prompt_injection import BotPromptInfo, bot_for_turn, build_system_prompt_blocks
+from modules.im.base import MessageContext
+from storage.importer import ensure_sqlite_state
+from vibe import cli
+
+
+def _context(session_id: str = "sesabc1234567", *, fork_of: str | None = None) -> MessageContext:
+ target = {"metadata": {"fork_source_session_id": fork_of}} if fork_of else None
+ return MessageContext(
+ user_id="user",
+ channel_id="channel",
+ platform="avibe",
+ platform_specific={"agent_session_id": session_id, **({"agent_session_target": target} if target else {})},
+ )
+
+
+_ROSTER = [
+ {"name": "main", "backend": "vibey", "description": "The user's main Bot and first point of contact.",
+ "bot": {"handle": "main", "display_name": "", "builtin": True}},
+ {"name": "cso", "backend": "vibey", "description": "Reviews security risks.",
+ "bot": {"handle": "cso", "display_name": "首席安全官", "position": 1}},
+ {"name": "vibey", "backend": "vibey", "description": "Vibey, the official agent of Avibe."},
+ {"name": "reviewer", "backend": "codex", "description": "Reviews code."},
+]
+
+_MAIN = BotPromptInfo(
+ handle="main", display_name="", role="The user's main Bot and first point of contact.",
+ session_id="ses_main", workdir="/home/u/.avibe/bots/main", builtin=True,
+)
+_CSO = BotPromptInfo(
+ handle="cso", display_name="首席安全官", role="Reviews security risks",
+ session_id="ses_cso", workdir="/home/u/.avibe/bots/cso",
+)
+
+
+def _blocks(**kwargs):
+ return {block.module_id: block.text for block in build_system_prompt_blocks(context=_context(), **kwargs)}
+
+
+def test_the_roster_lists_each_bot_once_as_a_bot():
+ roster = _blocks(enabled_agents=_ROSTER)["harness-agents-prompt"]
+ bots, agents = roster.split("| Agent Name | Backend | Agent Description |")
+ assert "| main | Vibey | The user's main Bot and first point of contact. |" in bots
+ assert bots.index("| main |") < bots.index("| cso | 首席安全官 | Reviews security risks. |")
+ assert "| reviewer | codex |" in agents and "| vibey | vibey |" in agents
+ assert "| main |" not in agents and "| cso |" not in agents
+ assert "`@<bot:name>` points at a Bot" in roster
+ assert "`@<name>` without a type, found in older messages, points at an Agent." in roster
+
+
+def test_bot_sections_appear_only_for_a_bot_and_the_main_section_only_for_the_main_bot():
+ worker = _blocks(enabled_agents=_ROSTER)
+ assert not {"bot-identity-prompt", "bot-memory-prompt", "bot-main-prompt"} & set(worker)
+ assert "session-title-prompt" in worker
+
+ main = _blocks(enabled_agents=_ROSTER, bot=_MAIN)
+ assert "You are Vibey, the Bot `@<bot:main>`. Your role: The user's main Bot and first point of contact." in (
+ main["bot-identity-prompt"]
+ )
+ assert "Session `ses_main`" in main["bot-identity-prompt"]
+ assert "`/home/u/.avibe/bots/main`" in main["bot-memory-prompt"]
+ assert "## You are the user's main Bot" in main["bot-main-prompt"]
+ # A Bot's Session is titled by its display name.
+ assert "session-title-prompt" not in main
+
+ cso = _blocks(enabled_agents=_ROSTER, bot=_CSO)
+ assert "You are 首席安全官, the Bot `@<bot:cso>`. Your role: Reviews security risks. Your one" in (
+ cso["bot-identity-prompt"]
+ )
+ assert "bot-main-prompt" not in cso
+
+
+def test_a_bots_sections_are_byte_stable_across_its_turns_and_its_forks():
+ def bot_text(context):
+ return [
+ block.text
+ for block in build_system_prompt_blocks(context=context, enabled_agents=_ROSTER, bot=_CSO)
+ if block.module_id.startswith("bot-")
+ ]
+
+ first = bot_text(_context("ses_cso"))
+ assert first == bot_text(_context("ses_cso"))
+ assert first == bot_text(_context("sesfork123456", fork_of="ses_cso"))
+ # They come before anything that names the Session, so a fork shares that prefix.
+ order = [block.module_id for block in build_system_prompt_blocks(context=_context(), bot=_CSO)]
+ assert order.index("bot-memory-prompt") < order.index("session-start-prompt")
+
+
+def test_prompt_cli_examples_parse_against_the_real_cli():
+ """Every `vibe agent run` the roster and mention sections teach is a live caller."""
+ roster = _blocks(enabled_agents=_ROSTER)["harness-agents-prompt"]
+ examples = re.findall(r"`(vibe agent run [^`]+)`", roster)
+ assert any("--bot" in example for example in examples)
+ parser = cli.build_parser()
+ for example in examples:
+ # A placeholder is a value; `...` after a flag is its value, and a trailing one stands for the rest.
+ tokens = shlex.split(re.sub(r"<[^>]+>", "x", example))
+ argv = [
+ "x" if token == "..." else token
+ for index, token in enumerate(tokens)
+ if token != "..." or tokens[index - 1].startswith("--")
+ ]
+ if "--message" not in argv:
+ argv += ["--message", "x"]
+ parser.parse_args(argv[1:])
+
+
+def bots(monkeypatch, tmp_path):
+ from core.bots import BotService
+ from core.vibe_agents import VibeAgentStore
+
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ ensure_sqlite_state()
+ store = VibeAgentStore()
+ store.ensure_builtin_default_agents([])
+ with BotService(store) as service:
+ yield service
+ store.close()
+
+
+def test_a_turn_runs_as_a_bot_only_in_the_bots_directory(bots, tmp_path):
+ main = bots.ensure_main_bot()
+ vibey = bots.store.get_builtin_default_agent_for_backend("vibey")
+ info = bot_for_turn(bots.store, agent_id=main.agent.id, cwd=str(tmp_path / "bots" / "main"))
+ assert info == BotPromptInfo(
+ handle="main", display_name="", role=main.role, session_id="ses_main",
+ workdir=str(tmp_path / "bots" / "main"), builtin=True,
+ )
+ # A fresh --agent Session of the Bot's Agent elsewhere, or another Agent in the directory, is a worker.
+ assert bot_for_turn(bots.store, agent_id=main.agent.id, cwd=str(tmp_path)) is None
+ assert bot_for_turn(bots.store, agent_id=vibey.id, cwd=str(tmp_path / "bots" / "main")) is None
+ bots.update_bot("main", display_name="歪比")
+ assert bot_for_turn(bots.store, agent_id=main.agent.id, cwd=str(tmp_path / "bots" / "main")).display_name == "歪比"
diff --git a/tests/test_bots.py b/tests/test_bots.py
index b95dec5b2..6ab4f5d57 100644
--- a/tests/test_bots.py
+++ b/tests/test_bots.py
@@ -387,3 +387,27 @@ def test_bot_change_events_reach_only_the_owner():
for role in ("member", "editor", "viewer"):
member = AuthorizationContext(instance_role=role, is_remote=True, subject="m1")
assert not can_receive_workbench_event(member, "bots.changed")
+
+
+def test_vibey_and_the_default_agent_stay_workers(service):
+ """The built-in Vibey Agent is never a Bot, and the default Agent and a Bot's Agent never trade places."""
+ from core.bots import BotError
+ from core.vibe_agents import AgentBotLockedError
+
+ store = service.store
+ vibey = store.get_builtin_default_agent_for_backend("vibey")
+ with pytest.raises(BotError) as builtin:
+ service.set_bot(vibey.name, display_name="Vibey")
+ assert builtin.value.code == "bot_agent_builtin"
+
+ store.create(name="writer", backend="vibey")
+ store.set_default_agent_name("writer")
+ with pytest.raises(BotError) as default:
+ service.set_bot("writer", display_name="Writer")
+ assert default.value.code == "bot_agent_default"
+
+ bot = service.create_bot(display_name="Researcher")
+ for name in (bot.agent.name, service.ensure_main_bot().agent.name):
+ with pytest.raises(AgentBotLockedError):
+ store.set_default_agent_name(name)
+ assert store.get_default_agent_name() == "writer"
diff --git a/tests/test_bots_api.py b/tests/test_bots_api.py
index f4c379a91..cf0e770c6 100644
--- a/tests/test_bots_api.py
+++ b/tests/test_bots_api.py
@@ -108,3 +108,11 @@ def test_bot_sessions_refuse_archive_and_title_edits(client):
).status_code == 200
searched = client.get("/api/sessions?q=Research").get_json()["sessions"]
assert all(row["id"] != "ses_researcher" for row in searched)
+
+
+def test_a_bots_agent_is_refused_as_the_default_over_http(client):
+ client.post("/api/bots", json={"display_name": "Researcher"}, headers=csrf_headers(client))
+ refused = client.post("/api/agents/default", json={"name": "researcher"}, headers=csrf_headers(client))
+ assert (refused.status_code, refused.get_json()["code"]) == (409, "agent_is_bot")
+ vibey = client.post("/api/bots/set", json={"agent_name": "vibey", "display_name": "V"}, headers=csrf_headers(client))
+ assert (vibey.status_code, vibey.get_json()["error"]["code"]) == (409, "bot_agent_builtin")
diff --git a/tests/test_internal_server.py b/tests/test_internal_server.py
index 0238022da..930edf5cc 100644
--- a/tests/test_internal_server.py
+++ b/tests/test_internal_server.py
@@ -8094,13 +8094,13 @@ def test_flush_suppressed_segment_claims_each_delivery_id_in_one_turn(tmp_path,
("trigger", "spec", "expected"),
[
pytest.param(
- "agent_run", {"source_kind": "agent", "source_actor": "ses_caller"},
- "[Harness: agent run run-1 from #ses_caller; agent run run-2 from #ses_caller]",
+ "agent_run", {"source_kind": "agent", "source_actor": "sescaller01"},
+ "[Harness: agent run run-1 from #sescaller01; agent run run-2 from #sescaller01]",
id="agent-runs-from-one-caller",
),
pytest.param(
- "agent_run", {"source_kind": "callback", "source_session_id": "ses_child"},
- "[Harness: callback of run run-1 from #ses_child; callback of run run-2 from #ses_child]",
+ "agent_run", {"source_kind": "callback", "source_session_id": "seschild01"},
+ "[Harness: callback of run run-1 from #seschild01; callback of run run-2 from #seschild01]",
id="callbacks-from-one-session",
),
pytest.param(
diff --git a/tests/test_prompt_render_export.py b/tests/test_prompt_render_export.py
index 95920b0b0..e9e6f3541 100644
--- a/tests/test_prompt_render_export.py
+++ b/tests/test_prompt_render_export.py
@@ -99,6 +99,14 @@ _PROJECT_CONTEXT = (
"`AGENTS.md` is an index, not a log. Keep high-level principles there, point to local detail files when needed, "
"and update by consolidating and abstracting instead of merely appending.\n\n"
)
+# The Bots and Agents roster (docs/plans/bots.md "Prompt drafts") and what it replaced, with no Bots listed.
+_BOTS_ROSTER_INTRO = '### Bots and Agents\nYou can address two kinds of workers. Both tables are generated from live definitions; use the first column exactly as listed in commands, and the display name when talking to the user.\n\n- A **Bot** is a standing member with one permanent Session and its own memory. A message to a Bot joins that conversation, and the Bot handles its messages in order.\n- An **Agent** is a reusable role: backend, model, and instructions. Each run starts a fresh Session with no memory of earlier runs, so several runs can work in parallel.\n\nAsk a Bot when the work needs its memory, ongoing responsibility, or judgment. Run an Agent for a self-contained task or for parallel work. In Chinese, the product calls Bots 伙伴; use that word when you write to the user in Chinese.\n\n| Bot | Display Name | Role |\n| --- | --- | --- |\n\n\n'
+_PREVIOUS_AGENTS_INTRO = '### Agents\nThe table below is generated from currently enabled Agents at prompt-injection time. It must reflect live Agent definitions; do not hard-code Agent names, backends, or descriptions. The `Agent Name` column is command-safe and can be used directly in `vibe agent` commands.\n\n'
+_BOT_RULES = '\nBot rules:\n- Message a Bot with `vibe agent run --bot <bot> --message ...`. Like any async run, its reply returns to this conversation as a callback.\n- Reach a Bot only through `--bot`, never through `--agent` or `--session-id`. `--model` and `--reasoning-effort` do not apply.\n\nAgent rules:\n'
+_PREVIOUS_RULES = '\nRules:\n'
+_TYPED_MENTIONS = '### Mentions in user messages\nThe Web composer inserts typed references into the message text:\n- `@<bot:name>` points at a Bot. Message it with `vibe agent run --bot <name> ...`.\n- `@<agent:name>` points at an Agent. Run it with `vibe agent run --agent <name> ...`.\n- `#<session-id>` points at a Session. Resume it with `vibe agent run --session-id <session-id> ...`, or read it with `vibe data query`.\n- `@<name>` without a type, found in older messages, points at an Agent.\n\nA mention says whom the user pointed at, not what to do; decide the action from the message. A mention of yourself needs no command. Only these bracketed forms are references; a bare `@` or `#` in prose is ordinary text.'
+_PREVIOUS_MENTIONS = '### Mentions in user messages\nOn the Web chat the user composes with `@` / `#` autocomplete, which inserts stable references into their message text:\n- `@<agent-name>` points at that enabled Agent (see the table above). Act on it with `vibe agent run --agent <agent-name> ...`.\n- `#<session-id>` points at that Session. Resume it with `vibe agent run --session-id <session-id> ...`, or read its history with `vibe data query`.\n\nTreat these as the user pointing at that Agent or Session, and decide the action from context. Only the bracketed `@<...>` / `#<...>` forms are references; a bare `@` or `#` in prose is ordinary text.'
+
_CODEX_SKILL_REUSE_GUIDANCE = (
"Choose skills by task relevance, but load a skill only if it has not already been read "
"in this conversation; reuse already-loaded instructions across turns, callbacks, "
@@ -124,6 +132,12 @@ def _inputs(backend="codex", history="managed", skill_mode="pages"):
{"name": "alpha", "backend": "codex", "description": "First"},
],
}
+ if backend == "vibey":
+ # Only a Vibey Turn runs as a Bot; the main Bot also renders its own section.
+ options["bot"] = {
+ "handle": "main", "display_name": "", "role": "The user's main Bot.", "session_id": "ses_main",
+ "workdir": "/fixture/bots/main", "builtin": True,
+ }
return {"backend": backend, "agent_instructions": "Custom {unchanged} instructions", "options": options}
@@ -543,7 +557,8 @@ def test_cli_renders_valid_json_agent_arrays(monkeypatch, tmp_path, capsys, agen
tables = [block for block in rendered["blocks"] if block["id"] == "harness-agents-prompt"]
assert bool(tables) == bool(expected_rows)
if tables:
- rows = [line for line in tables[0]["text"].splitlines() if line.startswith("| ")][2:]
+ agents_table = tables[0]["text"].split("| Agent Name | Backend | Agent Description |", 1)[1]
+ rows = [line for line in agents_table.splitlines() if line.startswith("| ")][1:]
assert rows == expected_rows
omitted = _inputs()
del omitted["options"]["enabled_agents"]
@@ -593,6 +608,10 @@ def test_approved_guidance_changes_preserve_all_other_injection_bytes(monkeypatc
assert text.count(_SESSION_TITLE_STEPS) == 1
assert text.count(_PROJECT_CONTEXT) == 1
text = text.replace(_PROJECT_CONTEXT, _PREVIOUS_PREFERENCES_CONTEXT)
+ assert text.count(_BOTS_ROSTER_INTRO) == text.count(_BOT_RULES) == text.count(_TYPED_MENTIONS) == 1
+ text = text.replace(_BOTS_ROSTER_INTRO, _PREVIOUS_AGENTS_INTRO)
+ text = text.replace(_BOT_RULES, _PREVIOUS_RULES)
+ text = text.replace(_TYPED_MENTIONS, _PREVIOUS_MENTIONS)
text = text.replace(_HARNESS_SOURCE_GUIDANCE, "")
text = text.replace(_SESSION_TITLE_STEPS, _PREVIOUS_SESSION_TITLE_STEPS)
text = text.replace(_NEW_SESSION_MODEL_GUIDANCE, _PREVIOUS_FORK_OVERRIDE_GUIDANCE)
@@ -608,6 +627,7 @@ def test_approved_guidance_changes_preserve_all_other_injection_bytes(monkeypatc
# only to forks (now: to any new Session a run creates), and without the
# Harness line that says what a `[Harness: ...]` input is, and restoring the
# two-call Session Title steps that `--if-untitled` replaced, and restoring the
- # retired shared preferences file paragraphs and their section heading.
+ # retired shared preferences file paragraphs and their section heading, and
+ # restoring the Agents roster and untyped mentions the Bots roster replaced.
# Every other byte/order stays pinned, including all Claude/OpenCode output.
assert digest == "262c7cbabbbb0bfefa4a69511d805d28f76a3559bd511184006242f831b4836e"
diff --git a/tests/test_vibey_agent.py b/tests/test_vibey_agent.py
index e2db3b9f1..445118b9c 100644
--- a/tests/test_vibey_agent.py
+++ b/tests/test_vibey_agent.py
@@ -1025,7 +1025,7 @@ async def test_resume_renders_a_recovered_steer_as_the_live_path_would(engine, s
"task_trigger_kind": "agent_run",
"task_execution_id": run_id,
"source_kind": "agent",
- "source_actor": "ses_source",
+ "source_actor": "sessource01",
},
}},
),
@@ -1050,7 +1050,7 @@ async def test_resume_renders_a_recovered_steer_as_the_live_path_would(engine, s
[recovered] = [entry for entry in await harness.context_rows() if entry.row_id == "dlv_agent_steer"]
assert recovered.message.content[-1].text.startswith(
- "[Harness: agent run run_1 from #ses_source; agent run run_2 from #ses_source]\n"
+ "[Harness: agent run run_1 from #sessource01; agent run run_2 from #sessource01]\n"
)
@@ -1097,7 +1097,7 @@ async def test_a_users_fork_of_a_turn_mid_tool_batch_gets_exactly_the_previous_e
cut = resolve_fork_point(conn, SESSION)
_insert_session(
conn,
- "ses_child",
+ "seschild01",
_SCOPES["avibe"],
{
"created_via": "session_fork",
@@ -1116,15 +1116,15 @@ async def test_a_users_fork_of_a_turn_mid_tool_batch_gets_exactly_the_previous_e
await running
assert [row["content_text"] for row in source.rows("result")] == ["first answer", "Released."]
- child = _Harness(engine, tmp_path, "avibe", [[Done(assistant("child answer"))]], session_id="ses_child")
+ child = _Harness(engine, tmp_path, "avibe", [[Done(assistant("child answer"))]], session_id="seschild01")
await child.agent.handle_message(child.request("child question"))
rows = await child.context_rows()
inherited = [entry for entry in await source.context_rows() if entry.context_seq <= cut]
assert rows[: len(inherited)] == inherited
assert [(entry.session_id, entry.context_seq, entry.kind) for entry in rows[len(inherited) :]] == [
- ("ses_child", cut + 1, "input"),
- ("ses_child", cut + 2, "response"),
+ ("seschild01", cut + 1, "input"),
+ ("seschild01", cut + 2, "response"),
]
# Nothing of the live Turn reaches the child: not its input, its calls, or its replies.
live_ids = {entry.row_id for entry in live}
@@ -1147,7 +1147,7 @@ async def test_a_fork_at_the_empty_prefix_still_carries_the_fork_notice(engine,
with engine.begin() as conn:
_insert_session(
conn,
- "ses_child",
+ "seschild01",
_SCOPES["avibe"],
{
"created_via": "session_fork",
@@ -1156,11 +1156,11 @@ async def test_a_fork_at_the_empty_prefix_still_carries_the_fork_notice(engine,
"fork_source_context_seq": 0,
},
)
- child = _Harness(engine, tmp_path, "avibe", [[Done(assistant("child answer"))]], session_id="ses_child")
+ child = _Harness(engine, tmp_path, "avibe", [[Done(assistant("child answer"))]], session_id="seschild01")
await child.agent.handle_message(child.request("child question"))
first = (await child.context_rows())[0]
- assert first.context_seq == 1 and first.session_id == "ses_child"
+ assert first.context_seq == 1 and first.session_id == "seschild01"
blocks = [block.text for block in first.message.content if isinstance(block, TextBlock)]
[notice] = [text_value for text_value in blocks if text_value.startswith("<fork>")]
assert "fork of Release work (Session " + SESSION + ")" in notice
diff --git a/tests/test_vibey_prompt_snapshots.py b/tests/test_vibey_prompt_snapshots.py
index ff85ffdba..a039f78f2 100644
--- a/tests/test_vibey_prompt_snapshots.py
+++ b/tests/test_vibey_prompt_snapshots.py
@@ -37,6 +37,9 @@ def choose(previous, candidate, **overrides):
(Component("hosted-tools", "new"), 2),
(Component("unknown-future-module", "new"), 2),
(Component("tool-environment", "new"), 3),
+ (Component("bot-identity-prompt", "new"), 1),
+ (Component("bot-memory-prompt", "new"), 1),
+ (Component("bot-main-prompt", "new"), 1),
])
def test_each_component_class_replaces_only_at_its_tier(component, expected):
old = replace(component, content="old")
@@ -218,3 +221,14 @@ def test_a_failed_optional_write_does_not_fail_the_turn(tmp_path, monkeypatch):
monkeypatch.setattr(SnapshotStore, "_write_bytes", denied)
assert not store.save("session", state, snapshot=True)
assert store.load("session") is None
+
+
+def test_a_bots_own_memory_file_is_tier_three_and_the_shared_layer_tier_two(monkeypatch, tmp_path):
+ """bots.md D11: a Bot's own AGENTS.md is its own writing; the memory Bot's shared layer is bounded."""
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ own = str(tmp_path / "bots" / "cso" / "AGENTS.md")
+ shared = str(tmp_path / "bots" / "AGENTS.md")
+ nested = str(tmp_path / "bots" / "cso" / "notes" / "AGENTS.md")
+ for path, expected in ((own, 3), (shared, 2), (nested, 2)):
+ component = Component("file:" + path, "new", path)
+ assert component_tier(replace(component, content="old"), component) == expected, path
diff --git a/vibe/api.py b/vibe/api.py
index 00ab4d8e6..d11d66044 100644
--- a/vibe/api.py
+++ b/vibe/api.py
@@ -2449,7 +2449,10 @@ def set_default_vibe_agent(name: str, *, user_context: Any = None) -> dict:
agent = store.require_manageable(name, user_context=context)
if not agent.enabled:
raise ValueError(f"agent '{agent.name}' is disabled")
- store.set_default_agent_name(name, user_context=context)
+ try:
+ store.set_default_agent_name(name, user_context=context)
+ except AgentBotLockedError as exc:
+ return _agent_lifecycle_error(exc)
return {"ok": True, "default_agent_name": agent.name, "agent": _vibe_agent_payload(agent, brief=True)}
finally:
store.close()
diff --git a/vibe/cli.py b/vibe/cli.py
index 15eb06534..24db7f62d 100644
--- a/vibe/cli.py
+++ b/vibe/cli.py
@@ -5459,6 +5459,9 @@ def cmd_agent_default(args):
agent = store.require(args.name)
_print_cli_payload("default_agent", default_agent_name=agent.name, agent=_agent_payload(agent, brief=True))
return 0
+ except AgentBotLockedError as exc:
+ _print_task_error(_agent_lifecycle_cli_error(exc))
+ return 1
except Exception as exc:
_print_task_error(exc)
return 1
@@ -17891,8 +17894,9 @@ def build_parser():
"set",
help="Make an existing Vibey Agent a Bot",
description=(
- "Make an enabled Vibey Agent a Bot. Its handle is its Agent name; an Agent that was a Bot before "
- "gets its old handle back, with its Session and directory."
+ "Make an enabled Vibey Agent a Bot, other than the built-in vibey Agent and the default Agent. Its "
+ "handle is its Agent name; an Agent that was a Bot before gets its old handle back, with its Session "
+ "and directory."
),
error_help_command="vibe bot set --help",
)
diff --git a/vibe/i18n/en.json b/vibe/i18n/en.json
index bf21a8f8b..c5b0b0601 100644
--- a/vibe/i18n/en.json
+++ b/vibe/i18n/en.json
@@ -378,7 +378,7 @@
},
"agentLifecycle": {
"agent_is_bot": {
- "message": "Agent `{agent}` is a Bot, so it stays enabled and keeps its name.",
+ "message": "Agent `{agent}` is a Bot: it stays enabled, keeps its name, and is never the default Agent.",
"hint": "Remove it from Bots first; you can still change its model, effort, description, and system prompt."
},
"agent_always_enabled": {
@@ -409,6 +409,8 @@
"bot_agent_backend": "Only Vibey Agents can be set as Bots.",
"bot_agent_disabled": "Enable the Agent before setting it as a Bot.",
"bot_agent_is_bot": "This Agent is already a Bot.",
+ "bot_agent_builtin": "The built-in Vibey Agent stays an Agent and cannot be set as a Bot.",
+ "bot_agent_default": "This Agent is the default Agent. Choose another default before setting it as a Bot.",
"bot_main_not_removable": "The main Bot cannot be removed.",
"bot_main_position": "The main Bot always comes first.",
"bot_position_invalid": "A Bot's position is a whole number from 1.",
diff --git a/vibe/i18n/zh.json b/vibe/i18n/zh.json
index ecd6663f0..6047a634b 100644
--- a/vibe/i18n/zh.json
+++ b/vibe/i18n/zh.json
@@ -378,7 +378,7 @@
},
"agentLifecycle": {
"agent_is_bot": {
- "message": "Agent `{agent}` 是伙伴,因此保持启用并保留名称。",
+ "message": "Agent `{agent}` 是伙伴:保持启用、保留名称,也不能设为默认 Agent。",
"hint": "请先将它移出伙伴;仍可调整它的模型、Effort、描述与系统提示词。"
},
"agent_always_enabled": {
@@ -397,9 +397,9 @@
"bots": {
"sessionProtected": "伙伴的对话由 Avibe 管理:不能归档,标题跟随伙伴的名字。",
"bot_not_found": "找不到伙伴 `@{handle}`。",
- "bot_handle_invalid": "`{handle}` 不是有效的标识。请使用 2 到 24 个小写字母、数字或连字符,以字母开头,且不以连字符结尾。",
- "bot_handle_reserved": "标识 `{handle}` 已保留给内置伙伴。",
- "bot_handle_taken": "标识 `{handle}` 已被占用。",
+ "bot_handle_invalid": "`{handle}` 不是有效的代号。请使用 2 到 24 个小写字母、数字或连字符,以字母开头,且不以连字符结尾。",
+ "bot_handle_reserved": "代号 `{handle}` 已保留给内置伙伴。",
+ "bot_handle_taken": "代号 `{handle}` 已被占用。",
"bot_display_name_required": "请给伙伴起个名字。",
"bot_display_name_too_long": "伙伴的名字最多 64 个字符。",
"bot_avatar_invalid": "头像无效。请选择一个 emoji 和颜色,或上传一张图片。",
@@ -409,6 +409,8 @@
"bot_agent_backend": "只有 Vibey Agent 可以设为伙伴。",
"bot_agent_disabled": "请先启用这个 Agent,再设为伙伴。",
"bot_agent_is_bot": "这个 Agent 已经是伙伴。",
+ "bot_agent_builtin": "内置的 Vibey Agent 保持为 Agent,不能设为伙伴。",
+ "bot_agent_default": "这个 Agent 是默认 Agent。请先选择其他默认 Agent,再把它设为伙伴。",
"bot_main_not_removable": "主伙伴不能移出。",
"bot_main_position": "主伙伴始终排在第一位。",
"bot_position_invalid": "伙伴的位置是从 1 开始的整数。",
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index ac524321b..466c6c8d5 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -5520,7 +5520,7 @@ def _vibe_agent_result_response(result: dict):
status = 200
if not result.get("ok", True):
code = result.get("code")
- if code in {"agent_in_use", "agent_archived_read_only"}:
+ if code in {"agent_in_use", "agent_archived_read_only", "agent_is_bot"}:
status = 409
elif code in {"agent_not_found", "agent_import_source_not_found"}:
status = 404
@@ -5727,7 +5727,7 @@ def vibe_agents_default_post():
payload = request.json or {}
try:
- return jsonify(
+ return _vibe_agent_result_response(
api.set_default_vibe_agent(
payload.get("name") or "",
user_context=getattr(g, "authorization_context", None),