Repository: microsoft/TypeChat
File: python/examples/multiSchema/agents.py (Python)

Code before:
    def __init__(self, model: TypeChatModel, target_type: type[T]):
        super().__init__()
        self._validator = TypeChatValidator(target_type)
        self._translator = TypeChatTranslator(model, self._validator, target_type)

    async def handle_request(self, line: str):
        result = await self._translator.translate(line)
        if isinstance(result, Failure):
            print("Translation Failed ❌")
            print(f"Context: {result.message}")
        else:
            result = result.value
            print("Translation Succeeded! ✅\n")
            print("JSON View")
            print(json.dumps(result, indent=2))


class MathAgent:
    _validator: TypeChatProgramValidator
    _translator: TypeChatProgramTranslator[math_schema.MathAPI]

    def __init__(self, model: TypeChatModel):
        self._validator = TypeChatProgramValidator(JsonProgram)
        self._translator = TypeChatProgramTranslator(model, self._validator, math_schema.MathAPI)

    async def _handle_jsonProgram_call(self, func: str, args: list[int|float]):
        print(f"{func}({json.dumps(args)}) ")
        match func:
            case "add":
                return args[0] + args[1]
            case "sub":
                return args[0] - args[1]
            case "mul":
                return args[0] * args[1]
            case "div":
                return args[0] / args[1]
            case "neg":
                return -1 * args[0]
            case "id":
                return args[0]

    async def handle_request(self, line: str):
        result = await self._translator.translate(line)
        if isinstance(result, Failure):
            print("Translation Failed ❌")
            print(f"Context: {result.message}")
        else:
            result = result.value
            print("Translation Succeeded! ✅\n")
            print("JSON View")
            print(json.dumps(result, indent=2))

Review comment (suggestion):
```suggestion
    async def _handle_json_program_call(self, func: str, args: list[int | float]):
```

Code after:


class JsonPrintAgent(Generic[T]):
    _validator: TypeChatValidator[T]
    _translator: TypeChatTranslator[T]

    def __init__(self, model: TypeChatModel, target_type: type[T]):
        super().__init__()
        self._validator = TypeChatValidator(target_type)
        self._translator = TypeChatTranslator(model, self._validator, target_type)

    async def handle_request(self, line: str):
        result = await self._translator.translate(line)
        if isinstance(result, Failure):
            print("Translation Failed ❌")
            print(f"Context: {result.message}")
        else:
            result = result.value
            print("Translation Succeeded! ✅\n")
            print("JSON View")
            print(json.dumps(result, indent=2))


class MathAgent:
    _validator: TypeChatProgramValidator[JsonProgram]
    _translator: TypeChatProgramTranslator[JsonProgram]

    def __init__(self, model: TypeChatModel):
        super().__init__()
        self._validator = TypeChatProgramValidator(JsonProgram)
        self._translator = TypeChatProgramTranslator(model, self._validator, math_schema.MathAPI)

    async def _handle_json_program_call(self, func: str, args: list[int | float]) -> int | float:
        print(f"{func}({json.dumps(args)}) ")
        match func:
            case "add":
                return args[0] + args[1]
            case "sub":
                return args[0] - args[1]
            case "mul":
                return args[0] * args[1]
            case "div":
                return args[0] / args[1]
            case "neg":
                return -1 * args[0]
            case "id":
                return args[0]
            case _:
                raise ValueError(f'Unexpected function name {func}')

    async def handle_request(self, line: str):