feat: provider-wide output compaction/truncation layer for CLI tool results

未关闭
#105 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 5 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
活跃
技术栈
go
领域
tooling

调研方向

Start by reading the implementation of k8s_get_resources from #83 and how providers return results through mcp.TextOutput; the issue names internal/commands and mcp.TextResult as possible integration points. Work out how output formats, structured content, configuration, and metrics should fit together. Done means a shared layer reduces oversized provider output safely and clearly reports truncation, with the open design questions resolved.

由索引模型根据 Issue 内容生成。

描述

enhancement

Summary

#83 (closing #82) adds a limit parameter to k8s_get_resources to cap result size. That fixes one tool, but the underlying problem is general: almost every provider returns raw CLI output (kubectl, helm, istioctl, cilium, argo, kubescape, ...) straight into the model's context via mcp.TextOutput. Large outputs (cluster-wide listings, describe, logs, proxy-config dumps, scan reports) can blow up token usage and exhaust the context window.

Rather than adding ad-hoc limits per tool, we should consider a shared output-reduction layer, inspired by rtk-ai/rtk — a CLI proxy that reduces LLM token consumption by 60–90% on common dev commands by filtering/compacting command output.

Proposal

Add a shared component in internal/ (e.g. alongside internal/commands or as a post-processor applied in mcp.TextResult) that:

  • Truncates safely per format — row-based for tabular output (preserving headers), items-level for JSON, passthrough for formats without a safe cut point (generalizing the approach in #83).
  • Always emits an explicit truncation notice with totals and how to narrow the query, so partial data is never mistaken for complete data.
  • Compacts noisy output — e.g. strip managedFields, last-applied-configuration annotations, empty/default fields, collapse repeated log lines, dedupe events.
  • Is configurable — global defaults via server flags/env/Helm values (e.g. max bytes/rows/tokens), with per-call overrides (limit=0 to disable) where it makes sense.
  • Is observable — metrics for bytes in/out and truncation counts per tool/provider.

Open questions

  • Default on (bounded) vs opt-in? (Same trade-off raised in #83.)
  • Size budget unit: rows, bytes, or estimated tokens?
  • Should per-command filters live in Go code, or be declarative/config-driven like rtk's filters?
  • How does this interact with StructuredContent and output schema validation?

References

主要语言
Go
星标
39
派生
35
平均合并
4 天 10 小时
30 天内合并 PR
8

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

kagent-dev/tools 的其他 Issue

查看 kagent-dev/tools 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。