InstaFuel_Chatbot_public/tests/test_knowledge_agent.py
2026-04-21 11:57:37 +05:30

43 lines
No EOL
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import pytest
from src.agents.base_agent import SharedMemory
from agents.retrieval_agent import KnowledgeRetrievalAgent
from src.models.schemas import (
AgentType,
ConversationContext,
ConversationState,
Message,
MessageType,
Platform,
)
@pytest.mark.asyncio
async def test_knowledge_agent_offline_summary():
shared_memory = SharedMemory()
agent = KnowledgeRetrievalAgent(shared_memory=shared_memory, enable_cloud=False)
await shared_memory.register_agent(agent)
context = ConversationContext(
conversation_id="conv_knowledge_1",
user_id="user123",
platform=Platform.WEBSITE,
state=ConversationState.ACTIVE,
)
message = Message(
id="msg1",
conversation_id=context.conversation_id,
sender_id=context.user_id,
sender_type=AgentType.ORCHESTRATOR,
message_type=MessageType.USER_MESSAGE,
content="What are the benefits of whey protein?",
platform=Platform.WEBSITE,
)
response = await agent.process_message(message, context)
assert response.agent_type == AgentType.KNOWLEDGE_RETRIEVAL
assert response.response_text.startswith("Heres what I can share right now:")
assert response.metadata.get("citations")
assert context.context_data["last_knowledge_query"] == message.content