a2aproject / a2aproject/a2a-samples

[Java Example] task stream output error

未关闭
#181 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Jupyter Notebook
星标
1.8k
派生
751
PR 合并指标
30 天内没有已合并 PR

描述

### What happened?

In A2AClient.java

public CompletableFuture sendTaskStreaming(TaskSendParams params, StreamingEventListener listener) {

..........

HttpRequest httpRequest = HttpRequest.newBuilder()
.uri(URI.create(baseUrl + "/a2a/stream"))
.header("Content-Type", "application/json")
.header("Accept", "text/event-stream")
.POST(HttpRequest.BodyPublishers.ofString(requestBody))
.build();

HttpResponse response = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());

if (response.statusCode() != 200) {
listener.onError(new A2AClientException("HTTP " + response.statusCode() + ": " + response.body()));
return;
}

this code snnipet here is not stream out,should use like `HttpResponse.BodyHandlers.ofLines()` or ` HttpResponse.BodyHandlers.ofInputStream()` instead

after modify:

=== Streaming Translation (French to English) ===
Original French: Bonjour le monde! Comment allez-vous?
当前时间: 2025-06-25 19:58:43:354
Streaming translation event: {id=french-streaming-task, status={state=working, timestamp=2025-06-25T11:58:43.339288800Z}, final=false}
当前时间: 2025-06-25 19:58:44:250
Streaming translation event: {id=french-streaming-task, status={state=completed, timestamp=2025-06-25T11:58:44.249476800Z}, final=true}
Translation streaming completed
Streaming translation finished successfully

before modify:

=== Streaming Translation (French to English) ===
Original French: Bonjour le monde! Comment allez-vous?
当前时间: 2025-06-25 20:12:07:251
Streaming translation event: {id=french-streaming-task, status={state=working, timestamp=2025-06-25T12:12:06.439230200Z}, final=false}
当前时间: 2025-06-25 20:12:07:252
Streaming translation event: {id=french-streaming-task, status={state=completed, timestamp=2025-06-25T12:12:07.237351500Z}, final=true}
Translation streaming completed
Streaming translation finished successfully


look at the difference of time output above

### Relevant log output

```shell

```

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。