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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to