awslabs/multi-agent-orchestrator

Bug:I keep getting error when trying to call the route_request

Closed this issue · 0 comments

Expected Behaviour

I expect current date as output from the agent.

Current Behaviour

currently it fails giving this error
[2024-12-07 21:54:07,067: INFO/MainProcess] Task test_task[1b7e4950-7c2a-4ec1-9d13-629eff8822fb] received
[2024-12-07 21:54:14,063: INFO/ForkPoolWorker-1]
** CLASSIFIED INTENT **
[2024-12-07 21:54:14,064: INFO/ForkPoolWorker-1] =======================
[2024-12-07 21:54:14,064: INFO/ForkPoolWorker-1] > Text: What is the current date?
[2024-12-07 21:54:14,064: INFO/ForkPoolWorker-1] > Selected Agent: Date Operation Agent
[2024-12-07 21:54:14,064: INFO/ForkPoolWorker-1] > Confidence: 0.90
[2024-12-07 21:54:14,064: INFO/ForkPoolWorker-1]
[2024-12-07 21:54:14,064: INFO/ForkPoolWorker-1]
** AGENT DATE-OPERATION-AGENT CHAT HISTORY **
[2024-12-07 21:54:14,065: INFO/ForkPoolWorker-1] =============================================
[2024-12-07 21:54:14,065: INFO/ForkPoolWorker-1] > - None -
[2024-12-07 21:54:14,065: INFO/ForkPoolWorker-1]
[2024-12-07 21:54:15,342: ERROR/ForkPoolWorker-1] Error during agent processing: object ConversationMessage can't be used in 'await' expression
[2024-12-07 21:54:15,342: INFO/ForkPoolWorker-1]
** EXECUTION TIMES **
[2024-12-07 21:54:15,342: INFO/ForkPoolWorker-1] =====================
[2024-12-07 21:54:15,342: INFO/ForkPoolWorker-1] > Classifying user intent: 6.776050567626953s
[2024-12-07 21:54:15,342: INFO/ForkPoolWorker-1] > Agent Date Operation Agent | Processing request: 1.277111291885376s
[2024-12-07 21:54:15,342: INFO/ForkPoolWorker-1]
[2024-12-07 21:54:15,349: INFO/ForkPoolWorker-1] Task test_task[1b7e4950-7c2a-4ec1-9d13-629eff8822fb] succeeded in 8.280865754000843s: 'An error occurred while processing your request. Please try again later.'

Code snippet

options=OrchestratorConfig(
    LOG_AGENT_CHAT=True,
    LOG_CLASSIFIER_CHAT=True,
    LOG_CLASSIFIER_RAW_OUTPUT=True,
    LOG_CLASSIFIER_OUTPUT=True,
    LOG_EXECUTION_TIMES=True,
    MAX_RETRIES=3,
    MAX_MESSAGE_PAIRS_PER_AGENT=50,
    USE_DEFAULT_AGENT_IF_NONE_IDENTIFIED=True,
    CLASSIFICATION_ERROR_MESSAGE="Oops! We couldn't process your request. Please try again.",
    NO_SELECTED_AGENT_MESSAGE="I'm sorry, I couldn't determine how to handle your request. Could you please rephrase it?",
    GENERAL_ROUTING_ERROR_MSG_MESSAGE="An error occurred while processing your request. Please try again later.",
)


class OrchestratorService:
    def __init__(self):
        self.orchestrator = MultiAgentOrchestrator(
            options=options,
            classifier=bedrock_classifier,
            default_agent=chit_chat_agent,
        )
    def add_agent(self, agent):
        return self.orchestrator.add_agent(agent)
    
    def route_request(self,user_input: str, user_id: str, session_id: str, additional_params: Dict[str, str] = {}):
        return self.orchestrator.route_request(user_input, user_id, session_id, additional_params)
    
    def set_default_agent(self, agent):
        return self.orchestrator.set_default_agent(agent)





@shared_task(bind=True, name="test_task", queue=high_fifo_queue, max_retries=3)
def test_task(self):
    log(level=INFO, function="test_task", message="Test task executed")
    from services.multi_agent_orchestrator.orchestrator.orchestrator_service import OrchestratorService
    from services.multi_agent_orchestrator.agents.arithmetic_agent import arithmetic_operation_agent
    from services.multi_agent_orchestrator.agents.date_operation_agent import date_operation_agent


    orchestrator = OrchestratorService()
    orchestrator.add_agent(arithmetic_operation_agent)
    orchestrator.add_agent(date_operation_agent)

    user_input = "What is the current date?"
    user_id = "123456789"
    session_id = "987654321"

    response = asyncio.run(orchestrator.route_request(user_input, user_id, session_id))
    return response.output


options = BedrockLLMAgentOptions(
    client=BedrockClientSingleton(),
    region='ap-south-1',
    name='Arithmetic Agent',
    description='An AI agent that can perform arithmetic operations.',
    model_id='anthropic.claude-3-sonnet-20240229-v1:0',
    streaming=False,
    inference_config={
        'maxTokens': 1000,
        'temperature': 0.7,
        'topP': 0.9,
        'stopSequences': ['Human:', 'AI:']
    },
    tool_config={
        'tool': arithmetic_tool,
        'toolMaxRecursions': 5,
        'useToolHandler': arithmetic_tool_handler.handle
    },
    custom_system_prompt={
        "template": aritmetic_agent_prompt,
        "variables": {}
    }
)

arithmetic_operation_agent = BedrockLLMAgent(options)


options = BedrockLLMAgentOptions(
    client=BedrockClientSingleton(),
    region='ap-south-1',
    name='Date Operation Agent',
    description='An AI agent that can perform date operations.',
    model_id='anthropic.claude-3-sonnet-20240229-v1:0',
    streaming=False,
    inference_config={
        'maxTokens': 1000,
        'temperature': 0.7,
        'topP': 0.9,
        'stopSequences': ['Human:', 'AI:']
    },
    tool_config={
        'tool': date_operation_tool,
        'toolMaxRecursions': 5,
        'useToolHandler': arithmetic_tool_handler.handle
    },
    custom_system_prompt={
        "template": date_operation_agent_prompt,
        "variables": {}
    }
)

date_operation_agent = BedrockLLMAgent(options)



options = BedrockLLMAgentOptions(
    client=BedrockClientSingleton(),
    region='ap-south-1',
    name='Chat Agent',
    description='An AI agent that can chat with humans and understands context',
    model_id='anthropic.claude-3-sonnet-20240229-v1:0',
    streaming=False,
    inference_config={
        'maxTokens': 1000,
        'temperature': 0.7,
        'topP': 0.9,
        'stopSequences': ['Human:', 'AI:']
    },
    guardrail_config={
        'guardrailIdentifier': 'my-guardrail',
        'guardrailVersion': '1.0'
    },
    custom_system_prompt={
        "template": """You are a specialized AI assistant with multiple capabilities.

Your expertise areas:
{{AREAS}}

When responding:
{{GUIDELINES}}

Always maintain: {{TONE}}""",
        "variables": {
            "AREAS": [
                "- Performing arithmetic operations",
                "- Performing date operations",
                "- Conversational AI",
                "- Data interpretation",
                "- Natural language processing"
            ],
            "GUIDELINES": [
                "- Provide detailed explanations",
                "- Use relevant examples",
                "- Consider user context"
            ],
            "TONE": "professional and helpful demeanor"
        }
    }
)

chit_chat_agent = BedrockLLMAgent(options)

Possible Solution

No response

Steps to Reproduce

define the agents . call the OrchestratorService and it just breaks.

i am using
boto3==1.35.0
multi-agent-orchestrator==0.1.2
Django==4.2.16