File size: 7,893 Bytes
2ec0d39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
"""
Enterprise Agent Gradio Application
Web interface for the Enterprise Agent
"""

import gradio as gr
import asyncio
import logging
from .enterprise_agent import EnterpriseAgent


class EnterpriseApp:
    """Gradio web application for Enterprise Agent."""
    
    def __init__(self):
        self.agent = EnterpriseAgent()
        self.conversation_history = []
        
        # Set up logging
        logging.basicConfig(level=logging.INFO)
        
        # Create the interface
        self.interface = self._create_interface()
    
    def _create_interface(self):
        """Create the Gradio interface."""
        
        with gr.Blocks(
            title="🏒 Enterprise Agent - Secure AI Suite",
            theme=gr.themes.Soft(
                primary_hue="blue",
                secondary_hue="gray", 
                neutral_hue="slate"
            ),
            css="""
            .container { max-width: 1200px; margin: auto; }
            .chatbot { height: 500px; }
            .status-card { background: linear-gradient(90deg, #667eea 0%, #764ba2 100%); color: white; }
            .tool-card { border: 2px solid #e2e8f0; border-radius: 8px; padding: 12px; margin: 8px 0; }
            """
        ) as app:
            
            # Header
            gr.HTML("""
            <div style='text-align: center; padding: 20px; background: linear-gradient(90deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 10px;'>
                <h1 style='margin: 0; font-size: 2.5em;'>🏒 Enterprise Agent</h1>
                <p style='margin: 10px 0; font-size: 1.2em;'>Automate CRM, Tickets & Calendar with AI</p>
                <p style='margin: 0; opacity: 0.8;'>πŸ” Secure AI Agents Suite</p>
            </div>
            """)
            
            with gr.Row():
                # Left column - Chat interface
                with gr.Column(scale=2):
                    gr.HTML("<h3>πŸ’¬ Chat with Enterprise Agent</h3>")
                    
                    chatbot = gr.Chatbot(
                        label="Enterprise Assistant",
                        height=400,
                        elem_classes=["chatbot"],
                        avatar_images=(None, "🏒")
                    )
                    
                    with gr.Row():
                        msg_input = gr.Textbox(
                            placeholder="Ask me about CRM updates, ticket creation, or calendar scheduling...",
                            lines=3,
                            max_lines=5,
                            label="Your Message"
                        )
                        with gr.Column(scale=0):
                            send_btn = gr.Button("Send", variant="primary")
                            clear_btn = gr.Button("Clear", variant="secondary")
                
                # Right column - Tools and Status
                with gr.Column(scale=1):
                    gr.HTML("<h3>πŸ› οΈ Available Tools</h3>")
                    
                    tools_info = gr.HTML("""
                    <div class="tool-card">
                        <h4>πŸ—ƒοΈ CRM Operations</h4>
                        <p>β€’ Update customer information<br>β€’ Search contacts and accounts<br>β€’ Modify customer records</p>
                    </div>
                    <div class="tool-card">
                        <h4>🎫 Support Tickets</h4>
                        <p>β€’ Create support tickets<br>β€’ Set priority levels<br>β€’ Categorize issues</p>
                    </div>
                    <div class="tool-card">
                        <h4>πŸ“… Calendar Management</h4>
                        <p>β€’ Schedule meetings<br>β€’ Manage appointments<br>β€’ View calendar events</p>
                    </div>
                    """)
                    
                    gr.HTML("<h3>πŸ“Š System Status</h3>")
                    status_display = gr.HTML()
            
            # Event handlers
            def user(user_message, history):
                """Handle user input."""
                if not user_message.strip():
                    return history, ""
                
                # Add user message to history
                history.append((user_message, None))
                return history, ""
            
            async def bot_response(history, user_message):
                """Generate bot response."""
                if not user_message.strip():
                    return history
                
                # Get response from agent
                response = await self.agent.handle_user_input(user_message)
                
                # Add bot response to history
                history[-1] = (user_message, response)
                return history
            
            def clear_conversation():
                """Clear conversation history."""
                return []
            
            def update_status():
                """Update status display."""
                status = self.agent.get_status()
                return f"""
                <div class="status-card" style="padding: 15px; border-radius: 8px;">
                    <h4>βœ… System Status</h4>
                    <p><strong>Agent:</strong> {status['name']}</p>
                    <p><strong>Status:</strong> {status['status']}</p>
                    <p><strong>Security:</strong> {'πŸ›‘οΈ Enabled' if status['security_enabled'] else '❌ Disabled'}</p>
                    <p><strong>Audit Logging:</strong> {'πŸ“Š Enabled' if status['audit_logging'] else '❌ Disabled'}</p>
                    <p><strong>Tools:</strong> {', '.join(status['tools'])}</p>
                </div>
                """
            
            # Connect events
            send_btn.click(
                user,
                inputs=[msg_input, chatbot],
                outputs=[chatbot, msg_input]
            ).then(
                bot_response,
                inputs=[chatbot, msg_input],
                outputs=[chatbot]
            )
            
            msg_input.submit(
                user,
                inputs=[msg_input, chatbot],
                outputs=[chatbot, msg_input]
            ).then(
                bot_response,
                inputs=[chatbot, msg_input],
                outputs=[chatbot]
            )
            
            clear_btn.click(clear_conversation, outputs=chatbot)
            
            # Initial status update
            app.load(update_status, outputs=status_display)
        
        return app
    
    def launch(self, **kwargs):
        """Launch the Gradio application."""
        self.interface.launch(
            server_name="0.0.0.0",
            server_port=7860,
            share=False,
            show_error=True,
            quiet=False,
            **kwargs
        )


# Example usage and quick commands
EXAMPLE_QUERIES = [
    "Update customer 001 email to newemail@company.com",
    "Create ticket about login issues - high priority",
    "Schedule team meeting for tomorrow at 2 PM", 
    "Search for john contacts",
    "Show calendar events for today",
    "Check system status"
]


def main():
    """Main function to run the Enterprise Agent app."""
    print("🏒 Starting Enterprise Agent...")
    print("πŸ“‘ Connecting to MCP servers...")
    print("πŸ›‘οΈ Security middleware initialized")
    print("πŸ”§ Available tools: CRM, Tickets, Calendar")
    
    app = EnterpriseApp()
    
    print("\n" + "="*60)
    print("🏒 ENTERPRISE AGENT - SECURE AI SUITE")
    print("="*60)
    print("\nπŸ’‘ Example queries you can try:")
    for i, query in enumerate(EXAMPLE_QUERIES, 1):
        print(f"   {i}. {query}")
    print("\n🌐 Starting Gradio server...")
    print("πŸ”— Open your browser to: http://localhost:7860")
    print("\n" + "="*60)
    
    app.launch()


if __name__ == "__main__":
    main()