-
Notifications
You must be signed in to change notification settings - Fork 259
feat: preserve context in agent streaming calls #691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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.
|
王奇轩 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. |
Summary of ChangesHello @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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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.
| agent.stream(inputMsgs, options).contextWrite(ctx -> ctx.put("test", "test")) | ||
| .doOnNext(events::add).blockLast(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
mvn spotless:applymvn test)