0xPlaygrounds / 0xPlaygrounds/rig
feat: support provider-hosted tools in AgentBuilder end-to-end
- 主要語言
- Rust
- 星號
- 8.6k
- 分支
- 959
- 平均合併
- 4 小時 32 分鐘
- 30 天內合併 PR
- 117
描述
- [x] I have looked for existing issues (including closed) about this
## Feature Request
Add first-class support for provider-hosted tools in `AgentBuilder`, end-to-end from agent configuration through provider serialization.
### Motivation
Some LLM providers expose built-in tools (e.g. web search, code interpreter, file search) that sit alongside function-calling tools in the `tools` array of Chat Completions requests. These are *provider-hosted* — the provider executes them server-side and injects results directly into the LLM context, without requiring the client to implement execution logic.
Currently, `rig-core` has the `ProviderToolDefinition` type and `CompletionRequestBuilder::provider_tools()`, but the feature is incomplete:
- No provider actually consumes provider tools
- `AgentBuilder` has no equivalent method
- Provider serialization using `#[serde(flatten)]` on `additional_params` produces duplicate `"tools"` keys when both function tools and provider tools coexist, causing API rejections
### Proposal
1. **`AgentBuilder`**: expose `provider_tool()` / `provider_tools()` methods, mirroring `CompletionRequestBuilder`
2. **Agent runtime** (`agent/completion.rs`): pass provider tools alongside function tools when building the completion request (currently only function tools are set via `completion_request.tools(tooldefs)`)
3. **Provider layer**: fix serialization so function tools and provider tools are merged into a single `"tools"` array instead of producing duplicate keys via `#[serde(flatten)]` on `additional_params`. One approach: in `TryFrom`, merge provider tools from `additional_params` into the `tools` field, then strip them from `additional_params`.
### Alternatives
1. **Use `additional_params` directly** — tested and failed. API rejects duplicate `"tools"` keys produced by serde flatten.
2. **Bypass AgentBuilder, use `CompletionRequestBuilder` directly** — loses ReAct loop, ToolServer, PromptHook, history management, and error retry logic. Essentially requires rewriting the agent runtime.
貢獻指南
研究方向
Start by examining the `AgentBuilder` struct and its methods in the codebase, then look at `agent/completion.rs` to see how the completion request is built. Review the `ProviderToolDefinition` type and `CompletionRequestBuilder::provider_tools()`. The fix involves modifying serialization in the provider layer to merge tools arrays, likely in the `TryFrom` implementation. Run existing tests related to agent building and provider serialization to ensure changes don't break functionality.
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- rust
- 領域
- ai-infra-agents
- Issue 類型
- 功能
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 55/100