From 2db7e12a9b8215cd684d77537d754e0a77067961 Mon Sep 17 00:00:00 2001 From: Pavan Kumar <66913595+ascender1729@users.noreply.github.com> Date: Fri, 18 Apr 2025 15:34:17 +0000 Subject: [PATCH] Assistant checkpoint: Update agent task handling to be more specialized Assistant generated file changes: - examples/mcp_example/mock_multi_agent.py: Update agent processing logic to handle only relevant tasks, Update results display to only show relevant responses --- User prompt: im facing the issue that whaen i send the agetn one speroce task it is send to tbothe agetn tand both the gets ater retuneitnthe the answers and udpate ti fix this and udpate it only it shoudl be repsonced by the rools or agetreas which is relvent to them Replit-Commit-Author: Assistant Replit-Commit-Session-Id: fb95cfda-0201-499a-811b-4d56364a96ec --- examples/mcp_example/mock_multi_agent.py | 34 ++++++++++++++++++------ 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/examples/mcp_example/mock_multi_agent.py b/examples/mcp_example/mock_multi_agent.py index 2fd5f278..9462674b 100644 --- a/examples/mcp_example/mock_multi_agent.py +++ b/examples/mcp_example/mock_multi_agent.py @@ -23,6 +23,15 @@ class MathAgent: max_tokens=1000 ) + def is_relevant_task(self, task: str) -> bool: + task_lower = task.lower() + if self.agent.agent_name == "Calculator": + math_keywords = ['add', 'plus', '+', 'multiply', 'times', '*', 'x', 'divide', '/', 'by'] + return any(keyword in task_lower for keyword in math_keywords) + else: # StockAnalyst + stock_keywords = ['moving average', 'stock', 'market', 'percentage', 'change'] + return any(keyword in task_lower for keyword in stock_keywords) + async def process(self, task: str): try: # Check if asking about capabilities @@ -39,6 +48,14 @@ class MathAgent: "task": task, "response": "I can analyze stock data using moving averages and calculate percentage changes. For example: 'calculate moving average of [10,20,30,40,50] over 3 periods'" } + + # Only process if task is relevant to this agent + if not self.is_relevant_task(task): + return { + "agent": self.agent.agent_name, + "task": task, + "response": None # Indicate this agent should not handle this task + } # Check if input is stock-related (for StockAnalyst) if self.agent.agent_name == "StockAnalyst" and "moving average" in task.lower(): @@ -124,14 +141,15 @@ class MultiAgentMathSystem: print("Results:") print("="*50) for result in results: - if "error" in result: - print(f"\n[{result['agent']}]") - print("-"*50) - print(f"Error: {result['error']}") - else: - print(f"\n[{result['agent']}]") - print("-"*50) - print(f"{result['response']}") + if result["response"] is not None: # Only show responses from relevant agents + if "error" in result: + print(f"\n[{result['agent']}]") + print("-"*50) + print(f"Error: {result['error']}") + else: + print(f"\n[{result['agent']}]") + print("-"*50) + print(f"{result['response']}") print("\n" + "="*50) except Exception as e: