Skip to content

Commit afef078

Browse files
committed
feat: allow setting max attempts for secretary from environment
And we can do this with other params in the future Signed-off-by: vsoch <vsoch@users.noreply.github.com>
1 parent ec50ad7 commit afef078

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ Each provider has a probe function that will return True/False if the provider e
7474

7575
This library will be used by agents and secretaries. You can also run it locally to detect or list providers.
7676

77+
### Settings
78+
79+
We currently expose the maximum number of attempts that each provider is allowed to make.
80+
81+
- `MCP_SERVER_SUBMIT_MAX_ATTEMPTS`: 10
82+
- `MCP_SERVER_NEGOTIATE_MAX_ATTEMPTS`: 10
83+
- `MCP_SERVER_SELECT_MAX_ATTEMPTS`: 10
7784

7885
### Providers
7986

resource_secretary/agents/secretary.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import os
23
import re
34
from typing import Any, Dict, List
45

@@ -30,6 +31,15 @@ def __init__(self, providers: List[Any] = None, verbose=False):
3031
self.calls = []
3132
self.provider_map = {p.name: p for p in self.providers}
3233
self.verbose = verbose
34+
self.settings_from_environment()
35+
36+
def settings_from_environment(self):
37+
"""
38+
Get max attempts from environment
39+
"""
40+
self.select_max_attempts = int(os.environ.get("MCP_SERVER_SELECT_MAX_ATTEMPTS") or 10)
41+
self.negotiate_max_attempts = int(os.environ.get("MCP_SERVER_NEGOTIATE_MAX_ATTEMPTS") or 10)
42+
self.submit_max_attempts = int(os.environ.get("MCP_SERVER_SUBMIT_MAX_ATTEMPTS") or 10)
3343

3444
def build_system_context(self, tool_types) -> str:
3545
"""
@@ -218,7 +228,9 @@ async def submit(self, request: str) -> str:
218228
"```"
219229
)
220230
# Require at least 2 calls - submit and info
221-
return await self.deliberate(f"EXECUTE REQUEST: {request}", instructions, 2)
231+
return await self.deliberate(
232+
f"EXECUTE REQUEST: {request}", instructions, 2, self.submit_max_attempts
233+
)
222234

223235
async def select(self, request: str, proposals: Dict[str, Any], metadata: str = None) -> str:
224236
"""
@@ -261,7 +273,7 @@ async def select(self, request: str, proposals: Dict[str, Any], metadata: str =
261273
f"ORIGINAL USER REQUEST: '{request}'\n\n"
262274
f"CLUSTER PROPOSALS TO EVALUATE:\n{json.dumps(proposals, indent=2)}"
263275
)
264-
return await self.deliberate(request, instructions)
276+
return await self.deliberate(request, instructions, max_attempts=self.select_max_attempts)
265277

266278
async def negotiate(self, request: str) -> str:
267279
"""
@@ -307,7 +319,7 @@ async def negotiate(self, request: str) -> str:
307319
"```"
308320
)
309321
# Require at least 1 call, and max 10 loops of thinking
310-
result = await self.deliberate(request, instructions, 1, 10)
322+
result = await self.deliberate(request, instructions, 1, self.negotiate_max_attempts)
311323

312324
# Max attempts reached
313325
if "TIMEOUT" in result:

0 commit comments

Comments
 (0)