You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "wenjin272 (via GitHub)" <gi...@apache.org> on 2025/09/29 09:30:25 UTC

[PR] [docs] Update react agent development doc. [flink-agents]

wenjin272 opened a new pull request, #236:
URL: https://github.com/apache/flink-agents/pull/236

   <!--
   * Thank you very much for contributing to Flink Agents.
   * Please add the relevant components in the PR title. E.g., [api], [runtime], [java], [python], [hotfix], etc.
   -->
   
   <!-- Please link the PR to the relevant issue(s). Hotfix doesn't need this. -->
   Linked issue: #201 
   
   ### Purpose of change
   
   Update react agent development doc.
   
   ### Tests
   
   No
   
   ### API
   
   No
   
   ### Documentation
   
   Yes
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [docs] Update react agent development doc. [flink-agents]

Posted by "wenjin272 (via GitHub)" <gi...@apache.org>.
wenjin272 commented on PR #236:
URL: https://github.com/apache/flink-agents/pull/236#issuecomment-3351029144

   @xintongsong , sorry I didn't check carefully before submitting this PR. I have updated it according to your comments.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [docs] Update react agent development doc. [flink-agents]

Posted by "xintongsong (via GitHub)" <gi...@apache.org>.
xintongsong commented on code in PR #236:
URL: https://github.com/apache/flink-agents/pull/236#discussion_r2387965559


##########
docs/content/docs/development/react_agent.md:
##########
@@ -24,12 +24,99 @@ under the License.
 
 ## Overview
 
-{{< hint warning >}}
-**TODO**: What is ReAct agent. When to use it.
-{{< /hint >}}
+ReAct Agent is a general paradigm that combines reasoning and action capabilities to solve complex tasks. Leveraging this paradigm, the user only needs to specify the goal with prompt and provide available tools, and the LLM will decide how to achieve the goal and take actions autonomously
 
 ## ReAct Agent Example
 
-{{< hint warning >}}
-**TODO**: Add the quickstart example code here. And briefly explain the code component by component. Link to the detailed documentation for each component, such as ChatModel, Prompt, Tool, etc.
-{{< /hint >}}
+```python
+review_analysis_react_agent = ReActAgent(
+    chat_model=chat_model,
+    prompt=review_analysis_react_prompt,
+    output_schema=ProductReviewAnalysisRes,
+)

Review Comment:
   ```suggestion
   review_analysis_react_agent = ReActAgent(
       chat_model=chat_model_descriptor,
       prompt=review_analysis_react_prompt,
       output_schema=ProductReviewAnalysisRes,
   )
   ```



##########
docs/content/docs/development/react_agent.md:
##########
@@ -24,12 +24,99 @@ under the License.
 
 ## Overview
 
-{{< hint warning >}}
-**TODO**: What is ReAct agent. When to use it.
-{{< /hint >}}
+ReAct Agent is a general paradigm that combines reasoning and action capabilities to solve complex tasks. Leveraging this paradigm, the user only needs to specify the goal with prompt and provide available tools, and the LLM will decide how to achieve the goal and take actions autonomously
 
 ## ReAct Agent Example
 
-{{< hint warning >}}
-**TODO**: Add the quickstart example code here. And briefly explain the code component by component. Link to the detailed documentation for each component, such as ChatModel, Prompt, Tool, etc.
-{{< /hint >}}
+```python
+review_analysis_react_agent = ReActAgent(
+    chat_model=chat_model,
+    prompt=review_analysis_react_prompt,
+    output_schema=ProductReviewAnalysisRes,
+)
+```
+## Initialize Arguments
+### Chat Model
+User should specify the chat model used in the ReAct Agent.
+
+We use `ResourceDescriptor` to describe the chat model, includes chat model type and chat model arguments. See [Chat Model]({{< ref "docs/development/chat_with_llm#chatmodel" >}}) for more details.
+```python
+chat_model = ResourceDescriptor(
+    clazz=OllamaChatModelSetup,
+    connection="ollama_server",
+    model="qwen3:8b",
+    tools=["notify_shipping_manager"],
+)
+```
+
+### Prompt
+User can provide prompt to instruct agent. 
+
+Here we create a prompt contains two messages. The first message tells the agent what to do, and gives the input and output example. The second message tells how to convert input element to text string.
+```python
+review_analysis_system_prompt_str = """
+    Analyze the user review and product information to determine a
+    satisfaction score (1-5) and potential reasons for dissatisfaction.
+
+    Example input format:
+    {{
+        "id": "12345",
+        "review": "The headphones broke after one week of use. Very poor quality."
+    }}
+
+    Ensure your response can be parsed by Python JSON, using this format as an example:
+    {{
+     "id": "12345",
+     "score": 1,
+     "reasons": [
+       "poor quality"
+       ]
+    }}
+
+    Please note that if a product review includes dissatisfaction with the shipping process,
+    you should first notify the shipping manager using the appropriate tools. After executing
+    the tools, strictly follow the example above to provide your score and reason — there is
+    no need to disclose whether the tool was used.
+    """
+    
+# Prompt for review analysis react agent.
+review_analysis_react_prompt = Prompt.from_messages(
+    messages=[
+        ChatMessage(
+            role=MessageRole.SYSTEM,
+            content=review_analysis_system_prompt_str,
+        ),
+        # For react agent, if the input element is not primitive types,
+        # framework will deserialize input element to dict and fill the prompt.
+        # Note, the input element should be primitive types, BaseModel or Row.
+        ChatMessage(
+            role=MessageRole.USER,
+            content="""
+            "id": {id},
+            "review": {review}
+            """,
+        ),
+    ],
+) 
+
+```
+If the input element is primitive types, like `int`, `str` and so on, the second message should be
+```python
+ChatMessage(
+    role=MessageRole.USER,
+    content="{input}"
+)
+```
+
+See [Prompt]({{< ref "docs/development/chat_with_llm#prompt" >}}) for more details.
+
+### Output Schema
+User can set output schema to configure the ReAct Agent output type. If output schema is set, the ReAct Agent will deserialize the llm response to expected type. 
+
+The output schema should be `BaseModel` or `RowTypeInfo`.

Review Comment:
   Can we also give an example about the row type?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [docs] Update react agent development doc. [flink-agents]

Posted by "xintongsong (via GitHub)" <gi...@apache.org>.
xintongsong commented on code in PR #236:
URL: https://github.com/apache/flink-agents/pull/236#discussion_r2390495116


##########
docs/content/docs/development/react_agent.md:
##########
@@ -24,12 +24,92 @@ under the License.
 
 ## Overview
 
-{{< hint warning >}}
-**TODO**: What is ReAct agent. When to use it.
-{{< /hint >}}
+ReAct Agent is a general paradigm that combines reasoning and action capabilities to solve complex tasks. Leveraging this paradigm, the user only needs to specify the goal with prompt and provide available tools, and the LLM will decide how to achieve the goal and take actions autonomously
 
 ## ReAct Agent Example
 
-{{< hint warning >}}
-**TODO**: Add the quickstart example code here. And briefly explain the code component by component. Link to the detailed documentation for each component, such as ChatModel, Prompt, Tool, etc.
-{{< /hint >}}
+```python
+review_analysis_react_agent = ReActAgent(
+    chat_model=chat_model_descriptor,
+    prompt=my_prompt,
+    output_schema=MyBaseModelDataType,
+)
+```
+## Initialize Arguments
+### Chat Model
+User should specify the chat model used in the ReAct Agent.
+
+We use `ResourceDescriptor` to describe the chat model, includes chat model type and chat model arguments. See [Chat Model]({{< ref "docs/development/chat_with_llm#chatmodel" >}}) for more details.
+```python
+chat_model = ResourceDescriptor(

Review Comment:
   ```suggestion
   chat_model_descriptor = ResourceDescriptor(
   ```



##########
docs/content/docs/development/react_agent.md:
##########
@@ -24,12 +24,92 @@ under the License.
 
 ## Overview
 
-{{< hint warning >}}
-**TODO**: What is ReAct agent. When to use it.
-{{< /hint >}}
+ReAct Agent is a general paradigm that combines reasoning and action capabilities to solve complex tasks. Leveraging this paradigm, the user only needs to specify the goal with prompt and provide available tools, and the LLM will decide how to achieve the goal and take actions autonomously
 
 ## ReAct Agent Example
 
-{{< hint warning >}}
-**TODO**: Add the quickstart example code here. And briefly explain the code component by component. Link to the detailed documentation for each component, such as ChatModel, Prompt, Tool, etc.
-{{< /hint >}}
+```python
+review_analysis_react_agent = ReActAgent(
+    chat_model=chat_model_descriptor,
+    prompt=my_prompt,
+    output_schema=MyBaseModelDataType,

Review Comment:
   ```suggestion
       output_schema=MyBaseModelDataType, # or output_schema=my_row_type_info
   ```



##########
docs/content/docs/development/react_agent.md:
##########
@@ -24,12 +24,92 @@ under the License.
 
 ## Overview
 
-{{< hint warning >}}
-**TODO**: What is ReAct agent. When to use it.
-{{< /hint >}}
+ReAct Agent is a general paradigm that combines reasoning and action capabilities to solve complex tasks. Leveraging this paradigm, the user only needs to specify the goal with prompt and provide available tools, and the LLM will decide how to achieve the goal and take actions autonomously
 
 ## ReAct Agent Example
 
-{{< hint warning >}}
-**TODO**: Add the quickstart example code here. And briefly explain the code component by component. Link to the detailed documentation for each component, such as ChatModel, Prompt, Tool, etc.
-{{< /hint >}}
+```python
+review_analysis_react_agent = ReActAgent(

Review Comment:
   It's still called `review_analysis_react_agent`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [docs] Update react agent development doc. [flink-agents]

Posted by "xintongsong (via GitHub)" <gi...@apache.org>.
xintongsong merged PR #236:
URL: https://github.com/apache/flink-agents/pull/236


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org