Skip to content

Conversation

letaoj
Copy link
Contributor

@letaoj letaoj commented Oct 1, 2025

Linked issue: #229

Purpose of change

This change added a example for the ReAct agent quickstart guide in Java similar to what python did. In this change, we are made a couple improvement to the existing single and multiple agent example to remove unused connection setup.

Tests

❯ cd examples; java --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED -cp "target/classes:$(mvn dependency:build-classpath -q -Dmdep.outputFile=/dev/stdout)" org.apache.flink.agents.examples.ReActAgentExample; cd ..
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.esotericsoftware.kryo.util.UnsafeUtil (file:/Users/ljiang/.m2/repository/com/esotericsoftware/kryo/kryo/2.24.0/kryo-2.24.0.jar) to constructor java.nio.DirectByteBuffer(long,int,java.lang.Object)
WARNING: Please consider reporting this to the maintainers of com.esotericsoftware.kryo.util.UnsafeUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
8> ProductReviewAnalysisRes{id='B009MA34NY', score=5, reasons=[good support, comfortable, lightweight, well-made, long lasting]}
4> ProductReviewAnalysisRes{id='B009MA34NY', score=5, reasons=[]}
1> ProductReviewAnalysisRes{id='B000YFSR5G', score=2, reasons=[did not fit well, not comfortable]}
5> ProductReviewAnalysisRes{id='B009MA34NY', score=5, reasons=[]}
7> ProductReviewAnalysisRes{id='B001IKJOLW', score=5, reasons=[]}
9> ProductReviewAnalysisRes{id='B000YFSR4W', score=5, reasons=[]}
6> ProductReviewAnalysisRes{id='B010RRWKT4', score=5, reasons=[]}
11> ProductReviewAnalysisRes{id='B000YFSR5G', score=5, reasons=[]}
10> ProductReviewAnalysisRes{id='B010RRWKT4', score=5, reasons=[comfortable]}
12> ProductReviewAnalysisRes{id='B014IBJKNO', score=5, reasons=[]}
3> ProductReviewAnalysisRes{id='B0092UF54A', score=5, reasons=[excellent product quality]}
8> ProductReviewAnalysisRes{id='B010RRWKT4', score=5, reasons=[]}
2> ProductReviewAnalysisRes{id='B000YFSR4W', score=1, reasons=[damaged product upon delivery]}
4> ProductReviewAnalysisRes{id='B000KPIHQ4', score=5, reasons=[]}
1> ProductReviewAnalysisRes{id='B0058YEJ5K', score=5, reasons=[comfortable]}
5> ProductReviewAnalysisRes{id='B005AGO4LU', score=5, reasons=[comfortable, great for weight training]}
7> ProductReviewAnalysisRes{id='B0058YEJ5K', score=2, reasons=[poor quality, overpriced]}

API

Documentation

@letaoj letaoj force-pushed the react-agent-example branch from 10ffbff to 43b5e39 Compare October 1, 2025 22:57
@letaoj
Copy link
Contributor Author

letaoj commented Oct 1, 2025

One thing that I'm not sure is whether the notifyShipping tools was called or not. At least, i'm not able to see it from the short period that I ran it.

@letaoj
Copy link
Contributor Author

letaoj commented Oct 1, 2025

@wenjin272 @xintongsong @Sxnan please take a look when you gets time.

@letaoj letaoj force-pushed the react-agent-example branch from 43b5e39 to 288f9f0 Compare October 2, 2025 21:16
Copy link
Collaborator

@wenjin272 wenjin272 left a comment

Choose a reason for hiding this comment

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

Hi, @letaoj, thanks for your work.

The tool is exactly called, but it fell into recursion.

"Notify the shipping manager when product received a negative review due to shipping damage.")
public static void notifyShippingManager(
@ToolParam(name = "id") String id, @ToolParam(name = "review") String review) {
notifyShippingManager(id, review);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should use org.apache.flink.agents.examples.agents.CustomTypesAndResources.notifyShippingManager( id, review); here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this. This is not an obvious bug. Is that possible to write this code in a different way so that I do not need to have this sort of redundent call in the ReAct agent?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe you can add @tool and @ToolParam directly on the notifyShippingManager method in CustomTypesAndResources, and register it in agents execution envrionment.

@letaoj letaoj force-pushed the react-agent-example branch from 288f9f0 to 8766f98 Compare October 6, 2025 06:35
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.

2 participants