快速上手
自 0.6.0 版本起,Bub 本体拆分成了两部分,因此你可以根据需要选择使用哪部分来玩转 Bub。
这一页假设你已经安装 Bub。
从 CLI 启动
Section titled “从 CLI 启动”打开你系统的终端,然后按如下步骤在命令行中进行操作:
-
如果你从未配置过 Bub,可以先执行如下命令来完成初始配置:
终端窗口 bub onboard -
在任意目录中创建一个工作区(目录)并切换到当中,然后使用
bub chat启动一个交互式会话:终端窗口 mkdir hello-bub && cd hello-bubbub chat -
现在,可以尝试复制粘贴如下文本并与 Bub 进行对话:
终端窗口 Summarize the files in this directory
在交互式的 CLI 界面中,使用 Ctrl+D 或输入 ,quit 退出交互式会话。
用 SDK 运行
Section titled “用 SDK 运行”如果要把 Agent 嵌入自己的 Python 项目,可以从基础 SDK 开始。
-
创建新项目并安装 Bub:
终端窗口 uv init --python 3.12 my-agent && cd my-agentuv add bub -
把下面这段代码保存为
main.pymain.py import asyncioimport republicfrom bub.core import Agentasync def main() -> None:agent = Agent(system_prompt="Be concise.")async with republic.get_model("openai:gpt-5-mini") as model:async with agent.run("What can you do?", model=model, tape="demo") as stream:async for event in stream:if event.kind == "text":print(event.data.get("delta", ""), end="")asyncio.run(main()) -
用你的 API Key 跑起来
终端窗口 export REPUBLIC_OPENAI_API_KEY=sk-...uv run python main.py
恭喜你,已经掌握 Bub 的基本使用方式了,接下来你可以继续深入探索这两种方式以解锁更多使用场景。
当然,如果你愿意的话,也可以继续了解一下 Bub 有哪些设计巧思。