AS AgentScopeAPI 手册 / API Reference
环境配置Setup

一次配置,跑通两条轨道Set up once, run both tracks

实验室默认离线:Python 用 ScriptedModel,Java 用 FakeChatModel,所有 check 都不访问网络。真实模型只在 run --online 时可选启用。The lab is offline by default: Python uses ScriptedModel, Java uses FakeChatModel, and every check stays off the network. Real models are opt-in only through run --online.

Python 2.0.11

在工作区根目录使用独立虚拟环境。运行 lab.py 前先激活它,这样 CLI、测试与 Java 的 MCP 客户端会使用同一个解释器。Use a dedicated virtual environment at the workspace root. Activate it before running lab.py so the same interpreter is used by the CLI, tests and the Java MCP client.

Windows / PowerShell
cd E:/Agent开发相关/AgentScope学习
python -m venv .venv-lab
.venv-lab/Scripts/python -m pip install -r lab/requirements.txt
cd lab
../.venv-lab/Scripts/python.exe lab.py doctor
macOS / Linux
cd /path/to/AgentScope学习
python3 -m venv .venv-lab
.venv-lab/bin/python -m pip install -r lab/requirements.txt
cd lab
../.venv-lab/bin/python lab.py doctor

doctor 会打印 Python 版本、agentscope 版本、Java 与 Maven 路径,以及解析后的 lab 根目录。doctor prints the Python version, agentscope version, Java and Maven paths, and the resolved lab root.

Java 2.0.4

需要 JDK 17+ 与 Maven 3.9+。pom 会解析 agentscope-core、model-openai 与 rag-simple。只有在依赖已缓存到本地后才使用 -o。Requires JDK 17+ and Maven 3.9+. The pom pulls agentscope-core, model-openai and rag-simple. Use -o only after the dependencies are cached locally.

First run
cd lab/java
mvn -q compile exec:java -Dexec.args="check p0"
Offline after the first run
cd lab/java
mvn -q -o compile exec:java -Dexec.args="check p0"

exec:java 不会自动重新编译。务必先 compile,否则旧 class 会掩盖你的修改。exec:java does not recompile automatically. Always run compile first, or a stale class can hide your edit.

常用命令Commands

Python
cd lab
python lab.py list
python lab.py run m1
python lab.py check m1
python lab.py check --all
Java
cd lab/java
mvn -q -o compile exec:java -Dexec.args="list"
mvn -q -o compile exec:java -Dexec.args="run m1"
mvn -q -o compile exec:java -Dexec.args="check m1"
mvn -q -o compile exec:java -Dexec.args="check --all"

任务阶梯Mission ladder

每次 check 会打印 PASS CODE、XP 与徽章名。在站点领取通行码即可记录到所选轨道。Each check prints PASS CODE, XP and the badge name. Claim the code on the site to record progress for the selected track.

任务MissionXP徽章Badge判题命令Check command
00 点火Ignition80Ignitionpython lab.py check p0
01 侦察兵Research Scout160Scoutpython lab.py check m1
02 修补匠Code Patcher200Patcherpython lab.py check m2
03 馆员Librarian180Librarianpython lab.py check m3
04 导演Showrunner240Showrunnerpython lab.py check m4
05 接线员Relay Operator200Relay Operatorpython lab.py check m5
06 舰长Captain300Captainpython lab.py check m6

排障Troubleshooting

  • ModuleNotFoundError: agentscope —— 你用的是系统 Python。请用 .venv-lab 运行 lab.py。ModuleNotFoundError: agentscope — you are using the system Python. Run lab.py with .venv-lab.
  • Maven 离线解析不到 agentscope-core —— 去掉一次 -o,或让 Maven 指向含有 2.0.4 的仓库。Maven cannot resolve agentscope-core offline — remove -o once, or point Maven at a repository that has 2.0.4.
  • Java MCP 初始化超时 —— .venv-lab 必须安装 mcp,且 PYTHONPATH 要指向 lab 根目录。Java MCP init timeout — the .venv-lab interpreter must have mcp installed and PYTHONPATH must point at the lab root.
  • Java RAG 检索为空 —— RetrieveConfig 默认 scoreThreshold 0.5,而哈希嵌入只有约 0.28,需要设为 0.0。RAG returns nothing in Java — RetrieveConfig defaults to scoreThreshold 0.5, while hash embeddings score around 0.28. Set 0.0.
  • Tool not found —— Python 的 MCP 工具带 mcp__server__ 前缀,Java 直接用远端名。检查脚本里的工具名。Tool not found — Python MCP tools carry mcp__server__ prefixes, Java exposes the remote name. Check the scripted tool name.

安全提示Safety notes

  • PermissionMode.BYPASS 只适用于隔离的实验沙箱。生产 Agent 应从 DEFAULT 开始并添加拒绝规则。PermissionMode.BYPASS exists only for isolated lab sandboxes. Start production agents from DEFAULT and add deny rules.
  • MCP 工具输出是不可信输入。把它当数据而不是指令;生产环境要限制长度并做隔离。MCP tool output is untrusted input. Treat it as data, not instructions; apply length limits and isolation in production.
  • 不要在生成工作区运行实验室。所有写入都限制在 lab/work。Never run the lab against a production workspace. All writes are confined to lab/work.
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.