Skip to content

使用自定义工作流CompiledGraph, agui无法返回事件流,REASONING_MESSAGE_CONTENT和TEXT_MESSAGE_CONTENT等重要的事件流类型没有 #2102

Open

Description

@lijinhua024-blip
Image

`
/**

  • 适配 CompiledGraph 为 AgentScope Agent
    */
    public class CompiledGraphAdapter implements Agent {

    private final CompiledGraph compiledGraph;
    private final String agentId;
    private final String name;

    public CompiledGraphAdapter(CompiledGraph compiledGraph) {
    this(compiledGraph, "compiled-graph-agent", "opt_workflow_agent");
    }

    public CompiledGraphAdapter(CompiledGraph compiledGraph, String agentId, String name) {
    this.compiledGraph = compiledGraph;
    this.agentId = agentId;
    this.name = name;
    }

    // ========== Agent 接口 ==========
    @OverRide
    public String getAgentId() {
    return agentId;
    }

    @OverRide
    public String getName() {
    return name;
    }

    @OverRide
    public void interrupt() {
    // 可空实现
    }

    @OverRide
    public void interrupt(Msg msg) {
    // 可空实现
    }

    // ========== ObservableAgent ==========
    @OverRide
    public Mono observe(Msg msg) {
    return Mono.empty();
    }

    @OverRide
    public Mono observe(List msgs) {
    return Mono.empty();
    }

    // ========== CallableAgent ==========
    @OverRide
    public Mono call(List msgs) {
    return Mono.fromCallable(() -> {
    // 1. 提取用户输入
    String userContent = msgs.stream()
    .filter(msg -> "USER".equalsIgnoreCase(msg.getRole().name()))
    .map(Msg::getTextContent)
    .reduce((a, b) -> b)
    .orElse("");

         // 2. 构建 Graph 输入 (OverAllState)
         // 使用 Spring AI 的 UserMessage
         Message userMessage = new UserMessage(userContent);
         Map<String, Object> inputData = Map.of(
                 "messages", List.of(userMessage)
         );
         OverAllState graphInput = new OverAllState(inputData);
    
         // 3. 执行 CompiledGraph
         RunnableConfig config = RunnableConfig.builder().build();
         OverAllState graphOutput = compiledGraph.invoke(graphInput, config)
                 .orElseThrow(() -> new RuntimeException("Graph 执行未返回结果"));
    
         // 4. 提取结果
         Map<String, Object> data = graphOutput.data();
         Object finalReport = data.get("final_report");
         AssistantMessage assistantMsg = (AssistantMessage) finalReport;
         String textContent = assistantMsg.getText();
    
    
         // 5. 构建 Msg
         Msg resultMsg = Msg.builder()
                 .id(UUID.randomUUID().toString())
                 .role(MsgRole.ASSISTANT)
                 .textContent(textContent)
                 .build();
         System.out.println("返回的 Msg: " + textContent);
         return resultMsg;
     });
    

    }

    @OverRide
    public Mono call(List msgs, Class<?> structuredModel) {
    return call(msgs);
    }

    @OverRide
    public Mono call(List msgs, com.fasterxml.jackson.databind.JsonNode schema) {
    return call(msgs);
    }

    // ========== StreamableAgent ==========
    @OverRide
    public Flux stream(List msgs, StreamOptions options) {
    // 调用 call 获取完整 Msg,然后包装为单个 AGENT_RESULT 事件
    return call(msgs)
    .map(msg -> new Event(EventType.SUMMARY, msg, true))
    .flux();
    }

    @OverRide
    public Flux stream(List msgs, StreamOptions options, Class<?> structuredModel) {
    return stream(msgs, options);
    }

    @OverRide
    public Flux stream(List msgs, StreamOptions options, JsonNode schema) {
    return stream(msgs, options);
    }
    }`

将自定义工作流通过agui暴露服务

Image

Activity

  1. lijinhua024-blip commented on Jul 10, 2026

    @lijinhua024-blip
    Author

    @jujn 帮忙看看,谢谢

  2. jujn commented on Jul 10, 2026

    @jujn
    Collaborator

    建议等后面 agui 模块重构。现在的 agui 模块还是用的 agentscope 1.0 的事件机制(Event)(有很多坑),很多新事件也不支持,等后面迁移到 2.0 事件(AgentEvent)吧。

  3. lijinhua024-blip commented on Jul 10, 2026

    @lijinhua024-blip
    Author

    @jujn 我们现在就要用自定义工作流,有临时方案可以用吗?比如自己手动暴露controller 返回agui数据流或agent scope 的原始数据流,感觉可行吗?

  4. jujn commented on Jul 10, 2026

    @jujn
    Collaborator

    @jujn 我们现在就要用自定义工作流,有临时方案可以用吗?比如自己手动暴露controller 返回agui数据流或agent scope 的原始数据流,感觉可行吗?

    维护成本比较高。你也可以本地改一下框架。
    目前框架层面主要是这个 AguiAgentAdapter 类有问题,发不出 text_content 是因为框架的问题,你让 ai 分析下吧:
    agentscope-extensions\agentscope-extensions-protocol\agentscope-extensions-agui\src\main\java\io\agentscope\core\agui\adapter\AguiAgentAdapter.java

    没有 reasoning_content ,你看下 AguiAdapterConfig.enableReasoning=true 这个配了没?如果是用 starter 的话,yml 配置文件里面 enableReasoning 要显示开启

  5. Zhanyuan23333 commented on Jul 10, 2026

    @Zhanyuan23333

    请问下agui重构 时间方面有计划了吗

  6. added
    bug
    area/ext/integration
    on Jul 11, 2026
  7. liyy653787585 commented on Jul 13, 2026

    @liyy653787585

    建议等后面 agui 模块重构。现在的 agui 模块还是用的 agentscope 1.0 的事件机制(Event)(有很多坑),很多新事件也不支持,等后面迁移到 2.0 事件(AgentEvent)吧。

    我看今天已经发布了2.0版本,在2.0版本中 该问题解决了吗?

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

    area/ext/integrationbug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions