Skip to content

[train] Gateway anthropic adapter#70

Draft
zackcxb wants to merge 18 commits into
verl-project:mainfrom
zackcxb:pr25-anthropic-adapter
Draft

[train] Gateway anthropic adapter#70
zackcxb wants to merge 18 commits into
verl-project:mainfrom
zackcxb:pr25-anthropic-adapter

Conversation

@zackcxb

@zackcxb zackcxb commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Normalize gateway adapter/session plumbing for OpenAI and Anthropic providers.
  • Split adapter-side wire types from session/internal types, remove stale request/protocol shims, and tighten prefix canonicalization around tool call IDs.
  • Add a standalone examples/gateway/debug_launcher.py plus docs and tests for local gateway debugging and trajectory collection.

Testing

  • pytest -q tests/uni_agent/gateway/test_debug_launcher.py tests/uni_agent/gateway/adapters/test_openai_adapter.py tests/uni_agent/gateway/adapters/test_anthropic_adapter.py tests/uni_agent/gateway/test_gateway_actor_on_cpu.py

@zackcxb zackcxb changed the title Pr25 anthropic adapter [train] Gateway anthropic adapter Jun 25, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces provider adapters for Anthropic and OpenAI to translate wire protocol requests into a canonical internal format (InternalGenerationRequest), decoupling wire translation from the session and codec logic. It also adds a standalone gateway debug launcher (debug_launcher.py) with extensive documentation and comprehensive unit tests. Feedback on the debug launcher suggests simplifying the redundant type checking and decoding logic for TimeoutExpired exceptions since subprocess.run is invoked with text=True.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +450 to +463
stdout = exc.stdout if exc.stdout is not None else exc.output
stderr = exc.stderr
if isinstance(stdout, bytes):
stdout = stdout.decode(errors="replace")
elif stdout is None:
stdout = ""
else:
stdout = str(stdout)
if isinstance(stderr, bytes):
stderr = stderr.decode(errors="replace")
elif stderr is None:
stderr = ""
else:
stderr = str(stderr)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The subprocess.run call uses text=True, so exc.stdout and exc.stderr from a TimeoutExpired exception will be strings or None. The complex type checking and decoding logic for these attributes can be simplified.

Additionally, exc.output is an alias for exc.stdout, making the conditional assignment on line 450 redundant.

Suggested change
stdout = exc.stdout if exc.stdout is not None else exc.output
stderr = exc.stderr
if isinstance(stdout, bytes):
stdout = stdout.decode(errors="replace")
elif stdout is None:
stdout = ""
else:
stdout = str(stdout)
if isinstance(stderr, bytes):
stderr = stderr.decode(errors="replace")
elif stderr is None:
stderr = ""
else:
stderr = str(stderr)
stdout = exc.stdout or ""
stderr = exc.stderr or ""

zackcxb and others added 5 commits June 27, 2026 06:57
… nested helpers

- 收紧 ANTHROPIC_ERROR_TYPE_BY_STATUS 和 _OPENAI_ERROR_TYPE_BY_STATUS 到实际产出的状态码(400/409/500 和 400/409),去掉鉴权/限流/404 等 gateway 不会产生的映射
- 统一所有 text block join 为 "\n" 分隔(system / tool_result / user / assistant),对齐 Slime/PolAR/AReaL,避免 Claude Code prompt caching 拆分的多 block 粘连
- 提升嵌套 helper 到 module level:_fold_reminder_into_user、_infer_json_type、_infer_any_of_type,消除不必要的闭包嵌套
- 重构 mid-list system 折叠逻辑为独立函数 _fold_mid_list_system_into_user,与 _messages_to_internal 解耦
- 删除未使用 helper _text_part / _content_parts_or_text,逻辑 inline
- 调整 flush 函数为 early-return 风格,与 flush_user 对称
- 删除低价值测试文件 test_public_exports.py

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Route gateway tool-call decode through SGLang/vLLM parsers instead of VERL Pydantic schemas.

Keep Anthropic tool schemas as copied OpenAI function parameters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant