Skip to content

[Feature] /workspace 命令支持工具调用格式配置参数 / /workspace command with tool call format configuration parameter #101

@SunYanbox

Description

@SunYanbox

现状 / Current State
当前 /workspace 命令没有参数来控制发给大模型的工具调用格式要求,导致无法针对不同模型或场景灵活调整提示词中的格式约束。
Currently the /workspace command has no parameter to control the tool call format requirements sent to the LLM, making it impossible to flexibly adjust format constraints in prompts for different models or scenarios.

目标 / Goal
/workspace 命令增加参数,允许用户指定期望的工具调用格式(如 xml、json、python_dict、auto 等),系统据此生成对应的格式要求说明并注入到大模型提示词中。
Add parameters to the /workspace command allowing users to specify the expected tool call format (e.g., xml, json, python_dict, auto), so the system can generate corresponding format requirements and inject them into LLM prompts.

提议的参数 / Proposed Parameters

参数 / Parameter 说明 / Description
--tool-format / -tf 指定工具调用格式 / Specify tool call format
可选值 / Options xml (默认/current default), json, python, auto
--tool-format-strict 严格模式:不符合格式则重试 / Strict mode: retry if format mismatches

格式行为 / Format Behaviors

  • xml:使用现有的 <func_call> 标签格式 / Use existing <func_call> tag format
  • json:要求输出标准 JSON,如 {"function": "name", "arguments": {...}} / Require standard JSON output
  • python:要求输出 Python dict 或函数调用表达式 / Require Python dict or function call expression
  • auto:让模型自由选择,后端用 RobustCallParser 解析 / Let model choose freely, backend parses with RobustCallParser

使用示例 / Usage Example

/workspace --tool-format json
/workspace -tf python --tool-format-strict
/workspace --tool-format auto

提示词模板示例 / Prompt Template Example

format_prompts = {
    "xml": "你必须使用 <func_call> 标签包裹工具调用...",
    "json": '你必须输出 JSON 格式:{"function": "函数名", "arguments": {...}}',
    "python": "你必须输出 Python 字典格式:{'参数名': '参数值'}",
    "auto": "你可以自由选择格式,但必须能被工具调用解析器理解",
}

实现要点 / Implementation Highlights

  • 参数解析扩展 / Extend argument parsing
  • 格式配置存储到会话上下文 / Store format config in session context
  • 生成系统提示词时动态注入对应格式要求 / Dynamically inject corresponding format requirements when generating system prompt
  • 响应解析时根据配置调用相应的解析器 / Call appropriate parser based on config when parsing response
  • RobustCallParser 集成,auto 模式使用全部解析策略 / Integrate with RobustCallParser, auto mode uses all parsing strategies

交互流程 / Interaction Flow

用户 / User
    ↓
/workspace -tf json
    ↓
系统保存格式配置 / System saves format config
    ↓
发送给大模型时注入 JSON 格式要求 / Inject JSON format requirements when sending to LLM
    ↓
大模型返回 JSON / LLM returns JSON
    ↓
使用 JSON 解析器提取 / Extract with JSON parser
    ↓
执行工具调用 / Execute tool call

兼容性 / Compatibility

  • 不指定参数时保持原有 xml 行为,不破坏现有体验 / Keep original xml behavior when parameter not specified, no breaking change
  • 支持在会话中动态切换格式 / Support dynamic format switching during a session

未来扩展 / Future Extensions

  • 支持自定义格式模板 / Support custom format templates
  • 支持按工具单独配置格式 / Support per-tool format configuration

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions