This is an automated email from the ASF dual-hosted git repository. wenjin272 pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/flink-agents.git
commit 9e2234dc26a80bdd8fbd5acd36e199fff6a0a312 Author: WenjinXie <[email protected]> AuthorDate: Tue Oct 20 11:14:34 2026 +0800 [docs][python] Correct Table input examples to use Row Describe Table input as Row, align example variable names, and exercise the prompt action with a real Row payload. Generated-by: Codex CLI 0.153.4 (GPT-6) Co-authored-by: Codex <[email protected]> --- .../quickstart/create-agent/multiple-agents.md | 18 ++++++++-------- .../agents/table_review_analysis_agent.py | 24 +++++++++++----------- .../quickstart/tests/test_prompt_driven_actions.py | 3 ++- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/docs/content/docs/get-started/quickstart/create-agent/multiple-agents.md b/docs/content/docs/get-started/quickstart/create-agent/multiple-agents.md index 0adecb9b9..49216fa83 100644 --- a/docs/content/docs/get-started/quickstart/create-agent/multiple-agents.md +++ b/docs/content/docs/get-started/quickstart/create-agent/multiple-agents.md @@ -159,7 +159,9 @@ The Java table declares only the `id` and `review` columns. ### Analyze Each Row with the Review Agent -A Table row reaches the Action as a `dict` in Python and a `Row` in Java. Build Your First Agent +A Table row reaches the Action as a `pyflink.common.Row` in Python and an +`org.apache.flink.types.Row` in Java. In Python, access fields with `row["id"]` or call +`row.as_dict()` when dictionary methods such as `.get()` are needed. Build Your First Agent gave its Agent a `ProductReview` object in Python and a JSON string in Java, so this example defines a second Agent class, `TableReviewAnalysisAgent`, for the row input. It redeclares the prompt, tool, and chat model setup that `ReviewAnalysisAgent` declares, and `ReviewAnalysisAgent` @@ -171,7 +173,7 @@ itself is unchanged. The key selector that reads `id` out of a row travels with {{< tab "Python" >}} ```python class TableKeySelector(KeySelector): - """KeySelector for extracting key from dictionary input (Table data).""" + """KeySelector for extracting the product id from a Table Row.""" def get_key(self, value: Any) -> str: if isinstance(value, dict): @@ -186,14 +188,14 @@ class TableReviewAnalysisAgent(Agent): @action(EventType.InputEvent) @staticmethod def process_input(event: Event, ctx: RunnerContext) -> None: - """Process input event from Table data (dictionary format). + """Process input event from Table data (Row format). - When using from_table(), the input is a dictionary with keys matching - the table column names. + When using from_table(), the input is a Row with fields matching + the table column names. Use row.as_dict() if a dictionary is needed. """ - input_dict = cast("InputEvent", event).input - product_id = str(input_dict["id"]) - review_text = str(input_dict["review"]) + input_row = cast("InputEvent", event).input + product_id = str(input_row["id"]) + review_text = str(input_row["review"]) # Rest of the body is the one Build Your First Agent shows. It keeps the id in # short-term memory and sends ChatRequestEvent. ... diff --git a/python/flink_agents/examples/quickstart/agents/table_review_analysis_agent.py b/python/flink_agents/examples/quickstart/agents/table_review_analysis_agent.py index 48ba0fa27..5f6c849bc 100644 --- a/python/flink_agents/examples/quickstart/agents/table_review_analysis_agent.py +++ b/python/flink_agents/examples/quickstart/agents/table_review_analysis_agent.py @@ -47,15 +47,15 @@ if TYPE_CHECKING: class TableKeySelector(KeySelector): - """KeySelector for extracting key from dictionary input (Table data).""" + """KeySelector for extracting the product id from a Table Row.""" def get_key(self, value: Any) -> str: - """Extract key from dictionary. + """Extract the product id from a Table Row or mapping. Parameters ---------- value : Any - The input value, expected to be a dictionary with 'id' key. + The input value, with an 'id' field. Returns: ------- @@ -72,11 +72,11 @@ class TableReviewAnalysisAgent(Agent): """An agent that analyzes product reviews from Flink Table input. This agent is designed to work with Flink Table API. It receives input as - dictionary (when using from_table()) and produces analysis results including - satisfaction score and reasons for dissatisfaction. + a pyflink.common.Row (when using from_table()) and produces analysis results + including satisfaction score and reasons for dissatisfaction. The main difference from ReviewAnalysisAgent is that this agent handles - dictionary input instead of Pydantic objects. + Row input instead of Pydantic objects. """ @prompt @@ -116,14 +116,14 @@ class TableReviewAnalysisAgent(Agent): @action(EventType.InputEvent) @staticmethod def process_input(event: Event, ctx: RunnerContext) -> None: - """Process input event from Table data (dictionary format). + """Process input event from Table data (Row format). - When using from_table(), the input is a dictionary with keys matching - the table column names. + When using from_table(), the input is a Row with fields matching + the table column names. Use row.as_dict() if a dictionary is needed. """ - input_dict = cast("InputEvent", event).input - product_id = str(input_dict["id"]) - review_text = str(input_dict["review"]) + input_row = cast("InputEvent", event).input + product_id = str(input_row["id"]) + review_text = str(input_row["review"]) ctx.short_term_memory.set("id", product_id) diff --git a/python/flink_agents/examples/quickstart/tests/test_prompt_driven_actions.py b/python/flink_agents/examples/quickstart/tests/test_prompt_driven_actions.py index 3218ddbe3..71dd23013 100644 --- a/python/flink_agents/examples/quickstart/tests/test_prompt_driven_actions.py +++ b/python/flink_agents/examples/quickstart/tests/test_prompt_driven_actions.py @@ -20,6 +20,7 @@ from unittest.mock import MagicMock import pytest +from pyflink.common import Row from flink_agents.api.chat_message import MessageRole from flink_agents.api.events.event import InputEvent @@ -38,7 +39,7 @@ from flink_agents.examples.quickstart.agents.table_review_analysis_agent import ("agent", "payload"), [ (ReviewAnalysisAgent, {"id": "product", "review": "damaged"}), - (TableReviewAnalysisAgent, {"id": "product", "review": "damaged"}), + (TableReviewAnalysisAgent, Row(id="product", review="damaged")), ( ProductSuggestionAgent, {"id": "product", "score_hist": ["1"], "unsatisfied_reasons": ["damaged"]},
