updates on the agent

This commit is contained in:
2026-09-22 15:29:39 +05:30
parent 90cdb57a38
commit 7227d2d2bd
7 changed files with 522 additions and 20 deletions

View File

@@ -0,0 +1,55 @@
"""Unit tests for ToolRegistry and Interactive Question Asking."""
import pytest
import asyncio
from core.tool_registry import Tool, ToolParameter, ToolRegistry
from core.interactive_question import QuestionManager, QuestionOption, question_manager
@pytest.mark.asyncio
async def test_tool_registry_registration_and_execution():
registry = ToolRegistry()
async def sample_handler(order_id: str, count: int = 1):
return {"order": order_id, "items": count}
tool = Tool(
name="test_tool",
description="A test tool",
handler=sample_handler,
parameters=[
ToolParameter(name="order_id", type="string", description="Order ID"),
ToolParameter(name="count", type="integer", description="Count", required=False, default=1),
],
)
registry.register(tool)
assert registry.get("test_tool") is not None
schemas = registry.get_schemas()
assert len(schemas) == 1
assert schemas[0]["name"] == "test_tool"
assert "order_id" in schemas[0]["parameters"]["properties"]
result = await registry.execute_tool("test_tool", order_id="ORD-100")
assert result == {"order": "ORD-100", "items": 1}
@pytest.mark.asyncio
async def test_question_manager_flow():
qm = QuestionManager()
q = qm.create_question(
prompt="Select target batch:",
options=[
{"id": "morning", "label": "Morning Batch", "badge": "12 AM–9 AM"},
{"id": "afternoon", "label": "Afternoon Batch", "badge": "9 AM–4 PM"},
],
allow_custom_input=False,
)
assert q.question_id.startswith("q-")
assert len(q.options) == 2
assert q.options[0].badge == "12 AM–9 AM"
assert not q.answered
qm.answer_question(q.question_id, "morning")
assert q.answered is True
assert q.answer == "morning"