agentscope-ai / agentscope-ai/agentscope-java

[Feature]: Support strict mode consistently across all tool definition paths

Đang mở
#1,243 2 bình luận 0 reaction 1 người được giao Được @BEASTSHRIRAM nhận Xem trên GitHub
area/core/tool enhancement
Ngôn ngữ chính
Java
Star
5.6k
Fork
1.3k
Merge trung bình
4 ngày 12 giờ
Pull request đã merge (30 ngày)
77

Mô tả

**Is your feature request related to a problem? Please describe.**

`ToolSchema` already exposes a `strict` field, and the OpenAI formatter also has support for propagating `strict` into the final tool/function definition.

However, strict mode is not consistently preserved across all tool definition and registration paths.

For example, when building a tool schema manually, it is possible to set strict mode explicitly:

~~~java
ToolSchema.builder()
.name(...)
.description(...)
.parameters(parameters)
.strict(true)
.build();
~~~

But in practice, this support is not consistently available through all higher-level tool registration flows.

In particular, when registering a schema through `Toolkit#registerSchema`, the provided `ToolSchema` appears to be wrapped into a `SchemaOnlyTool`, and during that process the original `ToolSchema` is not preserved as-is. As a result, the `strict` flag is effectively lost and does not reach the final tool definition sent to the model API.

This creates an inconsistency:
- `ToolSchema` already exposes `strict`
- the formatter layer already supports `strict`
- but some framework registration paths do not preserve or propagate it

This makes it difficult to rely on strict mode as a first-class capability.

**Describe the solution you'd like**

I’d like strict mode to be supported consistently across all tool schema definition and registration paths, including:

1. Manual `ToolSchema.builder(...)`
2. `Toolkit#registerSchema(...)`
3. `@Tool` annotation-based tools
4. `AgentTool` interface / implementation-based tools
5. Any other framework-provided path that eventually produces a `ToolSchema` or tool definition for model APIs

Concretely, it would be helpful if:
- `ToolSchema.strict` is always preserved when a tool is wrapped, converted, or re-registered
- higher-level APIs such as `@Tool` and `AgentTool` expose a way to configure strict mode
- all internal tool conversion paths propagate the strict flag into the final model API payload when the provider supports it

**Describe alternatives you've considered**

The current workaround is to avoid some higher-level registration paths and manually control tool schema construction as much as possible.

However, this has several downsides:
- it reduces the value of the higher-level abstractions
- it makes strict mode behavior depend on which registration path is used
- it is not obvious to users that `strict` may be silently lost during registration or wrapping
- it makes the API less consistent and less predictable

Another workaround would be to customize framework internals, but that is much heavier than having first-class support.

**Additional context**

According to the [OpenAI function calling documentation](https://developers.openai.com/api/docs/guides/function-calling), `strict: true` improves schema adherence for tool/function calling and is recommended when developers want reliable structured arguments.

Because of this, strict mode is not just a minor optional flag — it can materially affect tool calling reliability and schema correctness.

It would be great if AgentScope Java could provide a unified strict-mode experience across all tool-definition styles.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.