Spaces:
Runtime error

File size: 3,865 Bytes
64fb1e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"""
Tool catalog β€” all available tool definitions keyed by name.
Active tools per call are selected at runtime from tenant config (tool_configs JSONB).
"""

TOOL_CATALOG: dict[str, dict] = {
    # ── Fin support tools ─────────────────────────────────────────────────────
    "verify_account": {
        "type": "function",
        "function": {
            "name": "verify_account",
            "description": (
                "Verify the caller's identity by looking up their account using phone number. "
                "Call once per session at the start of any support interaction. "
                "Required before using lookup_transaction."
            ),
            "parameters": {
                "type": "object",
                "properties": {
                    "phone": {
                        "type": "string",
                        "description": "Caller's phone number (with or without country code)",
                    },
                },
                "required": ["phone"],
            },
        },
    },
    "lookup_transaction": {
        "type": "function",
        "function": {
            "name": "lookup_transaction",
            "description": (
                "Look up a specific transaction by ID from the verified customer's account. "
                "Requires verify_account to have been called first in this session."
            ),
            "parameters": {
                "type": "object",
                "properties": {
                    "transaction_id": {
                        "type": "string",
                        "description": "Transaction ID to look up (e.g. TXN-7731)",
                    },
                },
                "required": ["transaction_id"],
            },
        },
    },
    # ── Shared ────────────────────────────────────────────────────────────────
    "escalate_to_human": {
        "type": "function",
        "function": {
            "name": "escalate_to_human",
            "description": (
                "Transfer the call to a human agent. Use when the customer requests it, "
                "fraud is suspected, a dispute needs manual review, "
                "or the AI cannot resolve the issue."
            ),
            "parameters": {
                "type": "object",
                "properties": {
                    "reason": {
                        "type": "string",
                        "enum": [
                            "customer_request",
                            "fraud_suspected",
                            "dispute_review",
                            "kyc_issue",
                            "unresolvable_issue",
                            "enterprise_pricing",
                            "complex_issue",
                            "low_sentiment",
                        ],
                        "description": "Reason for escalation",
                    },
                    "transcript_summary": {
                        "type": "string",
                        "description": "Brief summary of what was discussed and the issue status",
                    },
                },
                "required": ["reason", "transcript_summary"],
            },
        },
    },
}


def get_tool_definitions(tool_configs: dict) -> list[dict]:
    """Return tool definitions for tools enabled in tenant config."""
    return [
        TOOL_CATALOG[name]
        for name, cfg in tool_configs.items()
        if cfg.get("enabled", True) and name in TOOL_CATALOG
    ]


# Tool names as a set for fast membership checks
TOOL_NAMES: set[str] = set(TOOL_CATALOG.keys())