Skip to content

Conversation

@qxwangjava
Copy link

@qxwangjava qxwangjava commented Jan 31, 2026

Add context propagation to agent streaming calls by capturing and writing the current context before execution. This ensures context information is maintained throughout the streaming operation.

AgentScope-Java Version

[The version of AgentScope-Java you are working on, e.g. 1.0.8, check your pom.xml dependency version or run mvn dependency:tree | grep agentscope-parent:pom(only mac/linux)]

Description

[Please describe the background, purpose, changes made, and how to test this PR]

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

Add context propagation to agent streaming calls by capturing and writing the current context before execution. This ensures context information is maintained throughout the streaming operation.
@qxwangjava qxwangjava requested a review from a team January 31, 2026 14:31
@cla-assistant
Copy link

cla-assistant bot commented Jan 31, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ qxwangjava
❌ 王奇轩


王奇轩 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@gemini-code-assist
Copy link

Summary of Changes

Hello @qxwangjava, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a crucial enhancement to the AgentScope framework by enabling Reactor context propagation within agent streaming calls. This ensures that contextual information, such as tracing IDs or user details, is consistently maintained and accessible throughout the lifecycle of streaming operations, improving observability and data flow integrity.

Highlights

  • Context Propagation: Implemented Reactor context propagation for agent streaming calls, ensuring that the current context is captured from the FluxSink and applied to the agent's execution Mono.
  • Test Coverage: Updated AgentStreamingTest to include a test case that verifies the correct propagation of Reactor context during streaming operations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly implements context propagation for agent streaming calls by using contextWrite to pass the downstream Reactor context to the agent execution mono. The change in AgentBase.java is sound. My main feedback is on the accompanying test. While it exercises the new code path, it doesn't verify that the context is actually propagated and accessible. I've left a comment with a suggestion to strengthen the test by adding an assertion for the context value.

Comment on lines 224 to 225
agent.stream(inputMsgs, options).contextWrite(ctx -> ctx.put("test", "test"))
.doOnNext(events::add).blockLast();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While adding contextWrite helps exercise the new code path, this test doesn't verify that the context is actually propagated and accessible within the agent's execution. A more robust test would assert that the value from the context is correctly received.

You could, for example, modify TestStreamingAgent to read a value from the Reactor context within its doCall method (using Mono.deferContextual) and store it in a field. Then, in this test, you could assert that the agent has captured the correct value from the context after the stream completes. This would provide a stronger guarantee that context propagation is working as expected.

@codecov
Copy link

codecov bot commented Jan 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant