|
|
import gradio as gr |
|
|
from mcp import StdioServerParameters |
|
|
from smolagents import MCPClient, CodeAgent |
|
|
|
|
|
|
|
|
def respond(message, history): |
|
|
"""Send the message to the MCP-powered agent and return its answer.""" |
|
|
params = StdioServerParameters(command="python", args=["mcp_server.py"]) |
|
|
with MCPClient(params) as tools: |
|
|
agent = CodeAgent(tools=tools, model="gpt-4") |
|
|
answer = agent.run(message) |
|
|
history.append((message, answer)) |
|
|
return history, history |
|
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
chat_state = gr.State([]) |
|
|
chatbot = gr.Chatbot(label="Enterprise SQL Agent") |
|
|
|
|
|
textbox = gr.Textbox( |
|
|
show_label=False, |
|
|
placeholder="Ask: Who are my inactive Northeast customers?", |
|
|
) |
|
|
textbox.submit(respond, [textbox, chat_state], [chatbot, chat_state]) |
|
|
|
|
|
gr.Markdown( |
|
|
""" |
|
|
### Example Prompts |
|
|
- Who are my Northeast customers who haven’t ordered in 6 months? |
|
|
- List customers sorted by last order date. |
|
|
- Find clients from the West with recent orders. |
|
|
""" |
|
|
) |
|
|
|
|
|
gr.Markdown("Built with MCP, smolagents, and Gradio") |
|
|
|
|
|
demo.launch() |
|
|
|