Skip to content

feat: ssh 元工具 #603

@ZhulongNT

Description

@ZhulongNT

Usecase: 远程服务器不想或不能安装 generic agent。如果把ssh连接的维护放到agent loop 中,那么为了完成loop,ssh可能中断。

设想的实现方法:使用 Paramiko

默认使用阻塞模式:对于简单查询(df -h, ps aux),一次性拿到结果最省事。

启用流式模式 当满足以下任一条件时:

命令本身会持续输出(如 tail -f, watch)

命令需要用户输入(sudo, ssh-keygen -t rsa)

你想让 LLM 根据实时输出动态决策(例如:看到错误日志后立即执行另一个补救命令)

方案二:流式处理 + 持久化存储

当你需要实时展示输出(比如 tail -f)或处理长时间运行的命令时:

每读取到一块数据,就追加到一个内存缓冲区或日志文件。

如果需要“回顾历史”,从那个缓冲区/文件中读取,而不是再从 SSH 通道读。

典型设计:维护一个会话对象,其中包含 output_buffer = [],每次 channel.recv() 后都 output_buffer.append(chunk),并提供 get_full_output() 方法给 LLM 查询。

在工具层面提供明确的语义

execute_and_forget():执行命令,丢弃输出(不适合查询)。

execute_and_return():阻塞等待结束,返回完整输出。

start_streaming(callback):启动流式传输,每次新数据都调用 callback 存起来,不直接暴露给 LLM 重复读取。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions