You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by sx...@apache.org on 2025/09/22 01:59:10 UTC
(flink-agents) branch main updated: [Feature] Remove the name field of Resource (#177)
This is an automated email from the ASF dual-hosted git repository.
sxnan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flink-agents.git
The following commit(s) were added to refs/heads/main by this push:
new 88e886d [Feature] Remove the name field of Resource (#177)
88e886d is described below
commit 88e886d275ec7ba1aeadd33bc9f44a480cc46924
Author: Eugene <me...@gmail.com>
AuthorDate: Mon Sep 22 09:59:04 2025 +0800
[Feature] Remove the name field of Resource (#177)
---
.../agents/plan/compatibility/CreateJavaAgentPlanFromJson.java | 1 -
python/flink_agents/api/agents/react_agent.py | 3 +--
python/flink_agents/api/prompts/prompt.py | 8 ++++----
python/flink_agents/api/resource.py | 3 ---
python/flink_agents/api/tests/mcp/test_mcp.py | 2 +-
python/flink_agents/api/tests/test_prompt.py | 5 ++---
python/flink_agents/api/tests/test_tool.py | 2 --
python/flink_agents/api/tools/mcp.py | 2 +-
python/flink_agents/api/tools/tool.py | 5 +++++
python/flink_agents/examples/chat_model_example.py | 6 ------
.../examples/integrate_table_with_react_agent_example.py | 1 -
.../examples/quickstart/agents/product_suggestion_agent.py | 1 -
.../examples/quickstart/agents/review_analysis_agent.py | 1 -
python/flink_agents/examples/react_agent_example.py | 1 -
python/flink_agents/plan/tests/tools/resources/function_tool.json | 1 -
python/flink_agents/runtime/tests/test_built_in_actions.py | 1 -
16 files changed, 14 insertions(+), 29 deletions(-)
diff --git a/plan/src/test/java/org/apache/flink/agents/plan/compatibility/CreateJavaAgentPlanFromJson.java b/plan/src/test/java/org/apache/flink/agents/plan/compatibility/CreateJavaAgentPlanFromJson.java
index 29e32df..2a9e365 100644
--- a/plan/src/test/java/org/apache/flink/agents/plan/compatibility/CreateJavaAgentPlanFromJson.java
+++ b/plan/src/test/java/org/apache/flink/agents/plan/compatibility/CreateJavaAgentPlanFromJson.java
@@ -134,7 +134,6 @@ public class CreateJavaAgentPlanFromJson {
kwargs);
Map<String, Object> serialized = new HashMap<>();
- serialized.put("name", "add");
// construct arguments schema
Map<String, String> a = new HashMap<>();
diff --git a/python/flink_agents/api/agents/react_agent.py b/python/flink_agents/api/agents/react_agent.py
index 63bb08a..825cc7e 100644
--- a/python/flink_agents/api/agents/react_agent.py
+++ b/python/flink_agents/api/agents/react_agent.py
@@ -115,7 +115,6 @@ class ReActAgent(Agent):
# prepare prompt
prompt = Prompt.from_messages(
- name="prompt",
messages=[
ChatMessage(
role=MessageRole.SYSTEM,
@@ -191,7 +190,7 @@ class ReActAgent(Agent):
raise TypeError(err_msg)
schema_prompt = f"The final response should be json format, and match the schema {json_schema}."
self._resources[ResourceType.PROMPT][_DEFAULT_SCHEMA_PROMPT] = (
- Prompt.from_text(name="output_schema", text=schema_prompt)
+ Prompt.from_text(text=schema_prompt)
)
if prompt:
diff --git a/python/flink_agents/api/prompts/prompt.py b/python/flink_agents/api/prompts/prompt.py
index a6b4bcf..37205d2 100644
--- a/python/flink_agents/api/prompts/prompt.py
+++ b/python/flink_agents/api/prompts/prompt.py
@@ -29,14 +29,14 @@ class Prompt(SerializableResource, ABC):
"""Base prompt abstract."""
@staticmethod
- def from_messages(name: str, messages: Sequence[ChatMessage]) -> "Prompt":
+ def from_messages(messages: Sequence[ChatMessage]) -> "Prompt":
"""Create prompt from sequence of ChatMessage."""
- return LocalPrompt(name=name, template=messages)
+ return LocalPrompt(template=messages)
@staticmethod
- def from_text(name: str, text: str) -> "Prompt":
+ def from_text(text: str) -> "Prompt":
"""Create prompt from text string."""
- return LocalPrompt(name=name, template=text)
+ return LocalPrompt(template=text)
@abstractmethod
def format_string(self, **kwargs: str) -> str:
diff --git a/python/flink_agents/api/resource.py b/python/flink_agents/api/resource.py
index d383aff..c07de2e 100644
--- a/python/flink_agents/api/resource.py
+++ b/python/flink_agents/api/resource.py
@@ -49,14 +49,11 @@ class Resource(BaseModel, ABC):
Attributes:
----------
- name : str
- The name of the resource.
get_resource : Callable[[str, ResourceType], "Resource"]
Get other resource object declared in the same Agent. The first argument is
resource name and the second argument is resource type.
"""
- name: str
get_resource: Callable[[str, ResourceType], "Resource"] = Field(
exclude=True, default=None
)
diff --git a/python/flink_agents/api/tests/mcp/test_mcp.py b/python/flink_agents/api/tests/mcp/test_mcp.py
index 893e309..80aecac 100644
--- a/python/flink_agents/api/tests/mcp/test_mcp.py
+++ b/python/flink_agents/api/tests/mcp/test_mcp.py
@@ -33,7 +33,7 @@ def test_mcp() -> None: # noqa : D103
process.start()
time.sleep(5)
- mcp_server = MCPServer(name="mcp_server", endpoint="http://127.0.0.1:8000/mcp")
+ mcp_server = MCPServer(endpoint="http://127.0.0.1:8000/mcp")
prompts = mcp_server.list_prompts()
assert len(prompts) == 1
prompt = prompts[0]
diff --git a/python/flink_agents/api/tests/test_prompt.py b/python/flink_agents/api/tests/test_prompt.py
index a3831b1..71ba075 100644
--- a/python/flink_agents/api/tests/test_prompt.py
+++ b/python/flink_agents/api/tests/test_prompt.py
@@ -29,7 +29,7 @@ def text_prompt() -> Prompt: # noqa: D103
"The product {product_id} is {description}, and user review is '{review}'."
)
- return Prompt.from_text(name="prompt", text=template)
+ return Prompt.from_text(text=template)
def test_prompt_from_text_to_string(text_prompt: LocalPrompt) -> None: # noqa: D103
@@ -75,7 +75,7 @@ def messages_prompt() -> Prompt: # noqa: D103
),
]
- return Prompt.from_messages(name="prompt", messages=template)
+ return Prompt.from_messages(messages=template)
def test_prompt_from_messages_to_string(messages_prompt: LocalPrompt) -> None: # noqa: D103
@@ -125,7 +125,6 @@ def test_prompt_lack_one_argument(text_prompt: LocalPrompt) -> None: # noqa: D1
def test_prompt_contain_json_schema() -> None: # noqa: D103
prompt = Prompt.from_text(
- name="prompt",
text=f"The json schema is {LocalPrompt.model_json_schema(mode='serialization')}",
)
prompt.format_string()
diff --git a/python/flink_agents/api/tests/test_tool.py b/python/flink_agents/api/tests/test_tool.py
index b06effd..1630833 100644
--- a/python/flink_agents/api/tests/test_tool.py
+++ b/python/flink_agents/api/tests/test_tool.py
@@ -130,7 +130,6 @@ def test_serialize_mcp_server() -> None: # noqa:D103
callback_handler=handle_callback,
)
mcp_server = MCPServer(
- name="mcp",
endpoint="http://localhost:8080",
auth=oauth_auth,
timeout=timedelta(seconds=5),
@@ -138,7 +137,6 @@ def test_serialize_mcp_server() -> None: # noqa:D103
data = mcp_server.model_dump_json(serialize_as_any=True)
deserialized = mcp_server.model_validate_json(data)
- assert deserialized.name == mcp_server.name
assert deserialized.endpoint == mcp_server.endpoint
assert deserialized.timeout == mcp_server.timeout
assert deserialized.auth.context.server_url == mcp_server.auth.context.server_url
diff --git a/python/flink_agents/api/tools/mcp.py b/python/flink_agents/api/tools/mcp.py
index 47983fa..147a3c4 100644
--- a/python/flink_agents/api/tools/mcp.py
+++ b/python/flink_agents/api/tools/mcp.py
@@ -74,6 +74,7 @@ class MCPPrompt(Prompt):
This represents a prompt managed by an MCP server.
"""
+ name: str
title: str | None
description: str | None = None
prompt_arguments: list[PromptArgument] = Field(default_factory=list)
@@ -228,7 +229,6 @@ class MCPServer(SerializableResource, ABC):
)
tool = MCPTool(
- name=tool_data.name,
metadata=metadata,
mcp_server=self,
)
diff --git a/python/flink_agents/api/tools/tool.py b/python/flink_agents/api/tools/tool.py
index d48b7a7..a410ec2 100644
--- a/python/flink_agents/api/tools/tool.py
+++ b/python/flink_agents/api/tools/tool.py
@@ -111,6 +111,11 @@ class BaseTool(SerializableResource, ABC):
metadata: ToolMetadata
+ @property
+ def name(self) -> str:
+ """Get the name of the tool."""
+ return self.metadata.name
+
@classmethod
@override
def resource_type(cls) -> ResourceType:
diff --git a/python/flink_agents/examples/chat_model_example.py b/python/flink_agents/examples/chat_model_example.py
index a46b2b0..04b2f7b 100644
--- a/python/flink_agents/examples/chat_model_example.py
+++ b/python/flink_agents/examples/chat_model_example.py
@@ -61,7 +61,6 @@ class MyAgent(Agent):
msg = "Please set the 'DASHSCOPE_API_KEY' environment variable."
raise ValueError(msg)
return TongyiChatModelConnection, {
- "name": "tongyi_connection",
"model": TONGYI_MODEL,
}
@@ -70,7 +69,6 @@ class MyAgent(Agent):
def ollama_connection() -> Tuple[Type[BaseChatModelConnection], Dict[str, Any]]:
"""ChatModelConnection responsible for ollama model service connection."""
return OllamaChatModelConnection, {
- "name": "ollama_connection",
"model": OLLAMA_MODEL,
}
@@ -80,13 +78,11 @@ class MyAgent(Agent):
"""ChatModel which focus on math, and reuse ChatModelConnection."""
if CURRENT_BACKEND == "Tongyi":
return TongyiChatModelSetup, {
- "name": "math_chat_model",
"connection": "tongyi_connection",
"tools": ["add"],
}
else:
return OllamaChatModelSetup, {
- "name": "math_chat_model",
"connection": "ollama_connection",
"tools": ["add"],
"extract_reasoning": True,
@@ -98,12 +94,10 @@ class MyAgent(Agent):
"""ChatModel which focus on text generate, and reuse ChatModelConnection."""
if CURRENT_BACKEND == "Tongyi":
return TongyiChatModelSetup, {
- "name": "creative_chat_model",
"connection": "tongyi_connection",
}
else:
return OllamaChatModelSetup, {
- "name": "creative_chat_model",
"connection": "ollama_connection",
"extract_reasoning": True,
}
diff --git a/python/flink_agents/examples/integrate_table_with_react_agent_example.py b/python/flink_agents/examples/integrate_table_with_react_agent_example.py
index 1467b4f..1c5ae43 100644
--- a/python/flink_agents/examples/integrate_table_with_react_agent_example.py
+++ b/python/flink_agents/examples/integrate_table_with_react_agent_example.py
@@ -94,7 +94,6 @@ if __name__ == "__main__":
# prepare prompt
prompt = Prompt.from_messages(
- name="prompt",
messages=[
ChatMessage(
role=MessageRole.SYSTEM,
diff --git a/python/flink_agents/examples/quickstart/agents/product_suggestion_agent.py b/python/flink_agents/examples/quickstart/agents/product_suggestion_agent.py
index cba5050..8d9b072 100644
--- a/python/flink_agents/examples/quickstart/agents/product_suggestion_agent.py
+++ b/python/flink_agents/examples/quickstart/agents/product_suggestion_agent.py
@@ -115,7 +115,6 @@ class ProductSuggestionAgent(Agent):
def generate_suggestion_model() -> Tuple[Type[BaseChatModelSetup], Dict[str, Any]]:
"""ChatModel which focus on generating product suggestions."""
return OllamaChatModelSetup, {
- "name": "generate_suggestion_model",
"connection": "ollama_server",
"prompt": "generate_suggestion_prompt",
"extract_reasoning": True,
diff --git a/python/flink_agents/examples/quickstart/agents/review_analysis_agent.py b/python/flink_agents/examples/quickstart/agents/review_analysis_agent.py
index 410f144..e3bbde5 100644
--- a/python/flink_agents/examples/quickstart/agents/review_analysis_agent.py
+++ b/python/flink_agents/examples/quickstart/agents/review_analysis_agent.py
@@ -114,7 +114,6 @@ class ReviewAnalysisAgent(Agent):
def review_analysis_model() -> Tuple[Type[BaseChatModelSetup], Dict[str, Any]]:
"""ChatModel which focus on review analysis."""
return OllamaChatModelSetup, {
- "name": "review_analysis_model",
"connection": "ollama_server",
"prompt": "review_analysis_prompt",
"extract_reasoning": True,
diff --git a/python/flink_agents/examples/react_agent_example.py b/python/flink_agents/examples/react_agent_example.py
index 7c603c7..862ca20 100644
--- a/python/flink_agents/examples/react_agent_example.py
+++ b/python/flink_agents/examples/react_agent_example.py
@@ -56,7 +56,6 @@ if __name__ == "__main__":
# prepare prompt
prompt = Prompt.from_messages(
- name="prompt",
messages=[
ChatMessage(
role=MessageRole.SYSTEM,
diff --git a/python/flink_agents/plan/tests/tools/resources/function_tool.json b/python/flink_agents/plan/tests/tools/resources/function_tool.json
index 52aee0d..50dd0e9 100644
--- a/python/flink_agents/plan/tests/tools/resources/function_tool.json
+++ b/python/flink_agents/plan/tests/tools/resources/function_tool.json
@@ -1,5 +1,4 @@
{
- "name": "foo",
"metadata": {
"name": "foo",
"description": "Function for testing ToolMetadata.\n",
diff --git a/python/flink_agents/runtime/tests/test_built_in_actions.py b/python/flink_agents/runtime/tests/test_built_in_actions.py
index 7a499e7..b0d0095 100644
--- a/python/flink_agents/runtime/tests/test_built_in_actions.py
+++ b/python/flink_agents/runtime/tests/test_built_in_actions.py
@@ -117,7 +117,6 @@ class MyAgent(Agent):
def prompt() -> Prompt:
"""Prompt can be used in action or chat model."""
return Prompt.from_text(
- name="prompt",
text="Please call the appropriate tool to do the following task: {task}",
)