From f2c78b701ef88a1b6a220d0adb48630e31c4e40d Mon Sep 17 00:00:00 2001 From: cybermaggedon Date: Tue, 19 Nov 2024 21:28:47 +0000 Subject: [PATCH] - Increased max-iterations to 15 default, and made it a configurable (#163) parameter with --max-iterations. Was previously hard-coded at 10. - Fixed arg passing causing pull the wrong tool name --- .../trustgraph/agent/react/service.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/trustgraph-flow/trustgraph/agent/react/service.py b/trustgraph-flow/trustgraph/agent/react/service.py index f367d10f..8799816b 100755 --- a/trustgraph-flow/trustgraph/agent/react/service.py +++ b/trustgraph-flow/trustgraph/agent/react/service.py @@ -32,6 +32,7 @@ module = ".".join(__name__.split(".")[1:-1]) default_input_queue = agent_request_queue default_output_queue = agent_response_queue default_subscriber = module +default_max_iterations = 15 class Processor(ConsumerProducer): @@ -39,6 +40,8 @@ class Processor(ConsumerProducer): additional = params.get("context", None) + self.max_iterations = int(params.get("max_iterations", default_max_iterations)) + tools = {} # Parsing the prompt information to the prompt configuration @@ -67,8 +70,9 @@ class Processor(ConsumerProducer): ) if len(ttoks) == 1: + tools[toks[0]] = Tool( - name = ttoks[0], + name = toks[0], description = "", implementation = impl, config = { "input": "query" }, @@ -76,7 +80,7 @@ class Processor(ConsumerProducer): ) else: tools[toks[0]] = Tool( - name = ttoks[0], + name = toks[0], description = "", implementation = impl, config = { "input": ttoks[1] }, @@ -226,7 +230,7 @@ class Processor(ConsumerProducer): print(f"Question: {v.question}", flush=True) - if len(history) > 10: + if len(history) >= self.max_iterations: raise RuntimeError("Too many agent iterations") print(f"History: {history}", flush=True) @@ -394,6 +398,12 @@ description.''' help=f'Optional, specifies additional context text for the LLM.' ) + parser.add_argument( + '--max-iterations', + default=default_max_iterations, + help=f'Maximum number of react iterations (default: {default_max_iterations})', + ) + def run(): Processor.start(module, __doc__)