You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -22,33 +22,162 @@ specific language governing permissions and limitations
22
22
under the License.
23
23
-->
24
24
25
+
## Overview
26
+
27
+
Flink Agents provides a flexible and extensible tool use mechanism. Developers can define the tool as a local Python function, or they can integrate with a remote MCP server to use the tools provided by the MCP server.
25
28
26
29
## Local Function as Tool
27
30
28
-
{{< hint warning >}}
29
-
**TODO**: How to define and use a Local Function as Tool.
31
+
Developer can define the tool as a local Python function, and there are two ways to define and register an local function as a tool:
32
+
33
+
{{< hint info >}}
34
+
Flink Agents uses the docstring of the tool function to generate the tool metadata. The docstring of the python function should accurately describe the tool's purpose, parameters, and return value, so that the LLM can understand the tool and use it effectively.
30
35
{{< /hint >}}
31
36
32
-
##How to Integrate with MCP Server
37
+
### Define Tool as Static Method in Agent Class
33
38
34
-
{{< hint warning >}}
35
-
**TODO**: How to integrate with MCP Server.
36
-
{{< /hint >}}
39
+
Developer can define the tool as a static method in the agent class while defining the workflow agent, and use the `@tool` annotation to mark the method as a tool. The tool can be referenced by its name in the `tools` list of the `ResourceDescriptor` when creating the chat model in the agent.
37
40
38
-
### MCP Tools
41
+
```python
42
+
classReviewAnalysisAgent(Agent):
39
43
40
-
{{< hint warning >}}
41
-
**TODO**: How to use the tools provided by MCP Server.
"""Notify the shipping manager when product received a negative review due to
48
+
shipping damage.
49
+
50
+
Parameters
51
+
----------
52
+
id : str
53
+
The id of the product that received a negative review due to shipping damage
54
+
review: str
55
+
The negative review content
56
+
"""
57
+
notify_shipping_manager(id=id, review=review)
58
+
59
+
@chat_model_setup
60
+
@staticmethod
61
+
defreview_analysis_model() -> ResourceDescriptor:
62
+
"""ChatModel which focus on review analysis."""
63
+
return ResourceDescriptor(
64
+
clazz=OllamaChatModelSetup,
65
+
...,
66
+
tools=["notify_shipping_manager"], # reference the tool by its name
67
+
)
68
+
69
+
...
70
+
```
71
+
72
+
**Key points:**
73
+
- Use `@tool` decorator to define the tool
74
+
- Reference the tool by its name in the `tools` list of the `ResourceDescriptor`
75
+
76
+
77
+
### Register Tool to Execution Environment
78
+
79
+
Developer can register the tool to the execution environment, and then reference the tool by its name. This allows the tool to be reused by multiple agents.
# Create react agent with notify shipping manager tool.
105
+
review_analysis_react_agent = ReActAgent(
106
+
chat_model=ResourceDescriptor(
107
+
clazz=OllamaChatModelSetup,
108
+
tools=["notify_shipping_manager"], # reference the tool by its name
109
+
),
110
+
...
111
+
)
112
+
```
45
113
46
-
{{< hint warning >}}
47
-
**TODO**: How to use the prompts provided by MCP Server.
114
+
**Key points:**
115
+
- Use `AgentsExecutionEnvironment.add_resource` to register the tool to the execution environment
116
+
- Reference the tool by its name in the `tools` list of the `ResourceDescriptor`
117
+
118
+
## MCP Tool
119
+
120
+
{{< hint info >}}
121
+
MCP (Model Context Protocol) is a standardized protocol for integrating AI applications with external data sources and tools. MCP tools allow dynamic tool retrieval from MCP servers.
48
122
{{< /hint >}}
49
123
50
-
## Built-in Events for Tool
124
+
MCP tools are managed by external MCP servers and automatically discovered when you define an MCP server connection in your agent.
125
+
126
+
### Define MCP Server with Tools
127
+
128
+
Create an MCP server that exposes tools using the `FastMCP` library:
0 commit comments