Skip to content

ToolCall 工具调用 ​

AI 对话组件。公开入口:ToolCall。

在线演示 ​

本页复用官方 Go gallery 的真实示例。下方可以切换场景、主题和深浅色;长页面支持滚动,复杂布局可以横向滚动或在独立页面打开。

ToolCall 工具调用 · 在线体验真实 Go 组件
在独立页面打开 ↗

查看此场景的 Go 源码 ↗

示例代码 ​

以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。

ToolCall 工具调用

gallery 演示 ToolCall 的具名 Render 函数,源码 page_chat.go#L222。

加载中…

API ​

签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。

入口函数 ​

ui.ToolCall ​

go
func ToolCall(c *Context, name string) *ToolCallW

ToolCall 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.

方法说明签名
ArgsArgs sets the arguments shown in the body (JSON by default, see Lang).Args(s string) *ToolCallW
BodyBody adds custom content at the end of the expanded body (a diff, an image, an Approval).Body(fn func()) *ToolCallW
DefaultOpenDefaultOpen starts expanded.DefaultOpen() *ToolCallW
DurationDuration shows how long the call took.Duration(d time.Duration) *ToolCallW
IconIcon replaces the tool icon.Icon(ic *icon.Icon) *ToolCallW
LangLang sets the code languages of the arguments and the result (default "json" and none).Lang(args, result string) *ToolCallW
LayoutLayout applies layout options to the card.Layout(opts ...layout.Option) *ToolCallW
OpenOpen reports whether the body is shown.Open() bool
ResultResult sets the output shown in the body.Result(s string) *ToolCallW
StartedStarted shows the live elapsed time while the call is running.Started(t time.Time) *ToolCallW
StatusStatus sets the call's state (default ChainPending).Status(s ChainStatus) *ToolCallW
SummarySummary shows a short description after the name (a path, a query).Summary(s string) *ToolCallW
ToggledToggled reports a click on the header this frame.Toggled() bool

相关链接 ​

本页由完整组件表、实际 gallery 注册信息和 Go 源码(site/tools/compdoc)生成;新增组件未接入演示时,文档构建会报错。场景中的表单、表格、图表和移动端屏幕使用示例数据。

以 MIT 许可发布