帮你快速理解、总结文档立即下载

参与日志

最近更新时间:2026-08-27 17:42:00
我的收藏

接口介绍

MetadataClient 提供以下参与日志接口,用于记录和查询 Agent 参与 Task 执行的日志。参与日志可用于追踪 Agent 在各 Task 中的执行事件和状态变化。
append_participation_log:追加一条参与日志记录。
list_participation_logs:按条件查询参与日志列表。

导入

from tencentdb_agent_memory.v3 import MetadataClient

方法签名

def append_participation_log(self, p: Dict[str, Any]) -> Dict[str, Any]
def list_participation_logs(self, p: Dict[str, Any]) -> Dict[str, Any]

使用示例

append_participation_log

from tencentdb_agent_memory.v3 import MetadataClient

metadata = MetadataClient(
endpoint="https://memory.tdai.tencentyun.com",
api_key="sk-xxxxxxxxxxxxxxxx",
service_id="tdai-mem-xxxxxxxx",
)

resp = metadata.append_participation_log({
"task_id": "task-xyz", # 必填,Task ID
"agent_id": "agt-abc", # 必填,参与的 Agent ID
"event": "completed", # 必填,事件类型(started/completed/failed)
"metadata": {"duration_ms": 5000}, # 可选,自定义事件元数据
})
print(resp)

list_participation_logs

resp = metadata.list_participation_logs({
"task_id": "task-xyz", # 必填,Task ID
"agent_id": "agt-abc", # 可选,按 Agent 过滤
"limit": 50, # 可选,分页大小
"offset": 0, # 可选,分页偏移
})
for log in resp["items"]:
print(log["event"], log["created_at_ms"])

请求参数

append_participation_log

参数名
类型
必填
描述说明
task_id
str
Task ID
agent_id
str
参与的 Agent ID
event
str
事件类型,如 startedcompletedfailed

list_participation_logs

参数名
类型
必填
描述说明
task_id
str
Task ID
agent_id
str
按 Agent 过滤
limit
int
返回结果数量上限
offset
int
分页偏移量

响应示例

append_participation_log

{
"log_id": "log-550e8400-e29b-41d4-a716-446655440000",
"task_id": "task-xyz",
"agent_id": "agt-abc",
"event": "completed",
"created_at_ms": 1723968000000
}

list_participation_logs

{
"items": [
{
"log_id": "log-001",
"task_id": "task-xyz",
"agent_id": "agt-abc",
"event": "started",
"created_at_ms": 1723900000000
},
{
"log_id": "log-002",
"task_id": "task-xyz",
"agent_id": "agt-abc",
"event": "completed",
"created_at_ms": 1723968000000
}
],
"total": 2
}

响应参数说明

参数名
类型
参数含义
log_id
str
日志唯一标识 ID
task_id
str
Task ID
agent_id
str
Agent ID
event
str
事件类型
created_at_ms
int
日志创建时间,Unix 时间戳,单位为毫秒
items
List[Dict]
日志列表
total
int
符合条件的日志总数

错误码

错误码
触发场景
处理建议
400
请求参数不合法(如 event 为空)
检查参数是否符合约束条件
401
API Key 无效或缺失
检查 Bearer Token 配置
404
指定 Task 或 Agent 不存在
确认 ID 是否正确
500
服务内部错误
稍后重试