-
Notifications
You must be signed in to change notification settings - Fork 49
feat: add MCP retry policy to Agent Spec #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -986,6 +986,7 @@ the correct built-in tool. | |
|
|
||
| class MCPTool(Tool): | ||
| client_transport: ClientTransport | ||
| retry_policy: Optional[RetryPolicy] | ||
|
|
||
| class BuiltinTool(Tool): | ||
| tool_type: str | ||
|
|
@@ -1059,11 +1060,17 @@ with mTLS) (details about the client transport can be found in | |
|
|
||
| class MCPTool(Tool): | ||
| client_transport: ClientTransport | ||
| retry_policy: Optional[RetryPolicy] | ||
|
|
||
| MCP Tools follow the same security principles as other tools: no arbitrary code is | ||
| embedded in the representation. Execution occurs remotely via the specified transport, with the | ||
| runtime handling session management and data relay. | ||
|
|
||
| ``retry_policy`` optionally specifies a ``RetryPolicy`` for direct MCP tool | ||
| resolution and execution. This is distinct from retry policies on remote MCP | ||
| transports, which apply to requests sent through the transport layer. Runtime | ||
| implementations decide which MCP resolution and execution failures are retryable. | ||
|
|
||
| For example, an MCP Tool might use an ``SSEmTLSTransport`` to securely call a remote | ||
| function for data processing. | ||
|
|
||
|
|
@@ -1104,12 +1111,20 @@ from that server to components. | |
|
|
||
| class MCPToolBox(ToolBox): | ||
| client_transport: ClientTransport | ||
| retry_policy: Optional[RetryPolicy] | ||
| tool_filter: Optional[List[Union[str, MCPToolSpec]]] | ||
|
|
||
|
|
||
| The ``client_transport`` specifies the MCP ClientTransport used to discover remote | ||
| MCP tools and route calls to them. | ||
|
|
||
| ``retry_policy`` optionally specifies a ``RetryPolicy`` for MCP toolbox | ||
| discovery/resolution and for the execution of tools generated by the toolbox. | ||
| This is distinct from retry policies on remote MCP transports, which apply to | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure about what does this involve (same for the equivalent paragraph in I think we need to be more clear on what this applies to, as we say "it's not the same as this other thing", but I feel like we don't say what it is. Also, whenever there's a "Runtime implementations decide ..." we are giving up on cross-framework consistency at spec level. I think we need to say what it should apply to, and if runtimes don't support it, that's on the runtime adapter. |
||
| requests sent through the transport layer. Runtime implementations decide which | ||
| MCP toolbox discovery, resolution, and generated-tool execution failures are | ||
| retryable. | ||
|
|
||
| .. _mcp_toolfilter_rules: | ||
|
|
||
| By default the ``tool_filter`` parameter is null and the MCPToolBox exposes all tools | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,6 +86,7 @@ def start_mcp_server() -> str: | |
| # .. start-##_Imports_for_this_guide | ||
|
|
||
| from pyagentspec.agent import Agent | ||
| from pyagentspec import RetryPolicy | ||
| from pyagentspec.flows.edges import ControlFlowEdge, DataFlowEdge | ||
| from pyagentspec.flows.flow import Flow | ||
| from pyagentspec.flows.nodes import EndNode, StartNode, ToolNode | ||
|
|
@@ -108,6 +109,23 @@ def start_mcp_server() -> str: | |
| mcp_client_with_oauth = SSETransport(name="MCP Client", url=mcp_server_url, auth=oauth) | ||
| # .. end-##_OAuth_in_MCP_Tools | ||
|
|
||
| # .. start-##_MCP_Retry_Policy | ||
| mcp_client_for_retry = SSETransport( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we have an example with both the retry on the transport and the retry on the MCP tool? |
||
| name="MCP Client", | ||
| url=mcp_server_url, | ||
| ) | ||
| mcp_toolbox_with_retry = MCPToolBox( | ||
| name="Payslip MCP ToolBox", | ||
| client_transport=mcp_client_for_retry, | ||
| tool_filter=["get_user_session", "get_payslips"], | ||
| retry_policy=RetryPolicy( | ||
| max_attempts=3, | ||
| initial_retry_delay=0.25, | ||
| max_retry_delay=2.0, | ||
| ), | ||
| ) | ||
| # .. end-##_MCP_Retry_Policy | ||
|
|
||
| # .. start-##_Connecting_an_agent_to_the_MCP_server | ||
| mcp_client = SSETransport(name="MCP Client", url=mcp_server_url) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could explain more clearly what "resolution" and "execution" mean