ToolCall 工具调用
AI 对话组件。公开入口:ToolCall。
在线演示
本页复用官方 Go gallery 的真实示例。下方可以切换场景、主题和深浅色;长页面支持滚动,复杂布局可以横向滚动或在独立页面打开。
ToolCall 工具调用 · 在线体验真实 Go 组件
在独立页面打开 ↗示例代码
以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。
API
签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。
入口函数
ui.ToolCall
go
func ToolCall(c *Context, name string) *ToolCallWToolCall adds a tool call card for tool name.
ui.ToolCall(c, "read_file").Summary("src/main.go").Status(ui.ChainSuccess).
Duration(320*time.Millisecond).Args(`{"path":"src/main.go"}`).Result(out)
返回 *ToolCallW,可链式调用的方法见 ToolCallW 方法。
ToolCallW 方法
ui.ToolCallW:ToolCallW is a collapsible card for one tool invocation: name, summary, status and duration in the header; arguments and result in the body.
| 方法 | 说明 | 签名 |
|---|---|---|
Args | Args sets the arguments shown in the body (JSON by default, see Lang). | Args(s string) *ToolCallW |
Body | Body adds custom content at the end of the expanded body (a diff, an image, an Approval). | Body(fn func()) *ToolCallW |
DefaultOpen | DefaultOpen starts expanded. | DefaultOpen() *ToolCallW |
Duration | Duration shows how long the call took. | Duration(d time.Duration) *ToolCallW |
Icon | Icon replaces the tool icon. | Icon(ic *icon.Icon) *ToolCallW |
Lang | Lang sets the code languages of the arguments and the result (default "json" and none). | Lang(args, result string) *ToolCallW |
Layout | Layout applies layout options to the card. | Layout(opts ...layout.Option) *ToolCallW |
Open | Open reports whether the body is shown. | Open() bool |
Result | Result sets the output shown in the body. | Result(s string) *ToolCallW |
Started | Started shows the live elapsed time while the call is running. | Started(t time.Time) *ToolCallW |
Status | Status sets the call's state (default ChainPending). | Status(s ChainStatus) *ToolCallW |
Summary | Summary shows a short description after the name (a path, a query). | Summary(s string) *ToolCallW |
Toggled | Toggled reports a click on the header this frame. | Toggled() bool |
相关链接
本页由完整组件表、实际 gallery 注册信息和 Go 源码(site/tools/compdoc)生成;新增组件未接入演示时,文档构建会报错。场景中的表单、表格、图表和移动端屏幕使用示例数据。