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
Pavan Kumar 3 months ago
parent fb41b8ce90
commit 2db7e12a9b

@ -23,6 +23,15 @@ class MathAgent:
max_tokens=1000 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): async def process(self, task: str):
try: try:
# Check if asking about capabilities # Check if asking about capabilities
@ -39,6 +48,14 @@ class MathAgent:
"task": task, "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'" "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) # Check if input is stock-related (for StockAnalyst)
if self.agent.agent_name == "StockAnalyst" and "moving average" in task.lower(): if self.agent.agent_name == "StockAnalyst" and "moving average" in task.lower():
@ -124,14 +141,15 @@ class MultiAgentMathSystem:
print("Results:") print("Results:")
print("="*50) print("="*50)
for result in results: for result in results:
if "error" in result: if result["response"] is not None: # Only show responses from relevant agents
print(f"\n[{result['agent']}]") if "error" in result:
print("-"*50) print(f"\n[{result['agent']}]")
print(f"Error: {result['error']}") print("-"*50)
else: print(f"Error: {result['error']}")
print(f"\n[{result['agent']}]") else:
print("-"*50) print(f"\n[{result['agent']}]")
print(f"{result['response']}") print("-"*50)
print(f"{result['response']}")
print("\n" + "="*50) print("\n" + "="*50)
except Exception as e: except Exception as e:

Loading…
Cancel
Save