Skip to content

s11: inject_background_results 里的 else 分支是不是走不到? #576

Description

@lll1024

看 s11 的时候有点没想明白这段:

if messages and messages[-1].get("role") == "user":
    # merge notifications into the last message
    ...
else:
    messages.append({"role": "user", "content": blocks})

inject_background_results() 目前只在 agent_loop() 每次调用模型之前执行。按现在的流程:

  • 用户输入后,外层会先 append 一条 user 消息,再进入 agent_loop();
  • 模型调用了工具时,循环末尾也会 append 一条 user/tool_result;
  • 模型没有调用工具时,循环直接 return,不会再次执行 inject。

所以在当前入口下,只要 messages 非空,执行到这里时最后一条看起来总是 user,else 分支似乎走不到(空列表也不会从当前入口传进来)。

这个分支是为了以后支持后台任务完成后主动唤醒 agent,还是单纯让函数可以独立复用?如果是有意保留,能否加一句注释或一个测试说明场景?

相关但不完全相同:#46

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions