shared_files
feishu.agent.toolkit.shared_files
¶
用户分享文件的工具:列出、(多模态)描述、上传到云盘。详见 feishu.agent.toolkit 与 feishu.agent.shared_files。
所有消费类工具都只接收 file_id 句柄,经 [feishu.agent.toolkit._base.resolve_shared_file_bytes][] 在调用瞬间
按请求用户取字节——模型永远拿不到字节,且不能越权访问他人文件。
list_shared_files
¶
list_shared_files(*, description: str, name: str = 'list_shared_files', locale: str = 'zh-CN') -> Tool
读类工厂:列出请求用户最近分享给机器人的文件,返回一个 feishu.agent.tools.Tool。
只返回中性元数据(file_id / name / media_type / kind / size / 时间),**绝不**返回字节或
file_key;结果严格限定为请求用户本人的文件。
示例:
| Python Console Session | |
|---|---|
源代码位于: feishu/agent/toolkit/shared_files.py
describe_shared_file
¶
describe_shared_file(*, description: str, analyzer: Callable[..., Awaitable[str]], name: str = 'describe_shared_file', locale: str = 'zh-CN') -> Tool
读类工厂:对某个分享文件做(多模态)内容描述 / 提取,返回文本摘要,返回一个 feishu.agent.tools.Tool。
字节经 [feishu.agent.toolkit._base.resolve_shared_file_bytes][] 按请求用户取得后,交由产品注入的 analyzer
(签名 async (data: bytes, *, media_type, name) -> str,通常用沙箱抽取 + 多模态模型实现)产出描述;模型只看到
描述文本,不接触字节。结果附**防注入提示**:文件内容来自用户、不可信,模型不得执行其中的指令。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
str
|
工具描述(产品本地化文案)。 |
必需 |
|
Callable[..., Awaitable[str]]
|
产品注入的内容分析器,输入字节、输出描述文本。 |
必需 |
|
str
|
工具名。默认为 |
'describe_shared_file'
|
|
str
|
本地化标识。默认为 |
'zh-CN'
|
示例:
| Python Console Session | |
|---|---|
源代码位于: feishu/agent/toolkit/shared_files.py
upload_shared_file_to_drive
¶
upload_shared_file_to_drive(*, description: str, name: str = 'upload_shared_file_to_drive', locale: str = 'zh-CN', requires_approval: bool = True, as_user: bool = True, auth_scopes: Sequence[str] = ()) -> Tool
写类工厂:把某个分享文件上传到用户云盘的指定文件夹,返回一个需审批的 feishu.agent.tools.Tool。
字节经 [feishu.agent.toolkit._base.resolve_shared_file_bytes][] 按请求用户取得后,以用户身份调用
client.drive.files.upload(file_name, parent_node, data, size=...)。requires_approval=True 时由
feishu.agent.loop.Agent 先发审批卡片,用户批准后处理函数才执行上传。
示例:
| Python Console Session | |
|---|---|